WEB开发网
开发学院软件开发C++ 员工管理系统(链表) 阅读

员工管理系统(链表)

 2008-03-08 12:51:29 来源:WEB开发网   
核心提示:#include <stdio.h>#include <conio.h>#include <PRocess.h>#define OUTPUT temp->num,temp->name,temp->gender,temp->age,temp->depart

  #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{
 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

Tags:员工 管理系统

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接