📄 dlgstatistic.cpp
字号:
// DlgStatistic.cpp : implementation file
//
#include "stdafx.h"
#include "stmanager.h"
#include "DlgStatistic.h"
#include "clist.h"
#include "student.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDlgStatistic dialog
CDlgStatistic::CDlgStatistic(CWnd* pParent /*=NULL*/)
: CDialog(CDlgStatistic::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgStatistic)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CDlgStatistic::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgStatistic)
DDX_Control(pDX, IDC_LIST2, m_list1);
DDX_Control(pDX, IDC_COMBO_Marksect, m_marksect);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgStatistic, CDialog)
//{{AFX_MSG_MAP(CDlgStatistic)
ON_NOTIFY(NM_CLICK, IDC_LIST2, OnClickList2)
ON_BN_CLICKED(IDC_BUTTON_Sure, OnBUTTONSure)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgStatistic message handlers
void CDlgStatistic::OnClickList2(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
*pResult = 0;
}
BOOL CDlgStatistic::OnInitDialog()//统计对话框中的CListCtrl对象的初始化
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_marksect.SetCurSel(0);//默认选择90分以上的统计
m_list1.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);//获得List控件所占范围的大小, 画网格
CRect rt;
m_list1.GetClientRect(&rt);
m_list1.SetBkColor(RGB(0,255,0)); //设置背景色
m_list1.SetTextColor(RGB(0,255,255)); //设置文本色
m_list1.SetTextBkColor(RGB(128,0,0));//设置文本背景色
//设置列
m_list1.InsertColumn(0,"姓名",LVCFMT_LEFT,rt.right/7,0);
m_list1.InsertColumn(1,"性别",LVCFMT_LEFT,rt.right/7,1);
m_list1.InsertColumn(2,"学号",LVCFMT_LEFT,rt.right/7,2);
m_list1.InsertColumn(3,"专业",LVCFMT_LEFT,rt.right/7,3);
m_list1.InsertColumn(4,"数学成绩",LVCFMT_LEFT,rt.right/7,4);
m_list1.InsertColumn(5,"Cpp成绩",LVCFMT_LEFT,rt.right/7,5);
m_list1.InsertColumn(6,"英语成绩",LVCFMT_LEFT,rt.right/7,6);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDlgStatistic::OnBUTTONSure()//统计框的显示函数
{
// TODO: Add your control notification handler code here
cstudent *temp=m_ptlist->head;//得到链表头指针
int combox=m_marksect.GetCurSel();//得到组合框的选中项
int note=0;//用来判断是否有该分数段的学生
if(combox==0)
{
m_list1.DeleteAllItems();
while(temp)
{
int row=m_list1.GetItemCount();
if(90<=temp->average()&&temp->average()<=100)
{
m_list1.InsertItem(row,temp->getname());
m_list1.SetItemText(row,1,temp->getsex());
m_list1.SetItemText(row,2,temp->getnumber());
m_list1.SetItemText(row,3,temp->getmajor());
CString math,cpp,english;
math.Format("%.1f",temp->getmath());//double类型转换cstring
m_list1.SetItemText(row,4,math);
cpp.Format("%.1f",temp->getcpp());
m_list1.SetItemText(row,5,cpp);
english.Format("%.1f",temp->getenglish());
m_list1.SetItemText(row,6,english);
note++;
}
temp=temp->next;
}
if(note==0)
AfxMessageBox("很遗憾,没有很优秀的学生");
else
AfxMessageBox("你们真是天才呀");
}
else
if(combox==1)
{
m_list1.DeleteAllItems();
while(temp)
{
int row=m_list1.GetItemCount();
if(80<=temp->average()&&temp->average()<=89)
{
m_list1.InsertItem(row,temp->getname());
m_list1.SetItemText(row,1,temp->getsex());
m_list1.SetItemText(row,2,temp->getnumber());
m_list1.SetItemText(row,3,temp->getmajor());
CString math,cpp,english;
math.Format("%.1f",temp->getmath());//double类型转换cstring
m_list1.SetItemText(row,4,math);
cpp.Format("%.1f",temp->getcpp());
m_list1.SetItemText(row,5,cpp);
english.Format("%.1f",temp->getenglish());
m_list1.SetItemText(row,6,english);
note++;
}
temp=temp->next;
}
if(note==0)
AfxMessageBox("很抱歉,该分数段没有学生");
else
AfxMessageBox("太棒了,你们");
}
else
if(combox==2)
{
m_list1.DeleteAllItems();
while(temp)
{
int row=m_list1.GetItemCount();
if(70<=temp->average()&&temp->average()<=79)
{
m_list1.InsertItem(row,temp->getname());
m_list1.SetItemText(row,1,temp->getsex());
m_list1.SetItemText(row,2,temp->getnumber());
m_list1.SetItemText(row,3,temp->getmajor());
CString math,cpp,english;
math.Format("%.1f",temp->getmath());//double类型转换cstring
m_list1.SetItemText(row,4,math);
cpp.Format("%.1f",temp->getcpp());
m_list1.SetItemText(row,5,cpp);
english.Format("%.1f",temp->getenglish());
m_list1.SetItemText(row,6,english);
note++;
}
temp=temp->next;
}
if(note==0)
AfxMessageBox("该分数段没有学生");
else
AfxMessageBox("不错,继续努力");
}
else
if(combox==3)
{
m_list1.DeleteAllItems();
while(temp)
{
int row=m_list1.GetItemCount();
if(60<=temp->average()&&temp->average()<=69)
{
m_list1.InsertItem(row,temp->getname());
m_list1.SetItemText(row,1,temp->getsex());
m_list1.SetItemText(row,2,temp->getnumber());
m_list1.SetItemText(row,3,temp->getmajor());
CString math,cpp,english;
math.Format("%.1f",temp->getmath());//double类型转换cstring
m_list1.SetItemText(row,4,math);
cpp.Format("%.1f",temp->getcpp());
m_list1.SetItemText(row,5,cpp);
english.Format("%.1f",temp->getenglish());
m_list1.SetItemText(row,6,english);
note++;
}
temp=temp->next;
}
if(note==0)
AfxMessageBox("该分数段没有学生");
else
AfxMessageBox("再努力一些会更好");
}
else
if(combox==4)
{
m_list1.DeleteAllItems();
while(temp)
{
int row=m_list1.GetItemCount();
if(temp->average()<60)
{
m_list1.InsertItem(row,temp->getname());
m_list1.SetItemText(row,1,temp->getsex());
m_list1.SetItemText(row,2,temp->getnumber());
m_list1.SetItemText(row,3,temp->getmajor());
CString math,cpp,english;
math.Format("%.1f",temp->getmath());//double类型转换cstring
m_list1.SetItemText(row,4,math);
cpp.Format("%.1f",temp->getcpp());
m_list1.SetItemText(row,5,cpp);
english.Format("%.1f",temp->getenglish());
m_list1.SetItemText(row,6,english);
note++;
}
temp=temp->next;
}
if(note==0)
AfxMessageBox("很好,没有不及格的学生");
else
AfxMessageBox("亲爱的同学们啊,你们要努力了");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -