注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

zjushuiping

追求的只是心中的那一份宁静!

 
 
 

日志

 
 

员工管理系统  

2010-08-12 14:45:20|  分类: 数据结构 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <conio.h>


using namespace std;
struct workers
{
      char name[15];   //姓名
      char  department[18];   //单位
      char gender[5];   //性别
      int age;   //年龄
      char telephone[12];   //电话
      long wage;   //工资
      char num[20];   //职工号
      
      char job[50];//职务
      struct workers *next;
};

typedef struct work_link{
        struct workers *head;
        int length;
        }workers_list;
void output_worker(struct workers *p);
void output_worker_wage(struct workers *p1);
int output_info(workers_list workers_Sq);

     

int Output_surface_two()//界面;
{    system("cls");
     printf("\n%15s","*");
     cout<<"*************************************************";
     printf("\n%15s","*");cout<<"*****************员工管理系统********************\n";
     printf("\n%15s","(");cout<<"1) ";cout<<"删除员工信息\n";
     printf("\n%15s","(");cout<<"2) ";cout<<"修改员工信息\n";
     printf("\n%15s","(");cout<<"3) ";cout<<"对员工进行排序\n";
     printf("\n%15s","(");cout<<"4) ";cout<<"查询员工信息\n";
     printf("\n%15s","(");cout<<"5) ";cout<<"加入新员工信息\n";
     printf("\n%15s","(");cout<<"6) ";cout<<"输出所有员工信息\n";
     printf("\n%15s","(");cout<<"7) ";cout<<"显示员工工资情况及平均工资\n";
     printf("\n%15s","(");cout<<"8) ";cout<<"退出\n";
     printf("\n%15s","*");
     cout<<"请选择您要进行的操作并确认...";
     int n;
     cin>>n;
    while(n<1||n>8)
    {printf("\n%15s","*");cout<<"输入错误,请重新输入...";cin>>n;}
    system("cls");//清屏函数;
    return n;
}

int  Delete_info(workers_list &workers_Sq)//删除员工信息;
{char num[20];
printf("\n%15s","");
cout<<"请输入您要删除员工的员工号并确认...";
cin>>num;
struct workers *p1,*p2;
p1=workers_Sq.head;
int n;
if(!p1)
{printf("\n%15s","*");cout<<"系统中没有员工信息";
 printf("\n\n%15s","*");cout<<"按1键并确认返回,按2键将退出...";
 cin>>n;
 while(n<1||n>2)
 {printf("\n%15s","*");cout<<"输入错误,请重新输入...";cin>>n;}
 int k;
 if(n==1)
 {k=Output_surface_two();
 return k;
 }
 else
 return 8;
}



p2=p1;
p1=p1->next;
if(strcmp(p2->num,num)==0)
{system("cls");
 printf("\n%15s","*");
 cout<<"您所要删除的员工信息为:\n";
 
 cout<<"职工号  |姓名     |性别|年龄|电话       |职务     |工资(元/月)| 单位           \n";
 int i;
 for(i=1;i<=80;i++)
 cout<<"-";
 
  output_worker(p2);
  printf("\n%15s","*");cout<<"确认删除请按1,取消删除请按0\n";
  printf("\n%15s","");
  cin>>n;
  while(n<0||n>1)
 {printf("\n%15s","*");cout<<"输入错误,请重新输入...";cin>>n;}
 if(n==1)
 {printf("\n%15s","*");cout<<"成功删除\n";workers_Sq.length--;
 workers_Sq.head=p1;
 free(p2);
 printf("\n%15s","*");
 cout<<"按确认键返回";
 getch();
 int k;
 k=Output_surface_two();
 return k;
 }
 else
 {int k;
 k=Output_surface_two();return k;
 }
}
while(p1)
{
         if(strcmp(p1->num,num)==0)
         {p2->next=p1->next;
         system("cls");
         printf("\n%15s","*");
         cout<<"您所要删除的员工信息为:\n";
 
         cout<<"职工号  |姓名     |性别|年龄|电话       |职务     |工资(元/月)| 单位           \n";
         int i;
         for(i=1;i<=80;i++)
         cout<<"-";
 
         output_worker(p1);
         printf("\n%15s","*");cout<<"确认删除请按1,取消删除请按0\n";
  cin>>n;
  while(n<0||n>1)
 {printf("\n%15s","*");cout<<"输入错误,请重新输入...";cin>>n;}
 if(n==1)
 {printf("\n%15s","*");cout<<"成功删除\n";workers_Sq.length--;
 free(p1);
 printf("\n%15s","*");
 cout<<"按确认键返回\n";
 getch();
 int k;
 k=Output_surface_two();
 return k;
 }
 else
 return 8;
 }
p1=p1->next;
}
if(!p1)
{printf("\n%15s","*");cout<<"系统中没有您要删除的员工\n";
printf("\n%15s","*");
cout<<"按确认键返回\n";
getch();
int k;
k=Output_surface_two();
 return k;
}
}
 
 
 
