1、2 设计学生信息管理系统 2设计学生信息管理系统 源程序代码/*/程序共有11个文件组成,五个类分别有头文件和实现文件,另外有一个主函数文件。1 Subject.h文件#if !defined(AFX_SUBJECT_H_3001776D_2E6A_4292_96F6_EF8525844C9E_INCLUDED_)#define AFX_SUBJECT_H_3001776D_2E6A_4292_96F6_EF8525844C9E_INCLUDED_#if _MSC_VER 1000#pragma once#endif / _MSC_VER 1000#include #include #incl
2、ude #include #include class Subject public: Subject * next; float fenshu; int Crect; char teacher12; char Cname12; char Cno5; Subject(); Subject(char *name,char *no,char *teacher1,int crect1,float fenshu1) strcpy(Cname,name); strcpy(Cno,no); strcpy(teacher,teacher1); Crect= crect1; fenshu= fenshu1;
3、next=NULL; virtual Subject(); friend ostream &operator (ostream &oc,Subject &obj); /重载(istream &ic,Subject &obj); /重载;#endif / !defined(AFX_SUBJECT_H_3001776D_2E6A_4292_96F6_EF8525844C9E_INCLUDED_)/*/2 Student.h文件#if !defined(AFX_STUDENT_H_4392E0A8_A0E9_4353_968C_F57DB538B90A_INCLUDED_)#define AFX_S
4、TUDENT_H_4392E0A8_A0E9_4353_968C_F57DB538B90A_INCLUDED_#if _MSC_VER 1000#pragma once#endif / _MSC_VER 1000#include #include #include #include #include #include Subject.hclass Student public: void DispAll(); Subject *Sub; int SubCount; Student * next; int Sage; int Sgrade; char Ssex4; char Pno5; char
5、 Cname10; char Sname10; char Sno10; Student(); Student(char *no,char *name,char *pno1,char *cname1,int grade1,char *sex,int age) next=NULL; Sub= NULL; SubCount = 0; strcpy(Sno,no); strcpy(Sname,name); strcpy(Pno,pno1); strcpy(Cname,cname1); Sgrade= grade1; strcpy(Ssex,sex); Sage= age; Student(); boo
6、l AddSub(char* name,char* no,char* teacher,int crect,float fenshu); Subject* FindSub(char* no); bool DelSub(char* no); float AvgFenShu(); float MaxFenShu(); float MinFenShu(); friend ostream &operator (ostream &oc,Student &obj); /重载(istream &ic,Student &obj); /重载;#endif / !defined(AFX_STUDENT_H_4392
7、E0A8_A0E9_4353_968C_F57DB538B90A_INCLUDED_)/*/3 Class.h文件#if !defined(AFX_LASS_H_CFFEE7B4_31E2_4F10_BA58_38D8D461130E_INCLUDED_)#define AFX_LASS_H_CFFEE7B4_31E2_4F10_BA58_38D8D461130E_INCLUDED_#if _MSC_VER 1000#pragma once#endif / _MSC_VER 1000#include Student.hclass Class public: void StudMenu(Stud
8、ent* studType); void DispAll(); char Pno5; char Cname10; char Cno5; int StudCount; Class *next; Student *Stud; Class(); Class(char *cno1,char *cname1,char *pno1) next= NULL; Stud=NULL; StudCount = 0; strcpy(Cno,cno1); strcpy(Cname,cname1); strcpy(Pno,pno1); virtual Class(); bool AddStud(char *no,cha
9、r *name,char *pno,char *cname,int grade,char *sex,int age); bool DeleteStud(char *no); Student * FindStud(char *no); friend ostream &operator (ostream &oc,Class &obj); /重载(istream &ic,Class &obj); /重载;#endif / !defined(AFX_LASS_H_CFFEE7B4_31E2_4F10_BA58_38D8D461130E_INCLUDED_)/*/4 Department.h文件#if
10、!defined(AFX_DEPANTMENT_H_A6895DC1_C3F3_4737_88EC_AE2DA280272E_INCLUDED_)#define AFX_DEPANTMENT_H_A6895DC1_C3F3_4737_88EC_AE2DA280272E_INCLUDED_#if _MSC_VER 1000#pragma once#endif / _MSC_VER 1000#include lass.hclass Department public: void ClaMenu(Class *ClaType); void DispAll(); char Pname10; char
11、Pno5; int ClaCount; Department *next; Class *Cla; Department(); Department(char *Pno1,char *Pname1) next= NULL; Cla=NULL; ClaCount = 0; strcpy(Pno,Pno1); strcpy(Pname,Pname1); virtual Department(); bool AddClass(char *cno,char *cname,char *pno); bool DeleteClass(char *no); Class * FindsClass(char *n
12、o); friend ostream &operator (ostream &oc,Department &obj); /重载(istream &ic,Department &obj); /重载;#endif / !defined(AFX_DEPANTMENT_H_A6895DC1_C3F3_4737_88EC_AE2DA280272E_INCLUDED_)/*/5 School.h文件#if !defined(AFX_SCHOOL_H_7D278A4A_44F9_45A2_B3D6_35306E25BEFE_INCLUDED_)#define AFX_SCHOOL_H_7D278A4A_44
13、F9_45A2_B3D6_35306E25BEFE_INCLUDED_#if _MSC_VER 1000#pragma once#endif / _MSC_VER 1000#include Depantment.hclass School public: void DepMenu(Department *depType); void DispAll(); Department *root; int DeptCount; School(); virtual School(); bool AddDept(char *pno,char *pname); bool DeleteDept(char *n
14、o); Department * FindDept(char *no); void save(); /将班级记录存入指定文件 void load(); /从指定文件装载班级记录;#endif / !defined(AFX_SCHOOL_H_7D278A4A_44F9_45A2_B3D6_35306E25BEFE_INCLUDED_)/*/6 School.cpp文件#include School.h/ Construction/Destruction/School:School() root=NULL; DeptCount = 0;School:School() if(root!=NULL)
15、delete root;bool School:AddDept(char *pno,char *pname) Department *temp,*old; temp= old= root; while(temp!=NULL) if(strcmp(temp-Pno,pno)=0) coutt这个系pno已经存在!next ; if(temp=NULL) Department *ptr; ptr= new Department(pno,pname); ptr-next= NULL; if (old != NULL) old-next = ptr; else root = ptr; DeptCoun
16、t+; couttpname(pno)加入成功!Pno,no)!=0) old= temp; temp= temp-next ; else old-next= temp-next ; coutt系号为no的系已经成功删除!endl; return true; if(temp=NULL) coutt系号为no的系不存在!Pno,no)=0) coutt系号为no的系已经找到!next ; if(temp=NULL) coutt系号为no的系不存在!endl; return NULL;void School:DispAll() Department *temp; temp= root; coutt
17、系名tt系号endl; while(temp!=NULL) couttPname ttPnonext ; void School:DepMenu(Department *depType) int sel; sel = 1; char cname10; char cno5; while(sel) coutendlendl; cout请选择您的操作:endlendl; cout 1.增加班级;endl; cout 2.查找班级;endl; cout 3.显示所有班级;endl; cout 4.删除班级;endl; cout 0.退出;endl; coutsel; cout=0 & sel=4) s
18、witch(sel) case 1: coutcno; coutendl; coutcname; coutAddClass(cno,cname,depType-Pno); break; case 2: Class* find; cout cno; find = depType-FindsClass (cno); if (find != NULL) cout班级号:Cno endl; cout班级名称:Cname endlendl; cout1.进入此班级endl; cout其他数返回上级菜单depsel; if (depsel = 1) /班级里菜单 depType-ClaMenu (find
19、); else break; break; case 3: coutt所有的班级信息为:DispAll (); break; case 4: coutcno; depType-DeleteClass (cno); break; case 0: break; else cout输入错误!请重新输入。; void School:save() if(root=NULL) coutt没有系记录可存!endl; return; ofstream out; out.open (school.dat,ios:out); if(!out) coutt文件不能打开!endl; return; coutt正在保存
20、系数据.endl; Department * p; p= root; out DeptCountt; while(p!=NULL) outnext ; out.close (); couttDeptCount 条记录已经存入文件!endl;void School:load() /从指定文件装载班级记录 /先清空当前列表 if(root!=NULL) delete root; root = NULL; DeptCount = 0; ifstream in; in.open (school.dat,ios:in| ios:nocreate); if(!in) coutt文件不能打开!endl; return; coutt正在读取系数据. count; for (int i= 0;i*p; if (root = NULL) root= p; old = root; else old-next = p; old = old-next; DeptCount+; in.close (); couttDeptCount 条记录已经读取!next; delete