题目
应用MFC应用程序实现学生信息管理系统
(1)、设计一个学生类Student,包括数据成员:姓名、学号、二门课程(面向对象程序设计、高等数学)的成绩。
(2)、创建一个管理学生的类Management,包括实现学生的数据的增加、删除、修改、按课程成绩排序、保存学生数据到文件及加载文件中的数据等功能。
(3)、创建一个基于对话框的MFC应用程序,程序窗口的标题上有你姓名、学号和应用程序名称。使用(1)和(2)中的类,实现对学生信息和成绩的输入和管理。
(4)、创建一个单文档的MFC应用程序,读取(3)中保存的文件中的学生成绩,分别用直方图和折线方式显示所有学生某课程的成绩分布图。
效果图
主窗口
添加数据窗口
修改数据窗口
查找
导出数据
导入数据
数据分析折线图
数据分析直方图
学生信息管理系统核心代码
文件名:Student Information Management SystemDlg.h
// Student Information Management SystemDlg.h: 头文件
#pragma once
// CStudentInformationManagementSystemDlg 对话框
class CStudentInformationManagementSystemDlg : public CDialogEx
{
// 构造
public:
CStudentInformationManagementSystemDlg(CWnd* pParent = nullptr); // 标准构造函数
// 对话框数据
#ifdef AFX_DESIGN_TIME
enum {
IDD = IDD_STUDENTINFORMATIONMANAGEMENTSYSTEM_DIALOG };
#endif
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
// 实现
protected:
HICON m_hIcon;
// 生成的消息映射函数
virtual BOOL OnInitDialog();
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnBnClickedAddButton();
afx_msg void OnBnClickedDeleteButton();
afx_msg void OnBnClickedChangeButton();
afx_msg void OnBnClickedDataButton();
afx_msg void OnBnClickedFileSaveButton();
afx_msg void OnBnClickedFileLoadButton();
afx_msg void OnBnClickedSearchButton();
afx_msg void OnBnClickedSortButton();
CListCtrl m_List;
// 排序选择
CComboBox m_Combo;
friend class Management;
};
文件名:Student Information Management SystemDlg.cpp
// Student Information Management SystemDlg.cpp: 实现文件
#include "pch.h"
#include "framework.h"
#include "Student Information Management System.h"
#include "Student Information Management SystemDlg.h"
#include "afxdialogex.h"
#include "CAddStudentDlg.h"
#include "Student.h"
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CStudentInformationManagementSystemDlg 对话框
CStudentInformationManagementSystemDlg::CStudentInformationManagementSystemDlg(CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_STUDENTINFORMATIONMANAGEMENTSYSTEM_DIALOG, pParent)
{
//m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_hIcon = AfxGetApp()->LoadIcon(IDI_ICON1);//设置图标
}
void CStudentInformationManagementSystemDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST, m_List);
DDX_Control(pDX, IDC_SORT_COMBO, m_Combo);
}
BEGIN_MESSAGE_MAP(CStudentInformationManagementSystemDlg, CDialogEx)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_ADD_BUTTON, &CStudentInformationManagementSystemDlg::OnBnClickedAddButton)
ON_BN_CLICKED(IDC_DELETE_BUTTON, &CStudentInformationManagementSystemDlg::OnBnClickedDeleteButton)
ON_BN_CLICKED(IDC_CHANGE_BUTTON, &CStudentInformationManagementSystemDlg::OnBnClickedChangeButton)
ON_BN_CLICKED(IDC_DATA_BUTTON, &CStudentInformationManagementSystemDlg::OnBnClickedDataButton)
ON_BN_CLICKED(IDC_FILE_SAVE_BUTTON, &CStudentInformationManagementSystemDlg::OnBnClickedFileSaveButton)
ON_BN_CLICKED(IDC_FILE_LOAD_BUTTON, &CStudentInformationManagementSystemDlg::OnBnClickedFileLoadButton)
ON_BN_CLICKED(IDC_SEARCH_BUTTON, &CStudentInformationManagementSystemDlg::OnBnClickedSearchButton)
ON_BN_CLICKED(IDC_SORT_BUTTON, &CStudentInformationManagementSystemDlg::OnBnClickedSortButton)
END_MESSAGE_MAP()
// CStudentInformationManagementSystemDlg 消息处理程序
BOOL CStudentInformationManagementSystemDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// 设置此对话框的图标。 当应用程序主窗口不是对话框时,框架将自动
// 执行此操作
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标
// TODO: 在此添加额外的初始化代码
//在窗口左上角设置自己的姓名和学号(课设要求)
CString str = "学生信息管理系统";
SetWindowText(str);
//设置数据显示区
m_List.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);//整行选择、网格线
m_List.InsertColumn(0, "姓名", LVCFMT_CENTER, 100);
m_List.InsertColumn(1, "性别", LVCFMT_CENTER, 100);
m_List.InsertColumn(2, "学号", LVCFMT_CENTER, 100);
m_List.InsertColumn(3, "高等数学", LVCFMT_CENTER, 100);
m_List.InsertColumn(4, "课程设计", LVCFMT_CENTER, 100);
m_List.InsertColumn(5, "总分", LVCFMT_CENTER, 100);
//排序函数
//读取文件函数
theApp.m_Management.LoadFile(&m_List);
//设置排序选择按钮
m_Combo.AddString(_T("总分"));
m_Combo.AddString(_T("课设"));
m_Combo.AddString(_T("高数"));
m_Combo.AddString(_T("学号"));
m_Combo.SetCurSel(2);
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}
// 如果向对话框添加最小化按钮,则需要下面的代码
// 来绘制该图标。 对于使用文档/视图模型的 MFC 应用程序,
// 这将由框架自动完成。
void CStudentInformationManagementSystemDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 用于绘制的设备上下文
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// 使图标在工作区矩形中居中
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x =