}
doubleIncoming()
{
returnSalary+Allowance+Hours*20;
}
};
3.7College类
3.7.1
College:
:
College(){
Person*p=newTeacher;
PL=p;
cout<<"自动装入数据...\n";Load();
}
头文件
intCollege:
:
Find(
intID,Person**p1,Person**p2);
public:
College();
//构造
~College();
//析构
voidAdd();
//增加职工
voidDelete();
//删除职工
voidModify();
//修改职工
voidPrint();
//输出职工信息
voidSave();
//职工信息存盘
voidLoad();
//职工信息装入
voidFinding();};
//查找职工
J>
3.7.2构造函数
//构造函数(创建个头结点的链表)
classCollege
{private:
Person*PL;voidClear();
3.7.3析构函数
College:
:
~College()//析构函数(仅保留个头结点){
Person*p=PL;
while(p)//逐个删除结点,包括头结点
{
PL=p->next;deletep;
p=PL;
}
PL=0;}
3.7.4Add函数
voidCollege:
:
Add()//增加职工
{
高校工资管理系统*******************\n\n\n"
增加职工,输入x结束**\n\n";
cout<<"\t\t*******cout<<"\n\t\t\t\t**
//查找尾结点
Person*p=PL;
while(p->next)p=p->next;
charch='m';
//创建新结点,录入数据,连接到链表Teacher*pt;Assistant*pa;Manager*pm;
Teacher_Assistant*pta;Manager_Teacher*pmt;
cout<<"职工分类码[0-教师,1-实验员,2-行政人员,3-教师兼实验员,4-行政兼教师]:
\n\n";
for(;ch!
='x';)
{
cout<<"类别:
";cin>>ch;
switch(ch){
case'0':
pt=newTeacher;pt->Input();p->next=pt;
break;
case'1':
pa=newAssistant;pa->Input();p->next=pa;
break;
case'2':
pm=newManager;pm->Input();p->next=pm;
break;
case'3':
pta=newTeacher_Assistant;pta->Input();p->next=pta;
break;
case'4':
pmt=newManager_Teacher;pmt->Input();p->next=pmt;
break;
}p=p->next;
}}
3.7.5Find函数
//查找职工结点(返回-找到,-未找到.结点指针由p1返回,p2为前看指针)
intCollege:
:
Find(intID,Person**p1,Person**p2)
{
*p1=PL->next;
*p2=PL;
while(*p1)
{
if((*p1)->No==ID)
break;//找到
else
{
*p2=*p1;//继续查找
*p1=(*p1)->next;
}
}
return*p1?
1:
0;
}
3.7.6Clear函数
voidCollege:
:
Clear()//清除所有的职工结点(仅保留头结点){
Person*p=PL->next;while(p)
{
PL->next=p->next;deletep;
p=PL->next;
}
}
3.7.7Delete函数
//删除职工
voidCollege:
:
Delete()
高校工资管理系统*******************\n\n\n"删除职工**\n";
{
cout<<"\t\t*******
cout<<"\n\t\t\t\t**intNo;
Person*p1,*p2;
cout<<"编号:
";cin>>No;
if(!
Find(No,&p1,&p2))
{
cout<<"指定的人员没有找到!
\n";
}
else
{
//连接
p2->next=p1->next;
deletep1;
cout<<"正确删除!
\n";}
}
3.7.8
Modify函数
3.7.9
Print函数
"\t\t****************高校工资管理系统*******************\n\n\n""\n**职工信息表**\n\n";
"编号\t姓名\t岗位\t\t其它\t工资\n";
Person*p=PL->next;
if(!
p)
{
cout<<"无职工记录!
\n";
return;
}
while(p)//遍历链表,输出职工信息
{p->Output();p=p->next;
}
}
voidCollege:
:
Save()
{
ofstreamf("Person.dat",ios:
:
out);
//遍历输出至文件
Person*p=PL->next;
while(p)
{p->Output(f);p=p->next;
}
f.close();//关闭文件
cout<<"职工信息已经保存在Person.dat.\n";}voidCollege:
:
Load()
{
charbuf[81];
charDuty;
Person*p2;
//职工信息存盘
//职工信息装入
//临时空间
//人员类型
//新建结点的指针
longt;//读写位置
//清除现有结点(保留头结点)
Clear();
//打开文件
ifstreamf("Person.dat",ios:
:
in);
//建立结点,读数据
Person*p=PL;//尾结点指针while
(1)
{
//读取人员类型t=f.tellg();f>>buf>>buf>>Duty;
if
{
(f)
//根据人员类型创建新结点switch(Duty)
case
case
case
casecase
'0'
'1'
'2'
'3'
'4'
p2=
p2=
p2=
p2=p2=
default:
f.close();
//打开文件
newTeacher;newAssistant;newManager;newTeacher_Assistant;break;newManager_Teacher;break;
return;
break;
break;
break;
p->next=p2;p=p->next;f.seekg(t);p->Input(f);
}
else
break;
}
关闭文件
//
f.close();
高校工资管理系统*******************\n\n\n"查找职工**\n";
cout<<"Person.dat数据已装入.\n";}voidCollege:
:
Finding(){
cout<<"\t\t*******cout<<"\n\t\t\t\t**
Person*p1,*p2;intID;
coutvv"编号;";
cin>>ID;
coutvv"\n\n";
p1=PL->next;p2=PL;
while(p1)
{
if((p1)->No==ID)
{
coutvv"编号\t姓名\t岗位\t\t其它\t工资\n";(p1)->Output();
break;
}//找到
else
{
p2=p1;//继续查找
p1=(p1)->next;
}
}
}
3.8界面函数
charMeau(){
charc;intflag;
do
{
system("cls");flag=1;
cout<<"\t\t****
*\n\n\n""\t\t\t"\t\t\t"\t\t\t"\t\t\t
cout<<
cout<<
cout<<
cout<cout<<"\t\t\t
cout<<"\t\t\tcout<<"\t\t\tcout<<"\t\t\tcout<<"\t\t\tcout<<"\t\t\t
1
1
11
1
、增加职工
12
、删除职工
3
、查找职工丨
14
、修改职工
15
、输出职工信息
6
、数据存盘丨
7
、数据装入丨
8
1
、退出丨
1
高校工资管理系统
\n";
\n";
\n";
\n";
\n";
\n";
\n";
\n";
\n";
\n";
\n";
cout<<"\n\n\n\t\t请输入您的选择:
cin>>c;
if(c=='1'||c=='2'||c=='3'||c=='4'||c==flag=0;
}while(flag);returnc;
}//显示主菜单,
'5'||c=='6'
||c=='7'||c=='8')
接受选择
3.9主函数
voidmain()
{
charch;
//定义大学对象
Collegec;
do{
ch=Meau();
switch(ch){
case'1':
system("cls");c.Add();cout<<
"\n\n\t\t
按任意键结
束...\n";getchar();getchar();break;
case'2':
system("cls");c.Delete();cout<<束...\n";getchar();getchar();break;
"\n\n\t\t
按任意键结
case'3':
system("cls");c.Finding();cout<<束...\n";getchar();getchar();break;
"\n\n\t\t
按任意键结
case'4':
system("cls");c.Modify();cout<<束...\n";getchar();getchar();break;
"\n\n\t\t
按任意键结
case'5':
system("cls");c.Print();cout<<束...\n";getchar();getchar();break;
"\n\n\t\t
按任意键结
5.1主界面
实现各种功能的选择:
5.2
添加功能
6.设计体会与建议
6.1体会
通过这次对《高校工资管理系统》这个实验的设计,充分感受并体会到了C++中的
面对对象设计的真意,以及学习了对一个程序的分解和分工完成的方法,掌握了一点编写的技巧。
实际的操作与解决问题的能力更有了大幅的提升。
6.2建议
希望在以后的课程设计中,能更多的得到老师的帮助,可以帮助我们更清晰地理清思路,以及一些编程上的技巧。
7.附录
7.1成员
7.2分工