int  insert_info(workers_list &workers_Sq)//插入新员工信息;
{printf("\n%15s","*");cout<<"请依次输入新员工信息...\n";
struct workers *p,*p1;
p=(struct workers *)malloc(sizeof(struct workers));
 printf("\n%15s","*");cout<<"职工号:";
 cin>>p->num;
 p1=workers_Sq.head;
 while(p1)
 {if(strcmp(p1->num,p->num)==0)
  {printf("\n%15s","*");cout<<"该员工已经存在";goto L;}
  p1=p1->next;
 }  
 printf("\n%15s","*");cout<<"姓名:";
 cin>>p->name;
 printf("\n%15s","*");cout<<"性别:";
 cin>>p->gender;  
 printf("\n%15s","*");cout<<"年龄:";
 cin>>p->age;
 printf("\n%15s","*");cout<<"电话:";
 cin>>p->telephone;
 printf("\n%15s","*");cout<<"职务:";
 cin>>p->job;  
 printf("\n%15s","*");cout<<"工资(元/月):";
 cin>>p->wage;
 printf("\n%15s","*");cout<<"单位:";
 cin>>p->department;
 p->next=NULL;
 p->next=workers_Sq.head;
 workers_Sq.head=p;
 system("cls");
 printf("\n%15s","*");
 cout<<"添加成功\n";
 printf("\n%15s","*");
 cout<<"您所添加的员工信息为:\n\n";
 workers_Sq.length++;
 
 cout<<"职工号  |姓名     |性别|年龄|电话       |职务     |工资(元/月)| 单位           \n";
 int i;
 for(i=1;i<=80;i++)
 cout<<"-";
 output_worker(p);
 L:;
 printf("\n\n%15s","*");cout<<"按1键并确认返回,按2键将退出...";
 int n;
 cin>>n;
 while(n<1||n>2)
 {printf("\n%15s","*");cout<<"输入错误,请重新输入...";cin>>n;}
 int k;
 if(n==1)
 {k=Output_surface_two();
 return k;
 }
 else
 return 8;
}
                
 
int change_info(workers_list &workers_Sq)//修改员工信息;
{
char num[20];
printf("\n%15s","");
cout<<"请输入您要修改员工的员工号并确认...";
cin>>num;
struct workers *p1,*p2;
p1=workers_Sq.head;
int n;
if(!p1)
{printf("\n%15s","*");cout<<"系统中没有员工信息";
 printf("\n\n%15s","*");cout<<"按1键并确认返回,按2键将退出...";
 cin>>n;
 while(n<1||n>2)
 {printf("\n%15s","*");cout<<"输入错误,请重新输入...";cin>>n;}
 int k;
 if(n==1)
 {k=Output_surface_two();
 return k;
 }
 else
 return 8;
}

p1=workers_Sq.head;
while(p1)
{
         if(strcmp(num,p1->num)==0)
         {system("cls");printf("\n%15s","");cout<<"请输入您所要修改的信息...";
          printf("\n%15s","");cout<<"(1)姓名:";
          printf("\n%15s","");cout<<"(2)单位: ";
          printf("\n%15s","");cout<<"(3)性别: ";
          printf("\n%15s","");cout<<"(4)年龄: ";
          printf("\n%15s","");cout<<"(5)电话: ";
          printf("\n%15s","");cout<<"(6)工资: ";
          printf("\n%15s","");cout<<"(7)职务: ";
          printf("\n%15s","");
          int m;
          cin>>m;
          
          while(m<1||m>7)
          {printf("\n%15s","*");cout<<"输入错误,请重新输入...";cin>>m;}
          printf("\n%15s","*"); cout<<"请输入相应最新信息...";
          switch(m)
          {case 1:cin>>p1->name;break;
           case 2:cin>>p1->department;break;
           case 3:cin>>p1->gender;break;
           case 4:cin>>p1->age;break;
           case 5:cin>>p1->telephone;break;
           case 6:cin>>p1->wage;break;
           case 7:cin>>p1->job;break;
          }
          system("cls");
          printf("\n%15s","*");cout<<"更新后的员工信息:\n";
          cout<<"职工号  |姓名     |性别|年龄|电话       |职务     |工资(元/月)| 单位           \n";
          output_worker(p1);
          printf("\n\n%15s","*");cout<<"按1键并确认返回,按2键将退出...";
          cin>>n;
          while(n<1||n>2)
          {printf("\n%15s","*");cout<<"输入错误,请重新输入...";cin>>n;}
          int k;
          if(n==1)
          {k=Output_surface_two();
          return k;
          }
          else
          return 8;
          }
          p1=p1->next;
}
if(!p1)
{printf("\n%15s","*");cout<<"系统中没有员工信息";
 printf("\n\n%15s","*");cout<<"按1键并确认返回,按2键将退出...";
 cin>>n;
 while(n<1||n>2)
 {printf("\n%15s","*");cout<<"输入错误,请重新输入...";cin>>n;}
 int k;
 if(n==1)
 {k=Output_surface_two();
 return k;
 }
 else
 return 8;
}
}

