C++课程设计--学生学籍管理系统(MFC)

课设题目

学生学籍管理系统

课设要求

  1. 用户管理
  2. 学生学籍信息录入、修改,删除
  3. 计算学生个人总成绩、平均成绩
  4. 学生可以查询个人学籍信 息
  5. 按学年、 班级、专业统计某门课的总成绩和平均成绩
  6. 学籍信息和报表数据导出
  7. 历史数据的导入、 浏览和查询

程序运行界面

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

核心源码

// members.cpp : implementation file
//

#include "stdafx.h"
#include "学生学籍管理系统.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;// 姓名
	//char name[20];
	CString id;// 学号
	CString grade;// 年级
	CString class_num;//班级号
	CString major;//专业

};

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

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

	m_list.SetExtendedStyle(LVS_EX_FLATSB  //扁平风格滚动条
		|LVS_EX_FULLROWSELECT  //选择整行
		|LVS_EX_HEADERDRAGDROP  //报表头可以拖拽
		|LVS_EX_ONECLICKACTIVATE  //单击激活
		|LVS_EX_GRIDLINES);    //绘制表格
	//设置表头
	m_list.InsertColumn(0,"姓名",LVCFMT_LEFT,100);
	m_list.InsertColumn(1,"学号",LVCFMT_LEFT,100);
	m_list.InsertColumn(2,"年级",LVCFMT_LEFT,100);
	m_list.InsertColumn(3,"班级",LVCFMT_LEFT,100);
	m_list.InsertColumn(4,"专业",LVCFMT_LEFT,135);

	ReadCai();
     

      return TRUE;
  }
 int members::ReadCai()
{
	m_list.DeleteAllItems(); // 全部清空 

	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);//增加容量以防止溢出

	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("请选择需要修改的简历");
	}
	else
	{
	
	
	if(name==""||id==""||grade==""||class_num==""||major=="")
	{
		MessageBox("修改信息不完整!请补充完所有信息!");
	}
	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("修改成功");
	ReadCai();	}
	
	}
	
}

void members::OnButton5() 
{
	// TODO: Add your control notification handler code here
		n = m_list.GetSelectionMark();
	if(n<0)
		MessageBox("请选中要删除的用户!");
	else
	{ 
        MessageBox("删除成功!");
        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);   //由于CString是MFC中,而ofstream是ATL中,ofstream能写入的需要char *
		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("保存成功!");
	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++;
			}
		}
	}
}

项目源码

需要源码的小伙伴请前往
微信公众号:海轰Pro
回复: 海轰
O(∩_∩)O哈哈~

发布了155 篇原创文章 · 获赞 110 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/weixin_44225182/article/details/103828426