点击这里给我发消息 点击这里给我发消息

员工管理系统的链表实现

添加时间:2013-12-7
    相关阅读: 系统
副标题#e#

      #include <stdio.h>
    #include <conio.h>
    #include <process.h>
    #define OUTPUT temp->num,temp->name,temp->gender,temp->age,temp->department,temp->telephone,temp->wage
    #define FORMAT "%-10lu%-13s%-9c%-6u%-18s%-13lu%lu\n"
    #define INFO "number\t  name\t       gender\tage   department\ttelephone    wage\n"

    char ch;
    unsigned int mn,fn,find;
    unsigned long msum,fsum;
    strUCt workers
    {
     char name[15],department[18],gender;
     unsigned int age;
     unsigned long telephone,wage,num;
     struct workers *next;
    };struct workers *head,*bottom,*temp,*p;
    create()
    {
     int i;
     head=NULL;
     mn=fn=msum=fsum=0;
     for (i=0;;i++)
     {
      printf("\n   Information of worker NO.%d(Press '*' when input worker's name if finish)",i+1);
      insert();
     }
     getch();
     return main();
    }
    analysis()
    {
     clrscr();
     printf("\n**********************************Wage report*********************************\n");
     printf(INFO);
     temp=head;
     while(temp!=NULL)
     {
      printf(FORMAT,OUTPUT);
      temp=temp->next;
     }
     if(head==NULL)
      printf("\n\t\t\t\No worker in list,please entry first!");
     showreport();
    }
    showreport()
    {
     FILE *report;
     report=fopen("report.dat","w");
     fprintf(report,"\n\n\tGender\t\t\tFemale\t\tMale\t\tTotal");
     fprintf(report,"\n\tNumber\t\t\t%d\t\t%d\t\t%d",fn,mn,fn+mn);
     fprintf(report,"\n\tTotal wage\t\t%lu\t\t%lu\t\t%lu",fsum,msum,fsum+msum);
     if(mn==0&&fn==0)
      fprintf(report,"\n\tAverage wage\t\t0.00\t\t0.00\t\t0.00");
     else if(fn==0)
      fprintf(report,"\n\tAverage wage\t\t0.00\t\t%.2f\t\t%.2f",(float)(msum/mn),(float)(msum/mn));
     else if(mn==0)
      fprintf(report,"\n\tAverage wage\t\t%.2f\t\t0.00\t\t%.2f",(float)(fsum/fn),(float)(fsum/fn));
     else
      fprintf(report,"\n\tAverage wage\t\t%.2f\t\t%.2f\t\t%.2f",(float)(fsum/fn),(float)(msum/mn),(float)((fsum+msum)/(fn+mn)));
     ch=fgetc(report);
     fclose(report);
     report=fopen("report.dat","r");
     while(feof(report)==0)
     {
      putchar(ch);
      ch=fgetc(report);
     }
     fclose(report);
    }
    search()
    {
     unsigned long fnum;
     find=0;
     temp=head;
     do
     {
      printf("\nWorker's number you want to find:");
      fflush(stdin);
      scanf("%lu",&fnum);
      if(fnum<1fnum>100000000)
       printf("\tWorker's number is required from 1 to 100000000!");
     }while(fnum<1fnum>100000000);
     while(temp->next!=NULL&&fnum!=temp->num)
     {
      p=temp;
      temp=temp->next;
     }
     if(fnum==temp->num)
     {
      find=1;
      printf("\n");
      printf(INFO);
      printf(FORMAT,OUTPUT);
     }
     else
     {
      find=0;
      printf("\n\t\t\tNot found this worker!");
     }
    }
    insert()
    {
     if(head==NULL)
     {
      bottom=temp=(struct workers *)malloc(sizeof(struct workers));
      head=temp;
     }
     else
     {
      temp=(struct workers *)malloc(sizeof(struct workers));
      bottom->next=temp;
     }
     do{

#p#副标题#e#

      printf("\nWorker's name:");
      fflush(stdin);
      scanf("%s",temp->name);
      if(strlen(temp->name)>15)
       printf("\tThe length of worker's name must less than 15!");
     }while(strlen(temp->name)>15);
     if (temp->name[0]!='*')
     {
      add();
      bottom->next=temp;
      bottom=temp;
     }
     else
     {
      free(temp);
      bottom->next=NULL;
      if(fn+mn==0)
       head=NULL;
      printf("\n\t\t\t\Entry finish,press any key to return...");
      getch();
      return main();
     }
     bottom->next=NULL;
    }
    add()
    {
     do{
      printf("Worker's number:");
      fflush(stdin);
      scanf("%lu",&temp->num);
      if(temp->num<1temp->num>100000000)
       printf("\tWorker's number is required from 1 to 100000000!\n");
     }while(temp->num<1temp->num>100000000);
     do
     {
      printf("Worker's gender('m','f','M'or'F'):");
      fflush(stdin);
      scanf("%c",&temp->gender);
      if((temp->gender!='m')&&(temp->gender!='f')&&(temp->gender!='M')&&(temp->gender!='F'))
       printf("\tPlease input as 'm','f','M'or'F'!\n");
     }while((temp->gender!='m')&&(temp->gender!='f')&&(temp->gender!='M')&&(temp->gender!='F'));
     do
     {
      printf("Worker's age:");
      fflush(stdin);
      scanf("%u",&temp->age);
      if(temp->age<=18temp->age>=100)
       printf("\tWorker's age must more than 18 and less than 100!\n");
     }while(temp->age<=18temp->age>=100);
     do{
      printf("Worker's department:");
      fflush(stdin);
      scanf("%s",&temp->department);
      if(strlen(temp->department)>18)
       printf("\tThe length of worker's department must less than 18!\n");
     }while(strlen(temp->department)>18);
     do
     {
      printf("Worker's telephone(8 digit):");
      fflush(stdin);
      scanf("%lu",&temp->telephone);
      if(temp->telephone>99999999temp->telephone<10000000)
       printf("\tContact telephone is 8 digit!\n");
     }while(temp->telephone>99999999temp->telephone<10000000);
     do
     {
      printf("Worker's wage(more than 100):");
      fflush(stdin);
      scanf("%lu",&temp->wage);
      if(temp->wage<100)
       printf("\tThis worker's wage mustn't below 100!\n");
     }while(temp->wage<100);
     if((temp->gender=='m')(temp->gender=='M'))
     {
      msum+=temp->wage;
      mn++;
     }
     else
     {
      fsum+=temp->wage;
      fn++;
     }
    }
    delete()
    {
     search();
     if(find==1)
     {
      printf("\n Do you want to delete this worker?(Y/N)");
      fflush(stdin);
      ch=getchar();
      if(ch=='y'ch=='Y')
      {
       if(temp==head)
        head=temp->next;
       else
        p->next=temp->next;
       if(temp->gender=='m'temp->gender=='M')
       {
        msum-=temp->wage;
        mn--;
       }
       else if(temp->gender=='f'temp->gender=='F')
       {
        fsum-=temp->wage;
        fn--;
       }
       free(temp);
       analysis();
       printf("\n\n\n\t\t\tDelete OK,press any key to return...");
       getch();
       return m

 

相关员工管理系统的链表实现

咨询热线:020-85648757 85648755 85648616 0755-27912581 客服:020-85648756 0755-27912581 业务传真:020-32579052
广州市网景网络科技有限公司 Copyright◎2003-2008 Veelink.com. All Rights Reserved.
广州商务地址:广东省广州市黄埔大道中203号(海景园区)海景花园C栋501室
= 深圳商务地址:深圳市宝源路华丰宝源大厦606
研发中心:广东广州市天河软件园海景园区 粤ICP备05103322号 工商注册