员工信息

来源:互联网 发布:大数据搜索与挖掘 pdf 编辑:程序博客网 时间:2024/04/29 03:04
#include<iostream>#include<fstream>#include<string>#include<iomanip>using namespace std;typedef struct node{int no,deno,salary;string name;node *pno,*depno,*psalary,*next;}*ptrn;int length(ptrn &e){int count=0;    ptrn temm;temm=e;while(temm!=0){count++;temm=temm->next;}return count;}void main(){ifstream inf("salary.dat",ifstream::out|ifstream::app);string no1,name1,depart,salary1;int time=0;ptrn head,temp,newnode;head=0;while(!inf.eof()){                                                  inf>>no1>>name1>>depart>>salary1;if(time==0){time=1;continue;}newnode=new node;newnode->no=atoi(no1.c_str());newnode->name=name1;newnode->deno=atoi(depart.c_str());newnode->salary=atoi(salary1.c_str());if(head==0){           head=newnode;   temp=newnode;}else{temp->next=newnode;temp=newnode;}}if(head)temp->next=0;inf.close();    cout<<"               |     (1)添加职工信息      |"<<endl;cout<<"               |     (2)输出所有信息      |"<<endl;cout<<"               |     (3)按职工号输出      |"<<endl;    cout<<"               |     (4)按部门号输出      |"<<endl;    cout<<"               |     (5)按工资输出        |"<<endl;     cout<<"               |     (6)清空职员信息      |"<<endl;    cout<<"               |     (7)退出              |"<<endl;cout<<"___________________________________________________________________"<<endl;while(1){cout<<"                      请输入序号             "<<endl;       int m;    cin>>m;    if(m==1){          cout<<"请按照职员号------姓名-------部门号-------工资的顺序输入"<<endl;  if(head)  {newnode=new node;cin>>newnode->no>>newnode->name>>newnode->deno>>newnode->salary;temp->next=newnode;temp=newnode;   }  else  {              newnode=new node;      cin>>newnode->no>>newnode->name>>newnode->deno>>newnode->salary;  head=newnode;  temp=newnode;  }  temp->next=0;  ofstream ouf1("salary.dat");  ouf1<<std::left<<setw(10)<<"职工号"<<std::right<<setw(6)<<"姓--名"<<std::right<<setw(10)<<"部门号"<<std::right<<setw(10)<<"工--资"<<endl;  ptrn tepp;  tepp=head;  while(tepp!=0)  {  ouf1<<std::left<<setw(10)<<tepp->no<<std::right<<setw(6)<<tepp->name<<std::right<<setw(10)<<tepp->deno<<std::right<<setw(10)<<tepp->salary<<endl;  tepp=tepp->next;  }  ouf1.close();          cout<<"___________________________________________________________________"<<endl;}else if(m==2){if(head==0)cout<<"                    无信息"<<endl;else{                ptrn tem;    tem=head;    cout<<std::left<<setw(10)<<"职工号"<<std::right<<setw(6)<<"姓--名"<<std::right<<setw(10)<<"部门号"<<std::right<<setw(10)<<"工--资"<<endl;    while(tem!=0){    cout<<std::left<<setw(10)<<tem->no<<std::right<<setw(6)<<tem->name<<std::right<<setw(10)<<tem->deno<<std::right<<setw(10)<<tem->salary<<endl;    tem=tem->next;}}            cout<<"___________________________________________________________________"<<endl;}else if(m==3){    int mm=0;mm=length(head);for(int i=0;i<mm;i++){ ptrn te;     te=head;for(int j=0;j<mm-i-1;j++){                                                                     if(te->no>te->next->no){ptrn newnode1;newnode1=new node;newnode1->no=te->next->no;newnode1->name=te->next->name;newnode1->deno=te->next->deno;newnode1->salary=te->next->salary;te->next->no=te->no;te->next->name=te->name;te->next->deno=te->deno;te->next->salary=te->salary;te->no=newnode1->no;te->name=newnode1->name;te->deno=newnode1->deno;te->salary=newnode1->salary;                 }te=te->next;                              }}ptrn tem1,tem2;tem2=head;cout<<std::left<<setw(10)<<"职工号"<<std::right<<setw(6)<<"姓--名"<<std::right<<setw(10)<<"部门号"<<std::right<<setw(10)<<"工--资"<<endl;while(tem2!=0){tem1=new node;               tem1->no=tem2->no;   tem1->name=tem2->name;   tem1->deno=tem2->deno;   tem1->salary=tem2->salary;   tem1->pno=0;               cout<<std::left<<setw(10)<<tem1->no<<std::right<<setw(6)<<tem1->name<<std::right<<setw(10)<<tem1->deno<<std::right<<setw(10)<<tem1->salary<<endl;   tem1=tem1->pno;   tem2=tem2->next;}            cout<<"___________________________________________________________________"<<endl;}else if(m==4){         int mm=0;mm=length(head);for(int i=0;i<mm;i++){ ptrn te;     te=head;for(int j=0;j<mm-i-1;j++){                                                                     if(te->deno>te->next->deno){ptrn newnode1;newnode1=new node;newnode1->no=te->next->no;newnode1->name=te->next->name;newnode1->deno=te->next->deno;newnode1->salary=te->next->salary;te->next->no=te->no;te->next->name=te->name;te->next->deno=te->deno;te->next->salary=te->salary;te->no=newnode1->no;te->name=newnode1->name;te->deno=newnode1->deno;te->salary=newnode1->salary;                 }te=te->next;                              }}ptrn tem1,tem2;tem2=head;cout<<std::left<<setw(10)<<"职工号"<<std::right<<setw(6)<<"姓--名"<<std::right<<setw(10)<<"部门号"<<std::right<<setw(10)<<"工--资"<<endl;while(tem2!=0){tem1=new node;               tem1->no=tem2->no;   tem1->name=tem2->name;   tem1->deno=tem2->deno;   tem1->salary=tem2->salary;   tem1->depno=0;               cout<<std::left<<setw(10)<<tem1->no<<std::right<<setw(6)<<tem1->name<<std::right<<setw(10)<<tem1->deno<<std::right<<setw(10)<<tem1->salary<<endl;   tem1=tem1->depno;   tem2=tem2->next;   }cout<<"___________________________________________________________________"<<endl;}else if(m==5){    int mm=0;mm=length(head);for(int i=0;i<mm;i++){ ptrn te;     te=head;for(int j=0;j<mm-i-1;j++){                                                                     if(te->salary>te->next->salary){ptrn newnode1;newnode1=new node;newnode1->no=te->next->no;newnode1->name=te->next->name;newnode1->deno=te->next->deno;newnode1->salary=te->next->salary;te->next->no=te->no;te->next->name=te->name;te->next->deno=te->deno;te->next->salary=te->salary;te->no=newnode1->no;te->name=newnode1->name;te->deno=newnode1->deno;te->salary=newnode1->salary;                 }te=te->next;                              }  }ptrn tem1,tem2;tem2=head;cout<<std::left<<setw(10)<<"职工号"<<std::right<<setw(6)<<"姓--名"<<std::right<<setw(10)<<"部门号"<<std::right<<setw(10)<<"工--资"<<endl;while(tem2!=0){tem1=new node;               tem1->no=tem2->no;   tem1->name=tem2->name;   tem1->deno=tem2->deno;   tem1->salary=tem2->salary;   tem1->psalary=0;               cout<<std::left<<setw(10)<<tem1->no<<std::right<<setw(6)<<tem1->name<<std::right<<setw(10)<<tem1->deno<<std::right<<setw(10)<<tem1->salary<<endl;   tem1=tem1->psalary;   tem2=tem2->next; }             cout<<"___________________________________________________________________"<<endl; }else if(m==6){ofstream ouf5("salary.dat");ouf5<<std::left<<setw(10)<<"职工号"<<std::right<<setw(6)<<"姓--名"<<std::right<<setw(10)<<"部门号"<<std::right<<setw(10)<<"工--资"<<endl;            ouf5.close();cout<<"                         已清空"<<endl;            cout<<"___________________________________________________________________"<<endl;}elsebreak;}}

0 0