void copy_worker(struct workers *x,struct workers *y)//交换x,y
{struct workers z;

strcpy(z.name,x->name);strcpy(x->name,y->name);strcpy(y->name,z.name);
strcpy(z.department,x->department);strcpy(x->department,y->department);strcpy(y->department,z.department);
strcpy(z.gender,x->gender);strcpy(x->gender,y->gender);strcpy(y->gender,z.gender);
strcpy(z.telephone,x->telephone);strcpy(x->telephone,y->telephone);strcpy(y->telephone,z.telephone);
strcpy(z.num,x->num);strcpy(x->num,y->num);strcpy(y->num,z.num);
strcpy(z.job,x->job);strcpy(x->job,y->job);strcpy(y->job,z.job);
z.age=x->age;x->age=y->age;y->age=z.age;
z.wage=x->wage;x->wage=y->wage;y->wage=z.wage;
}


      
      
      
      
int  sort_info(workers_list &workers_Sq)//对员工进行排序;
{system("cls");


printf("\n%15s","");cout<<"请选择排序条件...";

          printf("\n%15s","");cout<<"(1)姓名:";
          printf("\n%15s","");cout<<"(2)单位: ";
          printf("\n%15s","");cout<<"(3)性别: ";
          printf("\n%15s","");cout<<"(4)年龄: ";
          printf("\n%15s","");cout<<"(5)电话: ";
          printf("\n%15s","");cout<<"(6)工资: ";
          printf("\n%15s","");cout<<"(7)职务: ";
          printf("\n%15s","");cout<<"(8)职工号: \n";
          printf("\n%15s","");
   struct workers *p1,*p2,*p3;     
   int i,j;  
int m;
cin>>m;
while(m<1||m>8)
{printf("\n%15s","*");cout<<"输入错误,请重新输入...";cin>>m;}
          switch(m)
          {case 1:p1=p2=p3=workers_Sq.head;
                 for(i=1;i<workers_Sq.length;i++,p1=p1->next)
                  {p3=p1;
                   for(j=i+1,p2=p1->next;j<=workers_Sq.length;j++,p2=p2->next)
                   {if(strcmp(p3->name,p2->name)>0)
                      p3=p2;
                   }
                   if(p3!=p1)
                   copy_worker(p3,p1);
                  }break;
                   
                      
           
           case 2:p1=p2=p3=workers_Sq.head;
                 for(i=1;i<workers_Sq.length;i++,p1=p1->next)
                  {p3=p1;
                   for(j=i+1,p2=p1->next;j<=workers_Sq.length;j++,p2=p2->next)
                   {if(strcmp(p3->department,p2->department)>0)
                      p3=p2;
                   }
                   if(p3!=p1)
                   copy_worker(p3,p1);
                  }break;
                  
                  
           case 3:p1=p2=p3=workers_Sq.head;
                 for(i=1;i<workers_Sq.length;i++,p1=p1->next)
                  {p3=p1;
                   for(j=i+1,p2=p1->next;j<=workers_Sq.length;j++,p2=p2->next)
                   {if(strcmp(p3->gender,p2->gender)>0)
                      p3=p2;
                   }
                   if(p3!=p1)
                   copy_worker(p3,p1);
                  }break;
                  
                  
                  
           case 4:p1=p2=p3=workers_Sq.head;
                 for(i=1;i<workers_Sq.length;i++,p1=p1->next)
                  {p3=p1;
                   for(j=i+1,p2=p1->next;j<=workers_Sq.length;j++,p2=p2->next)
                   {if(p3->age>p2->age)
                      p3=p2;
                   }
                   if(p3!=p1)
                   copy_worker(p3,p1);
                  }break;
                  
                  
           case 5:p1=p2=p3=workers_Sq.head;
                 for(i=1;i<workers_Sq.length;i++,p1=p1->next)
                  {p3=p1;
                   for(j=i+1,p2=p1->next;j<=workers_Sq.length;j++,p2=p2->next)
                   {if(strcmp(p3->telephone,p2->telephone)>0)
                      p3=p2;
                   }
                   if(p3!=p1)
                   copy_worker(p3,p1);
                  }break;
                  
                  
           case 6:p1=p2=p3=workers_Sq.head;
                 for(i=1;i<workers_Sq.length;i++,p1=p1->next)
                  {p3=p1;
                   for(j=i+1,p2=p1->next;j<=workers_Sq.length;j++,p2=p2->next)
                   {if(p3->wage>p2->wage)
                      p3=p2;
                   }
                   if(p3!=p1)
                   copy_worker(p3,p1);
                  }break;
                  
                  
           case 7:p1=p2=p3=workers_Sq.head;
                 for(i=1;i<workers_Sq.length;i++,p1=p1->next)
                  {p3=p1;
                   for(j=i+1,p2=p1->next;j<=workers_Sq.length;j++,p2=p2->next)
                   {if(strcmp(p3->job,p2->job)>0)
                      p3=p2;
                   }
                   if(p3!=p1)
                   copy_worker(p3,p1);
                  }break;
                  
                  
           case 8:p1=p2=p3=workers_Sq.head;
                 for(i=1;i<workers_Sq.length;i++,p1=p1->next)
                  {p3=p1;
                   for(j=i+1,p2=p1->next;j<=workers_Sq.length;j++,p2=p2->next)
                   {if(strcmp(p3->num,p2->num)>0)
                      p3=p2;
                   }
                   if(p3!=p1)
                   copy_worker(p3,p1);
                  }break;
          }
          system("cls");
          printf("\n%15s","");cout<<"排序后输出...\n";
          return 6;
}


      
int find_info(workers_list workers_Sq)// 查询员工信息;
{system("cls");
printf("\n%15s","");cout<<"请选择查询条件...";

          printf("\n%15s","");cout<<"(1)姓名:";
          printf("\n%15s","");cout<<"(2)单位: ";
          printf("\n%15s","");cout<<"(3)性别: ";
          printf("\n%15s","");cout<<"(4)年龄: ";
          printf("\n%15s","");cout<<"(5)电话: ";
          printf("\n%15s","");cout<<"(6)工资: ";
          printf("\n%15s","");cout<<"(7)职务: ";
          printf("\n%15s","");cout<<"(8)职工号: \n";
          printf("\n%15s","");
          
int m;
cin>>m;
while(m<1||m>8)
{printf("\n%15s","*");cout<<"输入错误,请重新输入...";cin>>m;}
struct workers *p1=(struct workers *)malloc(sizeof(struct workers));
struct workers *p2=workers_Sq.head;
printf("\n%15s","*"); cout<<"请输入相应查询信息...";
          switch(m)
          {case 1:cin>>p1->name;p2=workers_Sq.head;
           while(p2)
           {if(strcmp(p1->name,p2->name)==0)
            break;p2=p2->next;
           }break;
           case 2:cin>>p1->department;
          while(p2)
           {if(strcmp(p1->department,p2->department)==0)
            break;p2=p2->next;
           }break;
           case 3:cin>>p1->gender;while(p2)
           {if(strcmp(p1->gender,p2->gender)==0)
            break;p2=p2->next;
           }break;
           case 4:cin>>p1->age;while(p2)
           {if(p1->age==p2->age)
            break;p2=p2->next;
           }break;
           case 5:cin>>p1->telephone;while(p2)
           {if(strcmp(p1->telephone,p2->telephone)==0)
            break;p2=p2->next;
           }break;
           case 6:cin>>p1->wage;while(p2)
           {if(p1->wage==p2->wage)
            break;p2=p2->next;
           }break;
           case 7:cin>>p1->job;while(p2)
           {if(strcmp(p1->job,p2->job)==0)
            break;p2=p2->next;
           }break;
           case 8:cin>>p1->num;while(p2)
           {if(strcmp(p1->num,p2->num)==0)
            break;p2=p2->next;
           }break;
          }
          
if(!p2)
{printf("\n%15s","*");cout<<"系统中没有员工信息";
 printf("\n\n%15s","*");cout<<"按1键并确认返回,按2键将退出...";
 int n;
 cin>>n;
 while(n<1||n>2)
 {printf("\n%15s","*");cout<<"输入错误,请重新输入...";cin>>n;}
 int k;
 if(n==1)
 {k=Output_surface_two();
 return k;
 }
 else
 return 8;
}
else
{system("cls");
printf("\n%15s","*");cout<<"    您所查询的员工信息    *\n\n";
cout<<"职工号  |姓名     |性别|年龄|电话       |职务     |工资(元/月)| 单位           \n";
int i;
for(i=1;i<=80;i++)
cout<<"-";
          output_worker(p2);
          printf("\n\n%15s","*");cout<<"按1键并确认返回,按2键将退出...";
          int n;
          cin>>n;
          while(n<1||n>2)
          {printf("\n%15s","*");cout<<"输入错误,请重新输入...";cin>>n;}
          int k;
          if(n==1)
          {k=Output_surface_two();
          return k;
          }
          else
          return 8;
}
}

