#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<1||fnum>100000000) printf("\tWorker's number is required from 1 to 100000000!"); }while(fnum<1||fnum>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<1||temp->num>100000000) printf("\tWorker's number is required from 1 to 100000000!\n"); }while(temp->num<1||temp->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<=18||temp->age>=100) printf("\tWorker's age must more than 18 and less than 100!\n"); }while(temp->age<=18||temp->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>99999999||temp->telephone<10000000) printf("\tContact telephone is 8 digit!\n"); }while(temp->telephone>99999999||temp->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 main(); } else { printf("\n\t\t\tDelete cancel,press any key to return..."); getch(); return main(); } } if(find==0) getch(); return main(); } edit() { search(); if(find==1) { printf("\n Do you want to edit this worker?(Y/N)"); fflush(stdin); ch=getchar(); if(ch=='y'||ch=='Y') { do{ printf("\n\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(strle
n(temp->name)>15); if(temp->gender=='m'||temp->gender=='M') { msum-=temp->wage; mn--; } else if(temp->gender=='f'||temp->gender=='F') { fsum-=temp->wage; fn--; } add(); analysis(); printf("\n\n\n\t\t\tEdit OK,press any key to return..."); getch(); return main(); } else { printf("\n\t\t\tEdit cancel,press any key to return..."); getch(); return main(); } } if(find==0) getch(); return main(); } bubblesort() { int i,j; struct tempworker { char name[15],department[18],gender; unsigned int age; unsigned long telephone,wage,num; };struct tempworker *change; temp=head; for (i=1;i<fn+mn;i++) for(temp=head;temp->next!=NULL;temp=temp->next) if(temp->wage>(temp->next->wage)) { change->num=temp->num; temp->num=temp->next->num; temp->next->num=change->num; for(j=0;j<strlen(temp->name);j++) { change->name[j]=temp->name[j]; temp->name[j]=temp->next->name[j]; temp->next->name[j]=change->name[j]; } change->gender=temp->gender; temp->gender=temp->next->gender; temp->next->gender=change->gender; change->age=temp->age; temp->age=temp->next->age; temp->next->age=change->age; for(j=0;j<strlen(temp->department);j++) { change->department[j]=temp->department[j]; temp->department[j]=temp->next->department[j]; temp->next->department[j]=change->department[j]; } change->telephone=temp->telephone; temp->telephone=temp->next->telephone; temp->next->telephone=change->telephone; change->wage=temp->wage; temp->wage=temp->next->wage; temp->next->wage=change->wage; bottom->next=NULL; } analysis(); getch(); return main(); } main() { int choice; do { clrscr(); printf("\n\t\t*************************************************"); printf("\n\t\t*\t Worker's wage management Ver 1.0\t*\n"); printf("\t\t*************************************************\n\n"); printf("\t\t\t\t1.Data entry\n\t\t\t\t2.Data analysis\n\t\t\t\t3.Search dara\n\t\t\t\t4.Add data\n\t\t\t\t5.Delete data\n\t\t\t\t6.Edit data\n\t\t\t\t7.Sort data\n\t\t\t\t8.Exit\n\n\t\t\t Make a choice please:"); fflush(stdin); scanf("%d",&choice); switch (choice) { case 1: clrscr(); create(); break; case 2: analysis(); printf("\n\nPress any key to return..."); getch(); return main(); break; case 3: clrscr(); search(); printf("\nPress any key to return..."); getch(); return main(); break; case 4: clrscr(); printf("\n Information of new worker(Press '*' when input worker's name if finish)"); insert(); printf("\nInsert OK,press any key to return..."); getch(); return main(); break; case 5: clrscr(); delete(); break; case 6: clrscr(); edit(); break; case 7: clrscr(); bubblesort(); break; case 8: exit(0); default: printf("\t\t\t Please choose from 1 to 8!"); } getch(); }while(choice<1||choice>8); }
视频教程列表
文章教程搜索
C语言程序设计推荐教程
C语言程序设计热门教程
|