高校人员管理系统c++课程设计报告.docx
《高校人员管理系统c++课程设计报告.docx》由会员分享,可在线阅读,更多相关《高校人员管理系统c++课程设计报告.docx(24页珍藏版)》请在冰点文库上搜索。
![高校人员管理系统c++课程设计报告.docx](https://file1.bingdoc.com/fileroot1/2023-4/30/3546d918-15ef-49b5-a6e6-107ec0b19e8a/3546d918-15ef-49b5-a6e6-107ec0b19e8a1.gif)
高校人员管理系统c++课程设计报告
C++面向对象程序综合设计实验报告
2014年11月4日
要求:
设计一个程序,用于管理某高校教师、一般员工、学生的数据。
学生的数据包括姓名、年龄、身份证号、年级和学费;
教师的数据包括姓名、年龄、身份证号、课时和课时费;
一般员工的数据包括姓名、年龄、身份证号和月薪。
管理系统分析:
各类的分析:
本程序包含五个类,分别是:
基本信息类,学生类,教师类,职工类,系统管理类。
对象模型图如下:
基本信息类
系统管理类
输入人员信息
查询人员信息
界面显示
人员类别编号
类别名
姓名
年龄
身份证号
数据输入
数据输出
取人员类别编号
教师类
课时
课时费
数据输入
数据输出
学生类
年级
学费
数据输入
数据输出
一般员工类
月薪
数据输入
数据输出
基本信息类:
数据输入:
输入各人员信息:
姓名,年龄,身份证号;
数据输出:
输出各人员信息:
人员类别编号,姓名,年龄,身份证号;
学生类:
数据输入:
除了继承基本信息类的数据输入功能外,增加了输入“年级,学费”信息的功能。
数据输出:
除了继承基本信息类的数据输出功能外,增加了输出“年级,学费”信息的功能。
教师类:
数据输入:
除了继承基本信息类的数据输入功能外,增加了输入“课时,课时费”信息的功能。
数据输出:
除了继承基本信息类的数据输出功能外,增加了输出“课时,课时费”信息的功能。
一般员工:
数据输入:
除了继承基本信息类的数据输入功能外,增加了输入“月薪”信息的功能。
数据输出:
除了继承基本信息类的数据输出功能外,增加了输出“月薪”信息的功能。
基类和派生类设计:
基类(Record)
数据成员
Intnum;charname;intage;intID_number;
成员函数
IntGet_num;charGet_nme;intGet_age;intGet_ID_number;
VoidInput;voidOutput;
3个人员类除了继承基类Record的数据外,类Student还增加了数据成员年级Grade,学费Spent;类Teacher增加了数据成员课时Hour,课时费Hourly_wages;类Staff增加了数据成员月薪Salary。
系统管理类System的主要操作是:
成员函数In_information负责输入人员信息,成员函数Search负责查询人员信息,成员函数Interface负责界面的输出。
系统管理类的设计:
1、当系统启动完成后,自动将人员信息从数据文件中读入内存各对象数组中。
这个功能由系统管理类System的构造函数自动调用函数save完成。
如
System:
:
system()
{save();}
所有人员的信息都存在一个数据文件中,由于不同种类人员信息的长度不同,如何从数据文件里将这些数据读出并存放到各自相对应的对象数组中是一个问题,解决的方法是:
每次从数据文件中读取基类大小的一条信息存入基类对象中,并获得这条信息的种类编号,通过人员类别编号可以判定人员的类别,然后将指针回指到这条信息的开头,从人员文件中重新读取完整的人员信息,存入对应的对象数组中。
如:
基本信息类Record的对象是A
学术类student的对象是B[j1]
从数据文件里将相关的学生数据读出并存放到对象B[j1]中,有关程序段如下:
fstreamdatafile(fileName,ios:
:
in|ios:
:
out|ios:
:
binary);
datafile.read((char*)&A,sizeof(Record));
while(!
datafile.eof())
{
a=A.Get_num();
switch(a)
{
case1:
{
datafile.seekp(-1*sizeof(classRecord),ios:
:
cur);
datafile.read((char*)&B[j1],sizeof(Student));
……
}
……
}
2、信息的输入
信息的输入功能由成员函数In_information来完成,他根据要输入人员的类别分别调用对应的人员信息输入功能函数完成本类人员的输入。
有3个类别的人员信息输入函数:
Voidinfor1;//输入学生类对象数据
Voidinfor2;//输入教师类对象数据
Voidinfor3//输入一般员工对象数据
下面以infor1为例说明一条人员信息输入的实现过程:
voidSystem:
:
infor1()//输入学生对象数据
{
StudentA;
fstreamdatafile(fileName,ios:
:
in|ios:
:
out|ios:
:
binary);
datafile.seekp(0,ios:
:
end);//写指针指到文件尾部
A.Input();
datafile.write((char*)&A,sizeof(classStudent));
B[j1]=A;
datafile.close();
}
函数infor1完成一条学生对象信息的输入。
新增加的学生信息添加在文件的尾部,基本信息类Record对象A的属性值的录入是调用学生类Student提供的数据输入成员Input完成,学生类对象信息输入文件的同时,也保存一份在内存学生类对象数组B中。
3、信息的查询
信息查询功能由成员函数Search来完成。
它接收从键盘输入的人员类别编号和类别名,在对应的对象数组中查找,找到后通过调用对象的数据输出成员函数Output来显示人员信息。
例如查询人员信息的程序段如下:
If(strcmp(ch,B[s].Getname())==0)
{
B[s].Output();
...
}
4、界面的设计和实现
程序运行主要由System类中的成员函数Interface来完成,通过选择不同的菜单选项调用不同的成员函数完成各自的功能。
例如程序运行的主界面如下:
********************Welcome***********************
******PersonalInformationManagementSystem**********
1.Inputtheinformationofpersonal
2.Foundinformationandshowing
3.Exit
Pleaseselecting(1-4):
程序运行后结果:
程序调试问题:
在姓名输入的时候,如果输入字符中有“”,程序会被终止,所以个人觉得姓名的输入应该用gets()函数,这样就可以把中英文的名字都输入了。
在询问用户“是否继续输入(y/n)?
”以后的程序没有做异常处理。
如果输入的不是y/n,程序将自动终止。
另外,根据姓名来查找人员信息相当的不科学,因为可能有重名的情况。
改成用身份证号来查询人员信息更靠谱,而且身份证号也不应该定义为int型,有的身份证尾号是X,所以定义为char型更适合。
…………
实验心得:
写如此长的程序还是第一次,即便是有书上的内容作为参考,感觉也相当的困难。
而且该程序里还含有多个类,基类派生类,又是一个多文件程序,这些对我这种写代码少的人来说简直就是:
蜀道难,难于上青天!
值得高兴的是虽然手速慢,英语差,但还是把程序敲完了,而且错误也检查改正了。
忽略掉那些拼写错误的单词,这也是一件挺有成就感的事。
不过调试的时候又出问题了,程序编译过了,但什么东西都不显示。
当时跳楼的心都有了,不过还好有度娘在,解决了问题。
原来是“super.dat”这个文件没有建立,菜鸟就是菜鸟,如此低级的错误都犯了。
幸苦的同时也收获了不少,以前写代码总是照着书上的格式写,好多东西都似是而非,似懂非懂。
这次领悟到的东西还是不少的,比如说弄清了cout最后加endl的作用和不加的作用,如何实现一个系统,如何将数据文件中的信息读入内存对象数组……
最后感谢老师两月的幸苦,感谢旁边教我如何建立和运行多文件程序的那位同学,感谢无所不能的度娘……
源代码如下(改进版):
//Record.h
classRecord
{
protected:
intnum;
charname[30];
intage;
intID_number;
public:
Record(char*R_name="",intage1=0,intID_number1=0);
~Record(){}
intGet_num();
intGet_age();
intGet_ID_number();
char*Getname();
voidInput();
voidOutput();
};
classStudent:
publicRecord
{
intgrade;
floatspent;
public:
Student(char*R_name="",intage1=0,intID_number1=0,intgrade1=0,intspent1=0);
~Student(){}
voidInput();
voidOutput();
};
classTeacher:
publicRecord
{
floathour;
floathourly_wages;
public:
Teacher(char*R_name="",intage1=0,intID_number1=0,floathour1=0,floathourly_wages1=0);
~Teacher(){}
voidInput();
voidOutput();
/*data*/
};
classStaff:
publicRecord
{
floatsalary;
public:
Staff(char*R_name="",intage1=0,intID_number1=0,floatsalary=0);
~Staff(){}
voidInput();
voidOutput();
/*data*/
};
classSystem
{
RecordA;
StudentB[20];
TeacherC[20];
StaffD[20];
staticintj1,j2,j3;
voidinfor1();
voidinfor2();
voidinfor3();
voidsave();
voidSearch1(inth,charch[20]);
voidInterface1();
public:
System();
voidIn_information();
voidSearch();
voidInterface();
/*data*/
};
//Record.cpp
#include
#include
#include
#include
#include"Record.h"
usingnamespacestd;
#defineN30
charfileName[]="super.dat";
Record:
:
Record(char*R_name,intage1,intID_number1)
{
strcpy(name,R_name);
age=age1;
ID_number=ID_number1;
}
intRecord:
:
Get_num()
{
returnnum;
}
intRecord:
:
Get_age()
{
returnage;
}
intRecord:
:
Get_ID_number()
{
returnID_number;
}
char*Record:
:
Getname()
{
returnname;
}
voidRecord:
:
Input()
{
cout<<"\t\tName:
";
cin>>name;
cout<<"\t\tAge:
";
cin>>age;
cout<<"\t\tID_number:
";
cin>>ID_number;
}
voidRecord:
:
Output()
{
cout<cout<<"\t\tInformationOfPersonal:
"<cout<<"\t\tClassfiednumber:
"<cout<<"\t\tName:
"<cout<<"\t\tage:
"<cout<<"\t\tID_number:
"<}
Student:
:
Student(char*R_name,intage1,intID_number1,intgrade1,intspent1):
Record(R_name,age1,ID_number1)
{
num=1;
grade=grade1;
spent=spent1;
}
voidStudent:
:
Input()
{
Record:
:
Input();
cout<<"\t\tGrade:
";
cin>>grade;
cout<<"\t\tSpent:
";
cin>>spent;
}
voidStudent:
:
Output()
{
Record:
:
Output();
cout<<"\t\tGrade:
"<cout<<"\t\tSpent:
"<}
Teacher:
:
Teacher(char*R_name,intage1,intID_number1,floathour1,floathourly_wages1):
Record(R_name,age1,ID_number1)
{
num=2;
hour=hour1;
hourly_wages=hourly_wages1;
}
voidTeacher:
:
Input()
{
Record:
:
Input();
cout<<"\t\tHour:
";
cin>>hour;
cout<<"\t\tHourly_wages:
";
cin>>hourly_wages;
}
voidTeacher:
:
Output()
{
Record:
:
Output();
cout<<"\t\tHour:
"<cout<<"\t\tHourly_wages:
"<}
Staff:
:
Staff(char*R_name,intage1,intID_number1,floatsalary1):
Record(R_name,age1,ID_number1)
{
num=3;
salary=salary1;
}
voidStaff:
:
Input()
{
Record:
:
Input();
cout<<"\t\tSalary:
";
cin>>salary;
}
voidStaff:
:
Output()
{
Record:
:
Output();
cout<<"\t\tSalary:
"<}
intSystem:
:
j1=0;
intSystem:
:
j2=0;
intSystem:
:
j3=0;
System:
:
System()
{
save();
}
voidSystem:
:
Interface1()
{
cout<<"\n\n\n";
cout<<"\t\t******Accordingtotheclassinformation******"<cout<<"\t\t**********Selectingtheinformation***********"<cout<<"\t\t1.Student"<cout<<"\t\t2.Teacher"<cout<<"\t\t3.Staff"<cout<<"\t\t4.Exit"<cout<<"\t\tPleaseselectingtheclass:
";
}
voidSystem:
:
In_information()
{
intrev1;
intagain=1;
chart;
while(again)
{
Interface1();
cin>>rev1;
switch(rev1)
{
case1:
infor1();
break;
case2:
infor2();
break;
case3:
infor3();
break;
case4:
Interface();
break;
default:
cout<<"\t\tThereisnothispersonal!
"<continue;
}
cout<<"\t\t\tInformationstoredsuccess!
"<cout<<"\t\t\tContinuetoInput(y/n)?
";
cin>>t;
cout<if(!
(t=='Y'||t=='y'))
again=0;
}
Interface();
}
voidSystem:
:
infor1()
{
StudentA;
fstreamdatafile(fileName,ios:
:
in|ios:
:
out|ios:
:
binary);
datafile.seekp(0,ios:
:
end);
A.Input();
datafile.write((char*)&A,sizeof(classStudent));
B[j1]=A;
datafile.close();
}
voidSystem:
:
infor2()
{
TeacherA;
fstreamdatafile(fileName,ios:
:
in|ios:
:
out|ios:
:
binary);
datafile.seekp(0,ios:
:
end);
A.Input();
datafile.write((char*)&A,sizeof(classTeacher));
C[j2]=A;
datafile.close();
}
voidSystem:
:
infor3()
{
StaffA;
fstreamdatafile(fileName,ios:
:
in|ios:
:
out|ios:
:
binary);
datafile.seekp(0,ios:
:
end);
A.Input();
datafile.write((char*)&A,sizeof(classStaff));
D[j3]=A;
datafile.close();
}
voidSystem:
:
save()
{
inta;
fstreamdatafile(fileName,ios:
:
in|ios:
:
out|ios:
:
binary);
datafile.read((char*)&A,sizeof(Record));
while(!
datafile.eof())
{
a=A.Get_num();
switch(a)
{
case1:
{
datafile.seekp(-1*sizeof(classRecord),ios:
:
cur);
datafile.read((char*)&B[j1],sizeof(Student));
j1++;
break;
}
case2:
{
datafile.seekp(-1*sizeof(classRecord),ios:
:
cur);
datafile.read((char*)&C[j2],sizeof(Teacher));
j2++;
break;
}
case3:
{
datafile.seekp(-1*sizeof(classRecord),ios:
:
cur);
datafile.read((char*)&D[j3],sizeof(Staff));
j3++;
break;
}
default:
break;
}
datafile.read((char*)&A,sizeof(Record));
}
datafile.close();
}
voidSystem:
:
Search1(inth,charch[20])
{
ints=0,found=0;
switch(h)
{
case1:
while(s{
if(strcmp(ch,B[s].Getname())==0)
{
B[s].Output();
cout<<"\t\t\t******************"<found=1;
}
s++;
}
break;
case2:
while(s{
if(strcmp(ch,C[s].Getname())==0)
{
C[s].Output();
cout<<"\t\t\t******************"<found=1;
}
s++;
}
break;
case3:
while(s{
if(strcmp(ch,D[s].Getname())==0)
{
D[s].Output();
cout<<"\t\t\t******************"<found=1;
}
s++;
}
break;
}
if(found==0)
cout<<"\n\n\t\tSorry,don'tseekoutthi