⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 学生管理dlg.cpp

📁 学生管理系统 能添加,删除,排序,查询,功能相当强大
💻 CPP
字号:
// 学生管理Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "学生管理.h"
#include "学生管理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];//定义一个marks类的数组
int n=0;
int flag=0;//定义两个标志量



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="学号(6位)  平时成绩  期中考试成绩  期末考试成绩";
	CString csFileName;
	CFileDialog dakai(TRUE, "dat", "note",OFN_HIDEREADONLY 
		|OFN_OVERWRITEPROMPT,       "DAT Files(*.dat)|*.dat|TXT Files(*.txt)|*.txt|All Files(*.*)|*.*||");
	//定义一个CFileDialog类名为dakai的函数,用来进行打开操作
	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);	//取出文件中的人数数据
	do
	{
		out.ReadString(cs);    //只能读取一行
		csSQL+=cs;
		csSQL+="\r\n";		
		s[n].setid(strtoul((char *)(LPCSTR)cs,&p1,10));//取出文件中的学号数据
		s[n].setps(strtod(p1, &p2));//取出文件中的平时成绩数据
		s[n].setqz(strtod(p2, &p3));//取出文件中的期中成绩数据
		s[n].setqm(strtod(p3, &p));//取出文件中的期末成绩数据
		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(*.*)|*.*||");
	//定义一个CFileDialog类名为baocun的函数,用来进行保存操作
	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() //计算按钮
{
	
	CString str="",str1="",str2="",str3="";//定义CString类,用来输出显示
	CString str4="学生学号(6位)   总评成绩   成绩等级";
	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');
		}//判断等级
		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);  //将输入的字符串转换成整型数
		for(int i=0;i<n;i++)
		{
			if(s[i].getid()==m1)//查询时判断学号
			{
				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("查不到该生信息!");//弹出错误信息
		}
	}
	else
		AfxMessageBox("请输入学号!");	//未输入学号时显示错误
}

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);//输出等级为A的学生信息
		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);//输出等级为B的学生信息
		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);//输出等级为C的学生信息
		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);//输出等级为D的学生信息
		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);//输出等级为E的学生信息
		break;
	case 0:
		AfxMessageBox("请选择!");//出错信息
		break;
	}	
}




































void CMyDlg::OnButton7() 
{
	AfxMessageBox("请先打开note.dat,进行计算后方可查询\r\n    程序作者:B06040312 冯小刚");
		
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -