📄 11.cpp
字号:
{
//查找尾结点
Person *p=PL;
while(p->next)p=p->next;
//创建新结点,录入数据,连接到链表
Teacher *pt;
Assistant *pa;
Manager *pm;
Logistic *pta;
Invitation *pmt;
int revl;
int again=1;
char t;
while(again)
{
Interface1();
cin>>revl;
switch(revl)
{
case 1: pt=new Teacher; pt->Input();
p->next=pt; break;
case 2: pa=new Assistant; pa->Input();
p->next=pa; break;
case 3: pm=new Manager; pm->Input();
p->next=pm; break;
case 4: pta=new Logistic; pta->Input();
p->next=pta; break;
case 5: pmt=new Invitation; pmt->Input();
p->next=pmt; break;
case 6: Interface();
default:
cout<<"\t\t\t 没有此类职员!"<<endl;
break;
}
cout<<"\t\t\t 是否继续输入(y/n)? ";
cin>>t;
cout<<endl;
if(!(t=='Y'||t=='y'))
again=0;
}
Interface();
}
void College::Clear() //清除所有的职工结点(仅保留头结点)
{
Person *p=PL->next;
while(p)
{
PL->next=p->next;
delete p;
p=PL->next;
}
}
//查找职工结点(返回1-找到,0-未找到.结点指针由p1返回,p2为前看指针)
int College::Find(int ID,Person **p1,Person **p2)
{
*p1=PL->next;
*p2=PL;
while(*p1)
{
if((*p1)->No==ID)
{cout<<"\t\t 姓名:"<<(*p1)->Name<<endl;
cout<<"\t\t 工作证号:"<<(*p1)->No<<endl;
cout<<"\t\t 工资:"<<(*p1)->Incoming()<<endl;
//p1->Output();
break; } //找到
else
{
*p2=*p1; //继续查找
*p1=(*p1)->next;
}
}
if (*p1==0)
{
cout<<"\n\n\t\t 对不起,该类别中没有您所要查询的职员!"<<endl;
}
return *p1?1:0;
}
//查找职工结点(返回1-找到,0-未找到.结点指针由p1返回,p2为前看指针)
int College::Find1(char *NAME,Person **p1,Person **p2)
{
*p1=PL->next;
*p2=PL;
while(*p1)
{
//if((*p1)->Name==NAME)//
if(strcmp(NAME ,(*p1)->Name)==0)
{ cout<<"\t\t 姓名:"<<(*p1)->Name<<endl;
cout<<"\t\t 工资:"<<(*p1)->Incoming()<<endl;
//p1->Output();
break;} //找到
else
{
*p2=*p1; //继续查找
*p1=(*p1)->next;
}
}
if(*p1==0){ cout<<"\n\n\t\t 对不起,该类别中没有您所要查询的职员!"<<endl;}
return *p1?1:0;
}
void College::Delete() //删除职工
{
int No;
Person *p1,*p2;
cout<<"\t\t 请输入要删除的职工的编号:";
cin>>No;
if(!Find(No,&p1,&p2))
{
cout<<"\t\t 指定的人员没有找到!"<<endl;
}
else
{
p2->next=p1->next; //连接
delete p1;
cout<<"\t\t 正确删除!"<<endl;
Save();
}
}
void College::Modify() //修改职工
{
//cout<<"\t\t 修改职工:"<<endl;
int No;
Person *p1,*p2;
cout<<"\t\t 编号:";
cin>>No;
if(!Find(No,&p1,&p2))
{
cout<<"\t\t 指定的人员没有找到!"<<endl;
}
else
{
p1->Output(); //输出原来的职工信息(做提示)
p1->Input(); //输入新的职工信息(更新)
cout<<"\t\t 修改完成!"<<endl;
Save();
}
Interface();
}
void College::Print() //输出职工信息
{
cout<<endl<<endl;
Person *p=PL->next;
if(!p)
{
cout<<"\t\t\t 无职工记录!"<<endl;
return;
}
while(p) //遍历链表,输出职工信息
{
p->Output();//
p=p->next;
}
Interface();
}
void College::Save() //职工信息存盘
{
ofstream f("Person.dat",ios::out);//打开文件
//遍历输出至文件
Person *p=PL->next;
while(p)
{
p->Output(f);
p=p->next;
}
f.close(); //关闭文件
cout<<"\t\t\t 信息存储成功! "<<endl;
cout<<"\t\t\t 职工信息已经保存在Person.dat"<<endl;
}
void College::Load() //职工信息装入
{
char buf[181]; //临时空间
int Duty; //人员类型
Person *p2; //新建结点的指针
long t; //读写位置
//清除现有结点(保留头结点)
Clear();
//打开文件
ifstream f("Person.dat",ios::in);
//建立结点,读数据
Person *p=PL; //尾结点指针
while(1)
{
//读取人员类型
t=f.tellg();
f>>buf>>buf>>buf>>Duty;
if(f)
{
//根据人员类型创建新结点
switch(Duty)
{
case 1: p2=new Teacher; break;
case 2: p2=new Assistant; break;
case 3: p2=new Manager; break;
case 4: p2=new Logistic; break;
case 5: p2=new Invitation; break;
default: f.close(); return;
}
p->next=p2;
p=p->next;
f.seekg(t);
p->Input(f);
}
else
break;
}
//关闭文件
f.close();
Interface();
}
void College::Salary()
{
Person *p1,*p2;
int rev,no;
char name[20];
int again=1;
char t;
while(again)
{
Interface2();
cout<<"\n\t\t 请输入所要查看职员的类别:";
cin>>rev;
if (rev==1)
{
cout<<"\n\t\t 请输入所要查看的职员的工作证号:";
cin>>no;
Find(no,&p1,&p2);
}
if(rev==2)
{cout<<"\n\t\t 请输入所要查看的职员的姓名:";
cin>>name;
Find1(name,&p1,&p2);
}
cout<<"\t\t\t 是否继续查看工资(y/n)?";
cin>>t;
cout<<endl;
if(!(t=='Y'||t=='y'))
again=0;
}
Interface();
}
void College::Interface3()
{
cout<<"\n\n\n";
cout<<"\t\t *********按职员类别进行管理**********"<<endl;
cout<<"\t\t ************高校职员类别**********"<<endl;
cout<<"\t\t 1.教师 "<<endl;
cout<<"\t\t 2.实验室人员 "<<endl;
cout<<"\t\t 3.行政人员 "<<endl;
cout<<"\t\t 4.后勤人员 "<<endl;
cout<<"\t\t 请您选择职员类别: ";
}
void College::Interface2()
{
cout<<"\n\n\n";
cout<<"\t\t *********按职员类别进行管理**********"<<endl;
cout<<"\t\t ************高校职员类别**********"<<endl;
cout<<"\t\t 1.校内老师 "<<endl;
cout<<"\t\t 2.外骋人员 "<<endl;
cout<<"\t\t 请您选择职员类别: ";
}
void College::Interface1()
{
cout<<"\n\n\n";
cout<<"\t\t *********按职员类别进行管理**********"<<endl;
cout<<"\t\t ************高校职员类别**********" <<endl;
cout<<"\t\t 1.教师 "<<endl;
cout<<"\t\t 2.实验室人员 "<<endl;
cout<<"\t\t 3.行政人员 "<<endl;
cout<<"\t\t 4.后勤人员 "<<endl;
cout<<"\t\t 5.外骋人员 "<<endl;
cout<<"\t\t 6.退出 "<<endl;
cout<<"\t\t 请您选择职员类别(1-6): ";
}
void College::Interface()
{
int rev;
cout<<"\n\n\n\n\n\n\n";
cout<<"\t\t *****************欢迎使用";
cout<<"*****************"<<endl;
cout<<"\t\t **********高校工资管理系统";
cout<<"**********"<<endl;
cout<<"\t\t 1.添加职员信息 "<<endl;
cout<<"\t\t 2.删除职员信息 "<<endl;
cout<<"\t\t 3.修改职员信息 "<<endl;
cout<<"\t\t 4.显示职员的信息 "<<endl;
cout<<"\t\t 5.查询职员的工资 "<<endl;
cout<<"\t\t 6.保存职工信息 "<<endl;
cout<<"\t\t 7.退出 "<<endl;
cout<<"\t\t 请您选择(1-7):";
cin>>rev;
switch(rev)
{
case 1:
Add();
break;
case 2:
Delete();
break;
case 3:
Modify();
break;
case 4:
Print();
break;
case 5:
Salary();
break;
case 6:
Save();
break;
case 7:
exit(0);
}
}
void main()
{
College c;
//c.Load();
c.Interface();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -