#include<iostream>
#include<string>
#include<fstream>
#include<iomanip>
using namespace std;
double sum,avarage;
int amount=0;
int ab=0,cd=0,ef=0;
ofstream *file[50];
struct xinxi
{
double jiben;
double zhiwu;
double gangwei;
double yiliao;
double gongji;
double sum;
double sum1;
double avarage;
struct xinxi *next;
};
class worker
{
public:
string name;
string ID;
double sum;
double avarage;
xinxi sc1;
class worker *next;
};
void luru(worker *head);
void search1(worker *head);
void search2(worker *head);
void xianshi(worker *head);
void xiugai(worker *head);
void chazhao(worker *head);
void shanchu(worker *head);
void tianjia(worker *head);
void tongji(worker *head);
void display();
void read(worker *head);
void dakai(worker *head);
int main()
{
system("color ff");
int x;
//bool flag2=0;
/*do
{
do
{
cin>>x;
if(x>=0&&x<=10)
flag2=1;
else
{
cout<<"~~~~~~~~~~~~指令错误!!!~~~~~~~~~~"<<endl;
cout<<"请选择相应数字进行操作"<<endl;
}
}
while(flag2==0)*/
worker *head=new worker;
head->next=NULL;
while(1)
{
display();
cin>>x;
if(x==1)
{
cout<<"***************现在进行职工数据的录入*****************\n";
luru(head);
cout<<"输入的职工信息为:\n";
xianshi(head);
display(); //break;
}
else
if(x==2)
{
cout<<"***************现在进行职工数据的修改******************\n";
xiugai(head);
display();
//break; //按姓名修改
}
else if(x==3)
{
cout<<"***************现在进行所有职工信息的显示*****************\n";
xianshi(head);
display();
//break; //显示数据
}
else if(x==4)
{
char z;
cout<<"*****************现在进行所有职工信息查找**************\n";
cout<<"请选择查询方式\n";
cout<<"(1).姓名查询方式 (2).ID查询方式\n";
cin>>z;
while(z!='1'&&z!='2')
{
cout<<"**************指令错误********************\n";
cout<<"(1).姓名查询方式 (2).ID查询方式\n";
cin>>z;
}
switch(z)
{
case '1': search1(head);break;//按姓名查询
case '2': search2(head);break;//按学号查询
}
display();
//
break;
}
else if(x==5)
{
cout<<"***************现在进行指定的职工信息的删除*****************\n";
shanchu(head);
xianshi(head);
display();
//break; //删除
}
else if(x==6)
{
cout<<"****************现在进行指定的职工信息的添加******************\n";
tianjia(head);
xianshi(head);
display();
break;//添加
}
else if(x==7)
{
cout<<"**********************现在进行指定的职工信息的统计***************\n";
tongji(head);
display();
//
break;
}
else if(x==8)
{
cout<<"**********************现在进行指定的职工信息的保存************\n";
read(head);
display();
// break;
}
else if(x==9)
{
cout<<"************************现在进行指定的职工信息的打开****************\n";
dakai(head);
display();
//
break;
}
else
{
cout<<"
╔═══════════════════════════╗\n";
cout<<"
║
您已退出职工管理系统, 谢谢您的使用!
║\n";
cout<<"
╚═══════════════════════════╝\n";
cout<<endl;
exit(0);
break;
}
}
return 0;
}
void display()
{
cout<<"
╔═══════════════════════════╗"<<endl;
cout<<"
║
☆ 职工管理系统 ☆
║"<<endl;
cout<<"
║═══════════════════════════║"<<endl;
cout<<"
║
║"<<endl;
cout<<"
║
(1)职工数据的录入
║"<<endl;
cout<<"
║
(2)职工数据的修改
║"<<endl;
cout<<"
║
(3)显示职工信息
║"<<endl;
cout<<"
║
(4)查询职工信息
║"<<endl;
cout<<"
║
--(1)按姓名查询
║"<<endl;
cout<<"
║
--(2)按ID查询
║"<<endl;
cout<<"
║
--统计总成绩和平均成绩
║"<<endl;
cout<<"
║
(5)职工信息的删除
║"<<endl;
cout<<"
║
(6)职工信息的添加
║"<<endl;
cout<<"
║
(7)职工信息的统计
║"<<endl;
cout<<"
║
(8)保存职工信息
║"<<endl;
cout<<"
║
(9)打开职工信息
║"<<endl;
cout<<"
║
退出程序
║"<<endl;
cout<<"
║
║"<<endl;
cout<<"
║═══════════════════════════║"<<endl;
cout<<"
║注:请输入相应括号里的阿拉伯数字来执行相关操作!
║"<<endl;
cout<<"
║
要保存数据请先建立好指定文件:
║"<<endl;
cout<<"
║
(D:\\职工管理系统\\职工信息.txt)
║"<<endl;
cout<<"
╟------------------------------------------------------╢"<<endl;
cout<<"
║===================谢谢您的使用=======================║"<<endl;
cout<<"
╚═══════════════════════════╝"<<endl;
cout<<"
→请选择相应的数字进行操作: "<<endl;
}
////////////////////////////////显示学生数据
void xianshi(worker *head)
{
worker *work=head->next;
cout<<" | name | ID |基本工资|职务工资|岗位津贴|医疗保险|公积金|总工资|平均工资|"<<endl;
while(work!=NULL)
{
cout<<" | "<<setw(4)<<(*work).name;
cout<<" | "<<setw(4)<<(*work).ID;
cout<<" | "<<setw(4)<<(*work).sc1.jiben;
cout<<" | "<<setw(4)<<(*work).sc1.zhiwu;
cout<<" | "<<setw(4)<<(*work).sc1.gangwei;
cout<<" | "<<setw(4)<<(*work).sc1.yiliao;
cout<<" | "<<setw(4)<<(*work).sc1.gongji;
cout<<" | "<<setw(4)<<(*work).sc1.sum;
cout<<" | "<<setw(4)<<(*work).sc1.avarage;
cout<<" | "<<endl;
work=work->next;
}
system("pause");
}
void read(worker *head)
{
char a;
worker *work=head->next;
cout<<"现在保存输入职工数据,是否继续操作?(y/n)";
cin>>a;
ofstream outfile("D:\\职工管理系统\\职工信息.txt",ios::out);
if(! outfile)
{
cout<<"!!!!!!!!打开文件错误!!!!!!!\n";
cout<<"!!!要保存数据请先建立好指定文件:D:\\职工管理系统\\职工信息.txt!!!\n";
exit(0);
}
while(a!='n')
{
while(work!=NULL)
{
outfile<<"****************第"<<amount<<"个职工的数据:***************\n";
outfile<<" | name | ID |基本工资|职务工资|岗位津贴|医疗保险|公积金|总工资|平均工资|"<<endl;
outfile<<" 职工信息: \n" <<" | "<<setw(4)<<(*work).name<<" | "<<setw(4)<<(*work).ID<<" | "<<setw(4)<<(*work).sc1.jiben<< " | "<<setw(4)<<(*work).sc1.zhiwu<<" | "<<setw(4)<<(*work).sc1.gangwei <<"|"<<setw(4)<<(*work).sc1.yiliao <<"|" <<setw(4)<<(*work).sc1.gongji <<"|"<<setw(4)<<(*work).sc1.sum<<"|"<<setw(4)<<(*work).sc1.avarage<<"|"<< endl;
amount++;
work=work->next;
}
break;
}
cout<<"......成功将学生数据保存到<职工信息.txt>中! ";
outfile.close();
}
void dakai(worker *head)
{
worker *work=head->next;
ofstream ofile("D:\\职工管理系统\\职工信息.txt",ios::out);
work=work->next;
}
void luru(worker *head)
{
char c;
int j=0;
worker *p=head;
file[j]=new ofstream("D:\\职工管理系统\\职工信息.txt",ios::app);
do
{
worker *work=new worker;
cout<<"请输入姓名:"<<setw(10);
cin>>(*work).name;
cout<<"请输入ID:"<<setw(10);
cin>>(*work).ID;
cout<<"请输入基本工资:"<<setw(2);
cin>>(*work).sc1.jiben;
cout<<"请输入职务工资:"<<setw(2);
cin>>(*work).sc1.zhiwu;
cout<<"请输入岗位津贴:"<<setw(2);
cin>>(*work).sc1.gangwei;
cout<<"请输入医疗保险:"<<setw(2);
cin>>(*work).sc1.yiliao;
cout<<"请输入公积金:"<<setw(2);
cin>>(*work).sc1.gongji;
(*work).sc1.sum=(*work).sc1.gangwei+(*work).sc1.gongji+(*work).sc1.yiliao+(*work).sc1.zhiwu+(*work).sc1.jiben;
(*work).sc1.avarage=((*work).sc1.gangwei+(*work).sc1.gongji+(*work).sc1.yiliao+(*work).sc1.zhiwu+(*work).sc1.jiben)/5;
(*work).sc1.sum1=(*work).sc1.gangwei+(*work).sc1.zhiwu+(*work).sc1.jiben;
if((*work).sc1.sum1>=2000) ab++;
if((*work).sc1.sum1>=1500&&(*work).sc1.sum1<2000) cd++;
if((*work).sc1.sum1>=1000&&(*work).sc1.sum1<1500) ef++;
work->next=p->next;
p->next=work;
amount++;
cout<<"数据录入成功,想继续录入吗(y/n)"; cin>>c;
p=p->next;
while(c!='y'&&c!='n')
{
cout<<"!!!!!!!!!!指令错误<请输入y/n!>!!!!!!!!!!"<<endl;
cout<<"数据录入成功,想继续录入吗(y/n)";
cin>>c;
}
}while(c=='y');
j++;
cout<<"输入了 "<<amount<<"个职工的信息."<<endl;
}
void search1(worker *head)
{
char c;
string name;
do{
worker*work=head->next;
bool flag=0;
cout<<"请输入要查找的职工的姓名:";
cin>>name;
do{
if(work!=NULL&&name==(*work).name)
{
flag=1;
cout<<" | name | ID |基本工资|职务工资|岗位津贴|医疗保险|公积金|总工资|平均工资|"<<endl;
cout<<" | "<<setw(4)<<(*work).name;
cout<<" | "<<setw(4)<<(*work).ID;
cout<<" | "<<setw(4)<<(*work).sc1.jiben;
cout<<" | "<<setw(4)<<(*work).sc1.zhiwu;
cout<<" | "<<setw(4)<<(*work).sc1.gangwei;
cout<<" | "<<setw(4)<<(*work).sc1.yiliao;
cout<<" | "<<setw(4)<<(*work).sc1.gongji;
cout<<" |"<<setw(4)<<(*work).sc1.sum;
cout<<" |"<<setw(4)<<(*work).sc1.avarage;
cout<<" | "<<endl;
}
work=work->next;
}while(work!=NULL);
if(flag==0)
cout<<"!!!!!!!!!!!!!对不起!您要查询的职工不存在!!!!!!!!!!!"<<endl;
cout<<"您想继续查询吗?(y/n)"; cin>>c;
while(c!='y'&&c!='n')
{
cout<<"!!!!!!!!!!!!!!指令错误<请输入y/n!>!!!!!!!!!!!"<<endl;
cout<<"您想继续查询吗?(y/n)"; cin>>c;
}
}while(c=='y');
}
void search2(worker *head)
{
char c;
string ID;
do{
worker *work=head->next;
int flag=0;
cout<<"请输入要查找职工的ID";
cin>>ID;
do{
if(work!=NULL&&ID==(*work).ID)
{
flag=1;
cout<<"你要查询的学生是"<<work->name<<endl;
cout<<" | name | ID |基本工资|职务工资|岗位津贴|医疗保险|公积金|总工资|平均工资|"<<endl;
cout<<" | "<<setw(4)<<(*work).name;
cout<<" | "<<setw(4)<<(*work).ID;
cout<<" | "<<setw(4)<<(*work).sc1.jiben;
cout<<" | "<<setw(4)<<(*work).sc1.zhiwu;
cout<<" | "<<setw(4)<<(*work).sc1.gangwei;
cout<<" | "<<setw(4)<<(*work).sc1.yiliao;
cout<<" | "<<setw(4)<<(*work).sc1.gongji;
cout<<" | "<<setw(4)<<(*work).sc1.sum;
cout<<" | "<<setw(4)<<(*work).sc1.avarage;
cout<<" | "<<endl;
}
work=work->next;
}while(work!=NULL);
if(flag==0)
cout<<"!!!!!!!!!!!!!!!对不起!您要查询的职工不存在!!!!!!!!!!!!!!!"<<endl;
cout<<"您想继续查询吗?(y/n)";
cin>>c;
while(c!='y'&&c!='n')
{
cout<<"!!!!!!!!!!!!指令错误<请输入y/n!>!!!!!!!!!!"<<endl;
cout<<"您想继续查询吗?(y/n)"<<endl;
cin>>c;
}
}while(c=='y');
}
void xiugai(worker *head)
{
string name;
char c;
do
{
bool flag2=0;
worker *work=head->next;
xinxi sc1;
cout<<"请输入你要修改的职工的姓名:";
cin>>name;
do{
if(name==(*work).name)
{
flag2=1;
cout<<"请输入新的基本工资:";
cin>>sc1.jiben;
cout<<"请输入新的职务工资:";
cin>>sc1.zhiwu;
cout<<"请输入新的岗位津贴:";
cin>>sc1.gangwei;
cout<<"请输入新的医疗保险:";
cin>>sc1.yiliao;
cout<<"请输入新的公积金:";
cin>>sc1.gongji;
(*work).sc1.jiben=sc1.jiben;
(*work).sc1.zhiwu=sc1.zhiwu;
(*work).sc1.gangwei=sc1.gangwei;
(*work).sc1.sum=(*work).sc1.gangwei+(*work).sc1.gongji+(*work).sc1.jiben+(*work).sc1.yiliao+(*work).sc1.zhiwu;
(*work).sc1.avarage=((*work).sc1.gangwei+(*work).sc1.gongji+(*work).sc1.jiben+(*work).sc1.yiliao+(*work).sc1.zhiwu)/5;
cout<<" | name | ID |基本工资|职务工资|岗位津贴|医疗保险|公积金|总工资|平均工资|"<<endl;
cout<<" | "<<setw(4)<<(*work).name;
cout<<" | "<<setw(4)<<(*work).ID;
cout<<" | "<<setw(4)<<(*work).sc1.jiben;
cout<<" | "<<setw(4)<<(*work).sc1.zhiwu;
cout<<" | "<<setw(4)<<(*work).sc1.gangwei;
cout<<" | "<<setw(4)<<(*work).sc1.yiliao;
cout<<" | "<<setw(4)<<(*work).sc1.gongji;
cout<<" | "<<setw(4)<<(*work).sc1.sum;
cout<<" | "<<setw(4)<<(*work).sc1.avarage;
cout<<" | "<<endl;
cout<<"数据修改成功......";
break;
}
work=work->next;
}while(work!=NULL);
if(flag2==0)
{
cout<<"!!!!对不起!您要修改的职工不存在!请检查重新输入!!!!!"<<endl;
}
cout<<"想继续修改吗?(y/n)";
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"!!!!!!!!!!!!!!!指令错误!请重新输入<y/n>!!!!!!!!!!!!!";
cin>>c;
}
}while(c=='y');
}
void shanchu(worker *head)
{
char c;
string no;
do{
int flag=0;
cout<<"请输入要删除的职工ID";
cin>>no;
worker *p,*q;
q=head;
while(q->next!=NULL&&q->next->ID!=no)
q=q->next;
if(q->next!=NULL)
{
flag=1;
p=q->next;
q->next=q->next->next;
amount--;
free(p);
cout<<"......成功删除! ";
}
if(flag==0)
cout<<"!!!!!!!!!!!!!对不起!您要删除的职工不存在!!!!!!!!!"<<endl;
cout<<"您想继续删除吗?(y/n)";
cin>>c;
while(c!='y'&&c!='n')
{
cout<<"!!!!!!!!!!!!!指令错误<请输入y/n!>!!!!!!!!!!!!"<<endl;
cout<<"您想继续删除吗?(y/n)";
cin>>c;
}
}while(c=='y');
}
void tongji(worker *head)
{
char c;
string name;
do
{
worker *work=head->next;
bool flag=0;
cout<<"----总工资和平均工资的计算------"<<endl;
cout<<"请输入要统计职工的姓名";
cin>>name;
do{
if(work!=NULL&&name==(*work).name)
{
flag=1;
cout<<" | name | ID |基本工资|职务工资|岗位津贴|医疗保险|公积金|总工资|平均工资|"<<endl;
cout<<" | "<<setw(4)<<(*work).name;
cout<<" | "<<setw(4)<<(*work).ID;
cout<<" | "<<setw(4)<<(*work).sc1.jiben;
cout<<" | "<<setw(4)<<(*work).sc1.zhiwu;
cout<<" | "<<setw(4)<<(*work).sc1.gangwei;
cout<<" | "<<setw(4)<<(*work).sc1.yiliao;
cout<<" | "<<setw(4)<<(*work).sc1.gongji;
cout<<" | "<<setw(4)<<(*work).sc1.sum;
cout<<" | "<<setw(4)<<(*work).sc1.avarage;
cout<<" | "<<endl;
cout<<"超过2000的百分比:"<<endl;
cout<<(ab*100)/amount<<"%"<<endl;
cout<<"小于2000,大于等于1500"<<endl;
cout<<(cd*100)/amount<<"%"<<endl;
cout<<"小于1500,大于等于1000"<<endl;
cout<<(ef*100)/amount<<"%"<<endl;
}
work=work->next;
}while(work!=NULL);
if(flag==0)
cout<<"!!!!!!!!!!!!!对不起!您要查询的职工不存在!!!!!!!!!!!"<<endl;
cout<<"您想继续查询吗?(y/n)"; cin>>c;
while(c!='y'&&c!='n')
{
cout<<"!!!!!!!!!!!!!!指令错误<请输入y/n!>!!!!!!!!!!!"<<endl;
cout<<"您想继续查询吗?(y/n)"; cin>>c;
}
} while(c=='y');
}
void tianjia(worker *head)
{
char c;
int j=0;
worker *p=head;
file[j]=new ofstream("D:\\职工管理系统\\职工信息.txt",ios::app);
do
{
worker *work=new worker;
cout<<"请输入姓名:"<<setw(10);
cin>>(*work).name;
cout<<"请输入ID:"<<setw(10);
cin>>(*work).ID;
cout<<"请输入基本工资:"<<setw(2);
cin>>(*work).sc1.jiben;
cout<<"请输入职务工资:"<<setw(2);
cin>>(*work).sc1.zhiwu;
cout<<"请输入岗位津贴:"<<setw(2);
cin>>(*work).sc1.gangwei;
cout<<"请输入医疗保险:"<<setw(2);
cin>>(*work).sc1.yiliao;
cout<<"请输入公积金:"<<setw(2);
cin>>(*work).sc1.gongji;
(*work).sc1.sum=(*work).sc1.gangwei+(*work).sc1.gongji+(*work).sc1.yiliao+(*work).sc1.zhiwu+(*work).sc1.jiben;
(*work).sc1.avarage=((*work).sc1.gangwei+(*work).sc1.gongji+(*work).sc1.yiliao+(*work).sc1.zhiwu+(*work).sc1.jiben)/5;
(*work).sc1.sum1=(*work).sc1.gangwei+(*work).sc1.zhiwu+(*work).sc1.jiben;
if((*work).sc1.sum1>=2000) ab++;
if((*work).sc1.sum1>=1500&&(*work).sc1.sum1<2000) cd++;
if((*work).sc1.sum1>=1000&&(*work).sc1.sum1<1500) ef++;
work->next=p->next;
p->next=work;
amount++;
cout<<"数据添加成功,想继续添加吗(y/n)"; cin>>c;
p=p->next;
while(c!='y'&&c!='n')
{
cout<<"!!!!!!!!!!指令错误<请输入y/n!>!!!!!!!!!!"<<endl;
cout<<"数据添加成功,想继续添加吗(y/n)";
cin>>c;
}
}while(c=='y');
j++;
cout<<"输入了 "<<amount<<"个职工的信息."<<endl;
}