void output_worker(struct workers *p)//输出一个员工信息
{int n;
printf("%-8s|",p->num);
printf("%-9s|",p->name);
printf("%-4s|",p->gender);
printf("%-4d|",p->age);
printf("%-11s|",p->telephone);
printf("%-9s|",p->job);
printf("%-11d|",p->wage);
printf("%-5s",p->department);
cout<<endl;
for(n=1;n<=80;n++)
cout<<"-";
}



int output_info(workers_list workers_Sq)//输出所有员工信息;
{printf("\n%15s","*");cout<<"请选择每页要显示的信息数,最多15条...";
int n;
cin>>n;
while(n<1||n>15)
{printf("\n%15s","*");cout<<"输入错误,请重新输入...";cin>>n;}
 system("cls");
if( workers_Sq.length==0)
{printf("\n%15s","*");cout<<"系统中没有员工信息";
 printf("\n\n%15s","*");cout<<"按1键并确认返回,按2键将退出...";
 int nn;
 cin>>nn;
 while(nn<1||nn>2)
 {printf("\n%15s","*");cout<<"输入错误,请重新输入...";cin>>nn;}
 int k;
 if(nn==1)
 {k=Output_surface_two();
 return k;
 }
 else
 return 8;
}

struct workers *p1;//信息的输出
p1=workers_Sq.head;
int count;
int i;
while(p1)
{system("cls");
 cout<<"职工号  |姓名     |性别|年龄|电话       |职务     |工资(元/月)| 单位           \n";
 for(i=1;i<=80;i++)
 cout<<"-";
 count=n;
 while((count--)&&(p1))
 {output_worker(p1);p1=p1->next;}
 printf("\n%15s","*");cout<<"按确认键翻页..."; getch();
}
printf("\n\n%15s","*");cout<<"按1键并确认返回,按2键将退出...";
int nn;
 cin>>nn;
 while(nn<1||nn>2)
 {printf("\n%15s","*");cout<<"输入错误,请重新输入...";cin>>nn;}
 int k;
 if(nn==1)
 {k=Output_surface_two();
 return k;
 }
 else
 return 8;
}
 
 
 
