📄 thesystemofworkerssalary.txt
字号:
system("cls");
if(head==NULL) //若调用次函数以前的头指针head为空
{
cout<<" 这是一个空表,请先输入职工信息!\n";
return(head);
}
else
{
p1=head; //否则将头指针赋给p1
while(id!=p1->id&&p1->next!=NULL)
//寻找结点当p1所指的职工编号不是输入的职工编号并且p1所指的next指针不为空
{
p1=p1->next; //p2指向原p1指向的结点p1后移一个结点
}
if(id==p1->id) //如果要查找的职工编号是p1所指的职工编号
{
cout<<"------------------------------------------------------------------------------\n";
cout<<"|编 号| |姓 名| |性别| |基本工资| |加班工资| |其他奖金| |总额|\n";
cout<<"------------------------------------------------------------------------------\n";
cout<<setw(6)<<p1->id
<<setw(10)<<p1->name
<<setw(10)<<p1->sex
<<setw(10)<<p1->paid[0]
<<setw(10)<<p1->paid[1]
<<setw(12)<<p1->paid[2]
<<setw(12)<<p1->total<<endl;
cout<<"------------------------------------------------------------------------------\n";
}
else
cout<<"信息中没有编号为"<<id<<"的职工.\n"; //结点没找到
return(head);
}
}
//------------定义paixu()函数将职工的工资总额从大到小排列并输出
void Information::paixu(student *head)
{
system("cls");
int i,k,m=0,j;
student *p[N];//定义一个指向struct student的结构体指针数组p
if(head!=NULL)//如果头指针是空则继续
{ m=count(head);
cout<<"------------------------------------------------------------------------------\n";
cout<<" *职工工资统计表*\n";
cout<<"------------------------------------------------------------------------------\n";
cout<<"|编号| |姓名| |性别| |基本工资| |加班工资| |其他奖金| |总额| |名次|\n";
cout<<"------------------------------------------------------------------------------\n";
p1=head;
for(k=0;k<m;k++)
{
p[k]=p1;
p1=p1->next;
}
for(k=0;k<m-1;k++) //选择排序法
for(j=k+1;j<m;j++)
if(p[k]->total<p[j]->total)
{
p2=p[k];
p[k]=p[j];
p[j]=p2;
} //从大到小排列的指针
for(i=0;i<m;i++)
{
cout<<setw(6)<<p[i]->id
<<setw(8)<<p[i]->name
<<setw(9)<<p[i]->sex
<<setw(10)<<p[i]->paid[0]
<<setw(10)<<p[i]->paid[1]
<<setw(10)<<p[i]->paid[2]
<<setw(10)<<p[i]->total
<<setw(10)<<i+1<<endl;
cout<<"------------------------------------------------------------------------------\n";
}
}
}
//------------>求各工资的平均值的函数
void Information::average(student *head)
{
int k,m;
float arg1=0,arg2=0,arg3=0;
if(head==NULL)//如果头指针是空则继续
{
cout<<" 这是一个空表,请先输入职工信息!\n";
}
else
{
m=count(head);
p1=head;
for(k=0;k<m;k++)
{
arg1+=p1->paid[0];
arg2+=p1->paid[1];
arg3+=p1->paid[2];
p1=p1->next;
}
arg1/=m;arg2/=m;arg3/=m;
cout<<" *各项工资的平均值*\n";
cout<<"------------------------------------------------------------------------------\n";
cout<<"\t\t基本工资的平均值: "<<setw(4)<<arg1
<<"\n"<<"\t\t加班工资的平均值: "<<setw(4)<<arg2
<<"\n"<<"\t\t奖金的平均值: "<<setw(4)<<arg3<<"\n";
cout<<"------------------------------------------------------------------------------\n";
}
}
//------------------->保存函数.
void Information::save(student *head)
{
system("cls");
ofstream out("data",ios::out);
out<<count(head)<<endl;
while(head!=NULL)
{ out<<head->name<<"\t"
<<head->id<<"\t"<<"\t"
<<head->sex<<"\t"
<<head->paid[0]<<"\t"
<<head->paid[1]<<"\t"
<<head->paid[2]<<"\t"
<<head->total<<endl;
head=head->next;
}
}
//———————————>读取文件的信息
student *Information::Read()
{
system("cls");
int i=0;
p1=p2=( student *)malloc(LEN);
head=NULL;
ifstream in("data",ios::out);
in>>i;
if(i==0){cout<<" data 文件中的数据为空,请先输入数据!"<<endl; return 0;}
else {
cout<<"\n原文件已保存的信息如下:\n";
cout<<" ………………………………………………………………………………………………"<<endl;
cout<<"|姓 名| |编 号| |性别| |基本工资| |加班工资| |其他奖金| |总额|\n";
cout<<" ………………………………………………………………………………………………"<<endl;
for(;i>0;i--)
{
p1=(student *)malloc(LEN);
in>>st.name>>st.id>>st.sex
>>st.paid[0]>>st.paid[1]>>st.paid[2]>>st.total;
strcpy(p1->name,st.name);
p1->id=st.id;
strcpy(p1->sex,st.sex);
p1->paid[0]=st.paid[0];
p1->paid[1]=st.paid[1];
p1->paid[2]=st.paid[2];
p1->total=st.total;
if(n==0)head=p1; //如果是输入第一组职工信息就将指针p1赋给指针head
else p2->next=p1; //否则将p1赋给p2所指结构体的next指针
p2=p1; //将指针p1赋给指针p2
n++; //将n的值加1
//显示读入数据
cout<<" "<<p1->name<<"\t"
<<p1->id<<" \t"
<< p1->sex <<" \t"
<< p1->paid[0] <<" \t"
<< p1->paid[1] <<" \t"
<< p1->paid[2] <<" \t"
<< p1->total<<endl;
cout<<" ………………………………………………………………………………………………"<<endl;
}
cout<<" 数据已经成功读取完毕!\n\n"<<endl;
p2->next=NULL;
return (head);
}
}
//-------------------->菜单
void Menu()
{
Information person;
student *head=NULL;
int choice;
long i;
do{
cout<<"\t※※※※※※※※※※※※※※※※※※※※※※※※※※※"<<endl;
cout<<"\t※ ※"<<endl;
cout<<"\t※ _ _ _ 欢迎进入职工成绩统计管理 _ _ _ ※"<<endl;
cout<<"\t※ ※"<<endl;
cout<<"\t※※※※※※※※※※※※※※※※※※※※※※※※※※※"<<endl;
cout<<"\t "<<endl;
cout<<"\t 相关操作选项 "<<endl;
cout<<"\t "<<endl;
cout<<"\t※※※※※※※※※※※※※※※※※※※※※※※※※※※"<<endl;
cout<<"\t※ 0. 读取文件信息 ※"<<endl;
cout<<"\t※ ※"<<endl;
cout<<"\t※ 1. 职工数据输入 ※"<<endl;
cout<<"\t※ ※"<<endl;
cout<<"\t※ 2. 显示职工工资 ※"<<endl;
cout<<"\t※ ※"<<endl;
cout<<"\t※ 3. 排序统计工资 ※"<<endl;
cout<<"\t※ ※"<<endl;
cout<<"\t※ 4. 查找职工工资 ※"<<endl;
cout<<"\t※ ※"<<endl;
cout<<"\t※ 5. 增加职工工资 ※"<<endl;
cout<<"\t※ ※"<<endl;
cout<<"\t※ 6. 删除职工工资 ※"<<endl;
cout<<"\t※ ※"<<endl;
cout<<"\t※ 7. 修改职工信息 ※"<<endl;
cout<<"\t※ ※"<<endl;
cout<<"\t※ 8. 成功保存信息 ※"<<endl;
cout<<"\t※ ※"<<endl;
cout<<"\t※ 9. 安全退出系统 ※"<<endl;
cout<<"\t※ ※"<<endl;
cout<<"\t※※※※※※※※※※※※※※※※※※※※※※※※※※※\n"<<endl;
cout<<" 请输入您的选择(0--9):";
cin>>choice;
while(choice<0||choice>9)
{
cout<<" 对不起您的输入错误!请输入您的选择(0--9): ";
cin>>choice;
}
switch(choice)
{
case 0:
head=person.Read();break;
case 1:
head=person.creat();
break;
case 2:
person.output(head);
break;
case 3:
person.paixu(head); person.average(head);
cout<<" 参加工作的职工人数为:"<<person.count(head)<<"人\n\n";
break;
case 4:
cout<<" 请输入要查找的编号:";
cin>>i;
while(i<0||i>100000)
{
cout<<" 对不起您的输入错误!请重新输入: ";
cin>>i;
}
person.find(head,i);
break;
case 5:
head=person.insert(head);
person.output(head);
break;
case 6:
cout<<" 请输入要删除的编号:";
cin>>i;
while(i<0||i>100000)
{
cout<<" 对不起您的输入错误!请重新输入: ";
cin>>i;
}
head=person.cancel(head,i);
person.output(head);
break;
case 7:
cout<<" 请输入要修改的编号:";
cin>>i;
while(i<0||i>100000)
{
cout<<" 对不起您的输入错误!请重新输入: ";
cin>>i;
}
person.modify(head,i);
break;
case 8:
cout<<"信息已经成功保存!"<<endl;
person.save(head);
break;
case 9:
system("cls");
break;
default :
cout<<" 对不起您的输入有误!请重新输入:\n";
break;
}
}
while(choice!=9);
}
//----------------->管理员登陆
void Pass()
{
char UserName[30];
char Passward[20];
int i=0;
cout<<"****************************************************************************\n";
cout<<"\n\t为保护职工成绩信息,只有管理员才可以进行管理!\n";
cout<<"\n\t管理员名和登陆密码都只有4次机会,如果超过将自动退出系统!\n\n";
cout<<"****************************************************************************\n";
cout<<"\n请输入管理员名:";
cin>>UserName;
while (strcmp(UserName,"fangfangff")!=0)
{
if(i>=3)
exit(0); //超过4次则登陆失败,退出系统
i++;
cout<<"\n管理员名无效!请重新输入:";
cin>>UserName;
}
cout<<"\n请输入密码:";
cin>>Passward;
while(strcmp(Passward,"fangfangff")!=0)
{
if(i>=3)
exit(0); //超过4次则登陆失败,退出系统
i++;
cout<<"\n密码输入错误!请重新输入:"<<endl;
cin>>Passward;
}
cout<<"\n\t\t欢迎管理员的到来!!!!!\n"<<endl;
}
//------------------------------>主函数.
int main(void)
{
system("color 012"); //设置背景色和字体颜色
zuozhe();
system("PAUSE"); //系统暂停
system("cls"); //系统清屏
Pass();
system("PAUSE");
system("cls");
Menu();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -