C + + Course Design -- student status management system (MFC)

Keywords: iOS

Lesson title

Student status management system

Class setting requirements

  1. user management
  2. Entry, modification and deletion of student status information
  3. Calculate the total and average scores of students
  4. Students can inquire personal student status information
  5. Statistics of total and average scores of a course by academic year, class and major
  6. Student status information and report data export
  7. Import, browse and query of historical data

Program operation interface



Core source code

// members.cpp : implementation file
//

#include "stdafx.h"
#include "student status management system. h"
#include "members.h"
#include"Huiyuan.h"
#include <vector>
#include <ostream>
#include<fstream>
#include "iostream.h"
#include <string>
using namespace std;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
class Student{
public:
	CString name;// Full name
	//char name[20];
	CString id;// Student ID
	CString grade;// grade
	CString class_num;//Class number
	CString major;//major

};

vector <Student>stu;
int n = -1;
/////////////////////////////////////////////////////////////////////////////
// members dialog

 BOOL members::OnInitDialog()
  {
	  	CDialog::OnInitDialog();

	m_list.SetExtendedStyle(LVS_EX_FLATSB  //Flat style scroll bar
		|LVS_EX_FULLROWSELECT  //Select entire line
		|LVS_EX_HEADERDRAGDROP  //Report header can be dragged
		|LVS_EX_ONECLICKACTIVATE  //click to activate
		|LVS_EX_GRIDLINES);    //Draw table
	//Set the header
	m_list.InsertColumn(0,"Full name",LVCFMT_LEFT,100);
	m_list.InsertColumn(1,"Student ID",LVCFMT_LEFT,100);
	m_list.InsertColumn(2,"grade",LVCFMT_LEFT,100);
	m_list.InsertColumn(3,"class",LVCFMT_LEFT,100);
	m_list.InsertColumn(4,"major",LVCFMT_LEFT,135);

	ReadCai();
     

      return TRUE;
  }
 int members::ReadCai()
{
	m_list.DeleteAllItems(); // Empty all 

	ifstream fin("members.txt",ios_base::in); 
	string a,b,c,d,e;
	fin>>a>>b>>c>>d>>e;
	for(int i=0;!fin.fail();++i){

		int n=m_list.GetItemCount();
		m_list.InsertItem(n,a.data());
		m_list.SetItemText(n,1,b.data());
		m_list.SetItemText(n,2,c.data());
		m_list.SetItemText(n,3,d.data());
		m_list.SetItemText(n,4,e.data());
		Student s1;
		s1.name=a.data();
		s1.id=b.data();
		s1.grade=c.data();
		s1.class_num=d.data();
		s1.major=e.data();
		stu.reserve(stu.size()+1);//Increase capacity to prevent overflow

	stu.push_back(s1);
	fin>>a>>b>>c>>d>>e;
	}
	fin.close();

	return 0;
}
members::members(CWnd* pParent /*=NULL*/)
	: CDialog(members::IDD, pParent)
{
	//{{AFX_DATA_INIT(members)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void members::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(members)
	DDX_Control(pDX, IDC_LIST1, m_list);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(members, CDialog)
	//{{AFX_MSG_MAP(members)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
	ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// members message handlers

void members::OnButton3() 
{
	// TODO: Add your control notification handler code here
		CHuiyuan dlg;
	    dlg.DoModal();
		ReadCai();
}

void members::OnButton4() 
{
	// TODO: Add your control notification handler code here
	int sel = m_list.GetSelectionMark();
	CString name,id,grade,class_num,major;
	GetDlgItem(IDC_EDIT1)->GetWindowText(id);
	GetDlgItem(IDC_EDIT7)->GetWindowText(name);
	GetDlgItem(IDC_EDIT8)->GetWindowText(grade);
	GetDlgItem(IDC_EDIT9)->GetWindowText(class_num);
	GetDlgItem(IDC_EDIT2)->GetWindowText(major);


	if(sel ==-1)
	{
		MessageBox("Please select the resume to be modified");
	}
	else
	{
	
	
	if(name==""||id==""||grade==""||class_num==""||major=="")
	{
		MessageBox("Incomplete modification information! Please fill in all the information!");
	}
	else
	{
		int num=m_list.GetItemCount();

//		int num=ReadCai();
//		CString x;
//		x.Format("%d",num);
//MessageBox(x);
	FILE *file=fopen("members.txt","w");	
	for(int i=0;i<num;i++)
	{
		if(sel==i)
		{
			stu[i].name=name;
			stu[i].id=id;
			stu[i].grade=grade;
			stu[i].class_num=class_num;
			stu[i].major=major;
		//	strcpy(stu[i].name,name);
		//	strcpy(cai[i].sex,sex);
		//	strcpy(cai[i].id,id);
          //  strcpy(cai[i].major,major);
			//strcpy(cai[i].about,about);

		}
		fprintf(file,"%s   %s   %s   %s   %s\r\n",stu[i].name,stu[i].id\
			,stu[i].grade,stu[i].class_num,stu[i].major);
	}
	fclose(file);

	MessageBox("Modified success");
	ReadCai();	}
	
	}
	
}

void members::OnButton5() 
{
	// TODO: Add your control notification handler code here
		n = m_list.GetSelectionMark();
	if(n<0)
		MessageBox("Please select the user to delete!");
	else
	{ 
        MessageBox("Delete successful!");
        stu.erase(stu.begin()+n);
		m_list.DeleteItem(n);
	UpdateData(false);
	}
	n=-1;
}

void members::OnButton6() 
{
ofstream fout("members.txt",ios::trunc);
	int n=m_list.GetItemCount();
	for(int i=0;i<n;++i){
		string str0 = CString(stu[i].name);   //Since CString is in MFC and ofstream is in ATL, char is required for ofstream to write*
		string str1 = CString(stu[i].id);
		string str2 = CString(stu[i].grade);
		string str3 = CString(stu[i].class_num);
		string str4 = CString(stu[i].major);
		
		fout<<str0.c_str()<<" "
			<<str1.c_str()<<" "
			<<str2.c_str()<<" "
			<<str3.c_str()<<" "
			<<str4.c_str()<<endl;
		if (fout.fail())  
			break;
	}
	fout.close();
	MessageBox("Save successfully!");
	CDialog::OnOK();		
}

void members::OnButton1() 
{
	// TODO: Add your control notification handler code here
//		m_list.DeleteAllItems();
	CString id;
	GetDlgItem(IDC_EDIT1)->GetWindowText(id);

	if(id=="")
	{
//		ShowCai();
		ReadCai();
	}
	else
	{
		int i = 0;
		int nums=m_list.GetItemCount();
		m_list.DeleteAllItems();
		CString x;
		x.Format("%d",nums);
		MessageBox(x);

		for(int a=0;a<nums;a++)
		{
			if(strcmp(id,stu[a].id)==0)
			{
				m_list.InsertItem(i,0);
				m_list.SetItemText(i,0,stu[a].name);
				m_list.SetItemText(i,1,stu[a].id);
				m_list.SetItemText(i,2,stu[a].grade);
				m_list.SetItemText(i,3,stu[a].class_num);
				m_list.SetItemText(i,4,stu[a].major);
				i++;
			}
		}
	}
}

155 original articles published, praised 103, visited 50000+
Private letter follow

Posted by GreyFilm on Sat, 08 Feb 2020 07:54:42 -0800