void output_worker_wage(struct workers *p1)//显示每个员工的工资;
{int n;
printf("%15s","");
printf("%-12d|",p1->num);
printf("%-9s|",p1->name);

printf("%-4d",p1->wage);
cout<<endl;

for(n=1;n<=80;n++)
cout<<"-";
}



int output_wage(workers_list workers_Sq)//显示员工工资情况及平均工资;
{printf("\n%15s","*");cout<<"请选择每页要显示的信息数,最多15条...";
int n;
cin>>n;
while(n<1||n>15)
{printf("\n%15s","*");cout<<"输入错误,请重新输入...";cin>>n;}
 system("cls");
if( workers_Sq.length==0)
{printf("\n%15s","*");cout<<"系统中没有员工信息";
 printf("\n\n%15s","*");cout<<"按1键并确认返回,按2键将退出...";
 int nn;
 cin>>nn;
 while(nn<1||nn>2)
 {printf("\n%15s","*");cout<<"输入错误,请重新输入...";cin>>nn;}
 int k;
 if(nn==1)
 {k=Output_surface_two();
 return k;
 }
 else
 return 8;
}

struct workers *p1;//信息的输出
p1=workers_Sq.head;
int count;
double sum=0;
int i;
while(p1)
{
         sum+=p1->wage;p1=p1->next;
}
int nn;
p1=workers_Sq.head;
while(p1)
{system("cls");
 printf("                      平均工资为:%1.2lf元/月\n",sum/workers_Sq.length);
for(nn=1;nn<=80;nn++)
cout<<"-";
cout<<"               职工号      |姓名     |工资(元/月)\n";
for(nn=1;nn<=80;nn++)
cout<<"-";
count=n;
 while((count--)&&(p1))
 {output_worker_wage(p1);p1=p1->next;}
 printf("\n%15s","*");cout<<"按确认键翻页..."; getch();
}
printf("\n\n%15s","*");cout<<"按1键并确认返回,按2键将退出...";
 cin>>nn;
 while(nn<1||nn>2)
 {printf("\n%15s","*");cout<<"输入错误,请重新输入...";cin>>nn;}
 int k;
 if(nn==1)
 {k=Output_surface_two();
 return k;
 }
 else
 return 8;
}

     
int main(int argc, char *argv[])
{int n=Output_surface_two();
workers_list workers_Sq;
workers_Sq.head=NULL;
workers_Sq.length=0;


while(1)
{
 switch(n)
 {case 1:n=Delete_info(workers_Sq);break;
  case 2:n=change_info(workers_Sq);break;
  case 3:n=sort_info(workers_Sq);break;
  case 4:n=find_info(workers_Sq);break;
  case 5:n=insert_info(workers_Sq);break;
  case 6:n=output_info(workers_Sq);break;
  case 7:n=output_wage(workers_Sq);break;
  case 8:exit(1);break;
 }
}
 
 
    //system("PAUSE");
    return EXIT_SUCCESS;
}
  评论这张
 
阅读(132)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018