学生管理系统vc++6.0
时间: 2023-12-30 10:05:48 浏览: 143
vc++6.0实现的学生成绩管理系统代码
4星 · 用户满意度95%
学生管理系统是一个用于管理学生信息的软件系统。在VC++6.0中,可以使用MFC(Microsoft Foundation Classes)来开发学生管理系统。MFC是一个C++类库,它提供了一组用于创建Windows应用程序的类和函数。
下面是一个简单的学生管理系统的示例代码:
```cpp
#include <afxwin.h>
class CStudent
{
public:
CString m_strName;
int m_nAge;
CString m_strMajor;
};
class CStudentManagementApp : public CWinApp
{
public:
virtual BOOL InitInstance();
};
class CStudentManagementWnd : public CFrameWnd
{
public:
CStudentManagementWnd();
private:
CListCtrl m_listCtrl;
void AddStudent(const CStudent& student);
afx_msg void OnAddStudent();
afx_msg void OnDeleteStudent();
afx_msg void OnEditStudent();
DECLARE_MESSAGE_MAP()
};
BOOL CStudentManagementApp::InitInstance()
{
CStudentManagementWnd* pMainWnd = new CStudentManagementWnd();
m_pMainWnd = pMainWnd;
pMainWnd->ShowWindow(SW_SHOW);
pMainWnd->UpdateWindow();
return TRUE;
}
CStudentManagementWnd::CStudentManagementWnd()
{
Create(NULL, _T("学生管理系统"), WS_OVERLAPPEDWINDOW, CRect(100, 100, 500, 400));
m_listCtrl.Create(WS_VISIBLE | WS_CHILD | LVS_REPORT, CRect(10, 10, 480, 300), this, 1);
m_listCtrl.InsertColumn(0, _T("姓名"), LVCFMT_LEFT, 100);
m_listCtrl.InsertColumn(1, _T("年龄"), LVCFMT_LEFT, 100);
m_listCtrl.InsertColumn(2, _T("专业"), LVCFMT_LEFT, 200);
CMenu* pMenu = new CMenu();
pMenu->CreateMenu();
pMenu->AppendMenu(MF_STRING, 1, _T("添加学生"));
pMenu->AppendMenu(MF_STRING, 2, _T("删除学生"));
pMenu->AppendMenu(MF_STRING, 3, _T("编辑学生"));
SetMenu(pMenu);
SetIcon(AfxGetApp()->LoadIcon(IDR_MAINFRAME), TRUE);
}
void CStudentManagementWnd::AddStudent(const CStudent& student)
{
int nIndex = m_listCtrl.GetItemCount();
m_listCtrl.InsertItem(nIndex, student.m_strName);
m_listCtrl.SetItemText(nIndex, 1, CString(std::to_string(student.m_nAge).c_str()));
m_listCtrl.SetItemText(nIndex, 2, student.m_strMajor);
}
void CStudentManagementWnd::OnAddStudent()
{
CStudent student;
student.m_strName = _T("张三");
student.m_nAge = 20;
student.m_strMajor = _T("计算机科学");
AddStudent(student);
}
void CStudentManagementWnd::OnDeleteStudent()
{
int nIndex = m_listCtrl.GetNextItem(-1, LVNI_SELECTED);
if (nIndex != -1)
{
m_listCtrl.DeleteItem(nIndex);
}
}
void CStudentManagementWnd::OnEditStudent()
{
int nIndex = m_listCtrl.GetNextItem(-1, LVNI_SELECTED);
if (nIndex != -1)
{
CStudent student;
student.m_strName = _T("李四");
student.m_nAge = 22;
student.m_strMajor = _T("软件工程");
m_listCtrl.SetItemText(nIndex, 0, student.m_strName);
m_listCtrl.SetItemText(nIndex, 1, CString(std::to_string(student.m_nAge).c_str()));
m_listCtrl.SetItemText(nIndex, 2, student.m_strMajor);
}
}
BEGIN_MESSAGE_MAP(CStudentManagementWnd, CFrameWnd)
ON_COMMAND(1, OnAddStudent)
ON_COMMAND(2, OnDeleteStudent)
ON_COMMAND(3, OnEditStudent)
END_MESSAGE_MAP()
CStudentManagementApp theApp;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
if (!AfxWinInit(hInstance, hPrevInstance, lpCmdLine, nCmdShow))
{
return FALSE;
}
return theApp.Run();
}
```
这个示例代码创建了一个简单的学生管理系统窗口,其中包含一个列表控件用于显示学生信息。通过菜单可以添加、删除和编辑学生信息。
阅读全文