?? 學(xué)生管理dlg.cpp
字號(hào):
// 學(xué)生管理Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "學(xué)生管理.h"
#include "學(xué)生管理Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class student{
private:
long a;
public:
void setid(long a1)
{
a=a1;
}
long getid()
{
return a;
}
};//定義student類
class marks:public student{
private:
float b,c,d;
float e;
char f;
public:
void setps(float b1)
{
b=b1;
}
float getps()
{
return b;
}
void setqz(float c1)
{
c=c1;
}
float getqz()
{
return c;
}
void setqm(float d1)
{
d=d1;
}
float getqm()
{
return d;
}
void setzf(float e1)
{
e=e1;
}
float getzf()
{
return e;
}
void setdj(char f1)
{
f=f1;
}
char getdj()
{
return f;
}
};//定義marks類
marks s[30];//定義一個(gè)marks類的數(shù)組
int n=0;
int flag=0;//定義兩個(gè)標(biāo)志量
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDlg dialog
CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMyDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMyDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDlg)
DDX_Control(pDX, IDC_EDIT4, m_c);
DDX_Control(pDX, IDC_EDIT2, m_b);
DDX_Control(pDX, IDC_EDIT1, m_a);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
//{{AFX_MSG_MAP(CMyDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
ON_BN_CLICKED(IDC_RADIO4, OnRadio4)
ON_BN_CLICKED(IDC_RADIO5, OnRadio5)
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDlg message handlers
BOOL CMyDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CMyDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CMyDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMyDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMyDlg::OnButton1() //打開按鈕
{
int renshu;
n=0;
char *p1,*p2,*p3,*p;
char *p4;
CString str="學(xué)號(hào)(6位) 平時(shí)成績 期中考試成績 期末考試成績";
CString csFileName;
CFileDialog dakai(TRUE, "dat", "note",OFN_HIDEREADONLY
|OFN_OVERWRITEPROMPT, "DAT Files(*.dat)|*.dat|TXT Files(*.txt)|*.txt|All Files(*.*)|*.*||");
//定義一個(gè)CFileDialog類名為dakai的函數(shù),用來進(jìn)行打開操作
if ( dakai.DoModal()!=IDOK ) return;
csFileName=dakai.GetPathName();//取文件存放目錄
SetDlgItemText(IDC_EDIT3,csFileName);
CStdioFile out;
out.Open(csFileName, CFile::modeRead);
CString csSQL="",cs;
out.ReadString(cs);
csSQL+=cs;
csSQL+="\r\n";
renshu=strtoul((char *)(LPCSTR)cs,&p4,10); //取出文件中的人數(shù)數(shù)據(jù)
do
{
out.ReadString(cs); //只能讀取一行
csSQL+=cs;
csSQL+="\r\n";
s[n].setid(strtoul((char *)(LPCSTR)cs,&p1,10));//取出文件中的學(xué)號(hào)數(shù)據(jù)
s[n].setps(strtod(p1, &p2));//取出文件中的平時(shí)成績數(shù)據(jù)
s[n].setqz(strtod(p2, &p3));//取出文件中的期中成績數(shù)據(jù)
s[n].setqm(strtod(p3, &p));//取出文件中的期末成績數(shù)據(jù)
n++;
}while ( out.GetPosition()<out.GetLength()-1);
SetDlgItemText(IDC_EDIT2,str);
SetDlgItemText(IDC_EDIT1,csSQL);//在文本框中顯示
out.Close();
}
void CMyDlg::OnButton2() //保存按鈕
{
CString csFileName;
CFileDialog baocun(FALSE, "dat", "out",OFN_HIDEREADONLY
| OFN_OVERWRITEPROMPT,"DAT Files(*.dat)|*.dat|TXT Files(*.txt)|*.txt|All Files(*.*)|*.*||");
//定義一個(gè)CFileDialog類名為baocun的函數(shù),用來進(jìn)行保存操作
if ( baocun.DoModal()!=IDOK ) return;
csFileName=baocun.GetPathName(); //取文件保存目錄
CStdioFile out;
out.Open(csFileName, CFile::modeCreate | CFile::modeWrite);
CString csSQL;
this->GetDlgItemText(IDC_EDIT1,csSQL);
out.WriteString(csSQL);
out.Close();
}
void CMyDlg::OnButton3() //計(jì)算按鈕
{
CString str="",str1="",str2="",str3="";//定義CString類,用來輸出顯示
CString str4="學(xué)生學(xué)號(hào)(6位) 總評(píng)成績 成績等級(jí)";
SetDlgItemText(IDC_EDIT2,str4);
for(int i=0;i<n;i++)
{
s[i].setzf(0.3*s[i].getps()+0.3*s[i].getqz()+0.4*s[i].getqm());
if(s[i].getzf()<60)
{
s[i].setdj('E');
}
else if(s[i].getzf()<=69&&s[i].getzf()>=60)
{
s[i].setdj('D');
}
else if(s[i].getzf()<=79&&s[i].getzf()>=70)
{
s[i].setdj('C');
}
else if(s[i].getzf()<=89&&s[i].getzf()>=80)
{
s[i].setdj('B');
}
else if(s[i].getzf()<=100&&s[i].getzf()>=90)
{
s[i].setdj('A');
}//判斷等級(jí)
str1.Format("%d",s[i].getid());
str2.Format("%g",s[i].getzf());
str3.Format("%c",s[i].getdj());
str=str+str1+" "+str2+" "+str3+" "+"\r\n";
}
SetDlgItemText(IDC_EDIT1,str);//輸出顯示
}
void CMyDlg::OnButton4() //退出按鈕
{
exit(0);
}
void CMyDlg::OnRadio1()
{
flag=1;
}
void CMyDlg::OnRadio2()
{
flag=2;
}
void CMyDlg::OnRadio3()
{
flag=3;
}
void CMyDlg::OnRadio4()
{
flag=4;
}
void CMyDlg::OnRadio5() //單選按鈕
{
flag=5;
}
void CMyDlg::OnButton5() //查詢(左邊)按鈕
{
CString cx1;
CString str="",str1="",str2="",str3="";
char *q;
int len1=m_c.GetWindowTextLength();//取明文框中輸入的字符串長度
int m1,m2=-1;
if(len1>0)
{
m_c.GetWindowText(cx1);
q=cx1.GetBuffer(cx1.GetLength()); //字符串的錄入
m1=strtoul(q,NULL,10); //將輸入的字符串轉(zhuǎn)換成整型數(shù)
for(int i=0;i<n;i++)
{
if(s[i].getid()==m1)//查詢時(shí)判斷學(xué)號(hào)
{
m2=i;
}
}
if(m2!=-1)
{
str1.Format("%d",s[m2].getid());
str2.Format("%g",s[m2].getzf());
str3.Format("%c",s[m2].getdj());
str=str+str1+" "+str2+" "+str3+" "+"\r\n";
SetDlgItemText(IDC_EDIT1,str);//輸出顯示
}
else
{
AfxMessageBox("查不到該生信息!");//彈出錯(cuò)誤信息
}
}
else
AfxMessageBox("請(qǐng)輸入學(xué)號(hào)!"); //未輸入學(xué)號(hào)時(shí)顯示錯(cuò)誤
}
void CMyDlg::OnButton6() //查詢(右邊)按鈕
{
CString str="",str1="",str2="",str3="";
int m1[30],m2[30],m3[30],m4[30],m5[30];
int i;
switch(flag)
{
case 1:
for(i=0;i<n;i++)
{
if(s[i].getdj()=='A')
{
str1.Format("%d",s[i].getid());
str2.Format("%g",s[i].getzf());
str3.Format("%c",s[i].getdj());
str=str+str1+" "+str2+" "+str3+" "+"\r\n";
}
}
SetDlgItemText(IDC_EDIT1,str);//輸出等級(jí)為A的學(xué)生信息
break;
case 2:
for(i=0;i<n;i++)
{
if(s[i].getdj()=='B')
{
str1.Format("%d",s[i].getid());
str2.Format("%g",s[i].getzf());
str3.Format("%c",s[i].getdj());
str=str+str1+" "+str2+" "+str3+" "+"\r\n";
}
}
SetDlgItemText(IDC_EDIT1,str);//輸出等級(jí)為B的學(xué)生信息
break;
case 3:
for(i=0;i<n;i++)
{
if(s[i].getdj()=='C')
{
str1.Format("%d",s[i].getid());
str2.Format("%g",s[i].getzf());
str3.Format("%c",s[i].getdj());
str=str+str1+" "+str2+" "+str3+" "+"\r\n";
}
}
SetDlgItemText(IDC_EDIT1,str);//輸出等級(jí)為C的學(xué)生信息
break;
case 4:
for(i=0;i<n;i++)
{
if(s[i].getdj()=='D')
{
str1.Format("%d",s[i].getid());
str2.Format("%g",s[i].getzf());
str3.Format("%c",s[i].getdj());
str=str+str1+" "+str2+" "+str3+" "+"\r\n";
}
}
SetDlgItemText(IDC_EDIT1,str);//輸出等級(jí)為D的學(xué)生信息
break;
case 5:
for(i=0;i<n;i++)
{
if(s[i].getdj()=='E')
{
str1.Format("%d",s[i].getid());
str2.Format("%g",s[i].getzf());
str3.Format("%c",s[i].getdj());
str=str+str1+" "+str2+" "+str3+" "+"\r\n";
}
}
SetDlgItemText(IDC_EDIT1,str);//輸出等級(jí)為E的學(xué)生信息
break;
case 0:
AfxMessageBox("請(qǐng)選擇!");//出錯(cuò)信息
break;
}
}
void CMyDlg::OnButton7()
{
AfxMessageBox("請(qǐng)先打開note.dat,進(jìn)行計(jì)算后方可查詢\r\n 程序作者:B06040312 馮小剛");
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -