加入nysec时写的第一个项目,比起之后写的差太多了,但是很有纪念意义,是克服众多困难后的产物
员工管理系统
#include <stdio.h>#include <stdlib.h>#include <conio.h>#include <windows.h>#include <iostream>struct Date{char year[5],month[3],day[3];};typedef struct Staff{char name[50];char sex[5];Date birth;char position[10];float wage;int work;struct Staff *next;}SF;void Input(Staff*head){char a;SF *p=head;SF *p1=(Staff*)malloc(sizeof(Staff));printf("请输入姓名\n");scanf("%s",&p1->name);fflush(stdin);while(p->next!=NULL){SF*b=p->next;while(strcmp(b->name,p1->name)==0){printf("该员工已存在!\n");getch();return;}p=p->next;}int m=0;while(m==0){printf("性别:1.男 2.女\t\r");a=getch();fflush(stdin);switch(a){case('1'):strcpy(p1->sex,"男");printf("性别:男 \t\t\t\r");m=1;continue;case('2'):strcpy(p1->sex,"女");printf("性别:女 \t\t\t\r");m=1;continue;default:printf("\t\t输入错误\t\t\t\r");m=0;continue;}}printf("\n请输入生日: \r");char x[5]={'0','0','0','0','\0'},b[3]={'0','0','\0'},c[3]={'0','0','\0'};int i=0;while(i<=7){if(i>=0&&i<4){x[i]=getch();if(i>0&&i<4&&x[i]=='\b'){x[i]='0';x[i-1]='0';i=i-1;printf("请输入生日: %c %c %c %c 年 %c %c 月 %c %c 日\r",x[0],x[1],x[2],x[3],b[0],b[1],c[0],c[1]);continue;}if(x[i]!='0'&&x[i]!='1'&&x[i]!='2'&&x[i]!='3'&&x[i]!='4'&&x[i]!='5'&&x[i]!='6'&&x[i]!='7'&&x[i]!='8'&&x[i]!='9'){printf("无效的年份: \r");x[i]='0';continue;}}elseif(i>=4&&i<6){b[i-4]=getch();if(i==4&&b[0]=='\b'){b[0]='0';x[i-1]='0';i=i-1;printf("请输入生日: %c %c %c %c 年 %c %c 月 %c %c 日\r",x[0],x[1],x[2],x[3],b[0],b[1],c[0],c[1]);continue;}if(i>4&&b[i-4]=='\b'){b[i-4]='0';b[i-5]='0';i=i-1;printf("请输入生日: %c %c %c %c 年 %c %c 月 %c %c 日\r",x[0],x[1],x[2],x[3],b[0],b[1],c[0],c[1]);continue;}if(i==4&&(b[0]!='0'&&b[0]!='1')){printf("无效的月份: \r");b[0]='0';continue;}if(i==5&&( (b[0]=='0'&&(b[1]!='1'&&b[1]!='2'&&b[1]!='3'&&b[1]!='4'&&b[1]!='5'&&b[1]!='6'&&b[1]!='7'&&b[1]!='8'&&b[1]!='9')) || (b[0]=='1'&&(b[1]!='0'&&b[1]!='1'&&b[1]!='2')) )){printf("无效的月份: \r");b[1]='0';continue;}}elseif(i>=6&&i<=7){c[i-6]=getch();if(i==6&&c[0]=='\b'){c[0]='0';b[1]='0';i=i-1;printf("请输入生日: %c %c %c %c 年 %c %c 月 %c %c 日\r",x[0],x[1],x[2],x[3],b[0],b[1],c[0],c[1]);continue;}if(i==7&&c[1]=='\b'){c[0]='0';c[1]='0';i=i-1;printf("请输入生日: %c %c %c %c 年 %c %c 月 %c %c 日\r",x[0],x[1],x[2],x[3],b[0],b[1],c[0],c[1]);continue;}if(i==6&&(c[0]!='0'&&c[0]!='1'&&c[0]!='2'&&c[0]!='3')){printf("无效的日期1: \r");c[0]='0';continue;}if(i==7&&( (c[0]=='3'&&(c[1]!='0'&&c[1]!='1')) ||(c[0]=='0'&&(c[1]=='0'))||(c[0]!='0'&&(c[1]!='0'&&c[1]!='1'&&c[1]!='2'&&c[1]!='3'&&c[1]!='4'&&c[1]!='5'&&c[1]!='6'&&c[1]!='7'&&c[1]!='8'&&c[1]!='9')))){printf("无效的日期2: \r");c[1]='0';continue;}}printf("请输入生日: %c %c %c %c 年 %c %c 月 %c %c 日\r",x[0],x[1],x[2],x[3],b[0],b[1],c[0],c[1]);i=i+1;}strcpy(p1->birth.year,x);strcpy(p1->birth.month,b);strcpy(p1->birth.day,c);printf("%c %c %c %c 年 %c %c 月 %c %c 日\t\t\n",x[0],x[1],x[2],x[3],b[0],b[1],c[0],c[1]);int n=0;while(n==0){printf("职位:1.经理 2.临时工 3.工人 4.销售人员\r");int M;a=getch();fflush(stdin);switch(a){case('1'):strcpy(p1->position,"经理");p1->wage=300000;printf("职位:经理 \t\t\t\t\t\t\t\t\t\t\t\t\t\t\r");n=1;break;case('2'):int f;strcpy(p1->position,"临时工");while(1){printf("\t\t\t\t\t\t\t\t\r");printf("请输入总工作时长: ");scanf("%d",&M);if(M>0&M<=720){p1->wage=M*30;}else{printf("无效的时长\t\t\r");char k;k=getch();fflush(stdin);continue;}printf("总工作时长: %d\n",M);printf("职位:临时工 \t\t\t\t\t\t\t\t\t\t\t\t\t\t\r");break;}n=1;break;case('3'):strcpy(p1->position,"工人");while(1){int base=3000;printf("\t\t\t\t\t\t\t\t\r");printf("请输入总工作天数: ");scanf("%d",&M);if(M>0&M<=30){p1->wage=base+M*30;}else{printf("无效的天数\t\t\t\r");char k;k=getch();fflush(stdin);continue;}break;}printf("总工作天数: %d\n",M);printf("职位:工人 \t\t\t\t\t\t\t\t\t\t\t\t\t\t\r");n=1;break;case('4'):strcpy(p1->position,"销售人员");while(1){printf("\t\t\t\t\t\t\t\t\r");printf("请输入销售数量: ");scanf("%d",&M);if(M>0&M<=500){p1->wage=M*300;}else{printf("无效的销售数量\t\t\r");char k;k=getch();fflush(stdin);continue;}break;}printf("销售数量: %d\n",M);printf("职位:销售人员 \t\t\t\t\t\t\t\t\t\t\t\t\t\t\r");n=1;break;default:printf("\t\t\t\t\t输入错误\r");continue;}}p->next=p1;p1->next=NULL;printf("\n存储成功\n");system("pause");}void Delete(Staff*head){Staff *p1,*p2;p1=head;p2=p1->next;char name[50];printf("请输入姓名:");scanf("%s",name);while(p2!=NULL){while(strcmp(p2->name,name)==0){p1->next=p2->next;free(p2);printf("%s",p2->name);printf("删除成功\n");system("pause");return;}p1=p2;p2=p2->next;}printf("查无此人\n");system("pause");}void Seek(Staff*head){SF *p=head;char name[50];printf("请输入要查找的姓名:");scanf("%s",&name);while(p->next!=NULL){while(strcmp(p->next->name,name)==0){printf("姓名:%s\n",p->next->name);printf("性别:%s\n",p->next->sex);printf("生日:%s年%s月%s日\n",p->next->birth.year,p->next->birth.month,p->next->birth.day);printf("职位:%s\n",p->next->position);printf("月工资:%.2f\n",p->next->wage);system("pause");return;}p=p->next;}printf("未找到该员工信息!");system("pause");return;}void Show(Staff*head){printf("\t\t\t员工统计\n");SF *p = head->next;printf("***********************************************************************\n");printf("姓名\t\t性别\t 生日 年 月 日\t\t职位\t\t月工资\n");while (p){printf("%s\t\t%s\t\t%s %s %s \t\t%s\t\t%.1f\n",p->name,p->sex,p->birth.year,p->birth.month,p->birth.day,p->position,p->wage);p = p->next;}system("pause");}void Save(Staff*head){SF *p;p=head;FILE*fp = fopen("员工信息.txt","w");fprintf(fp," 姓名\t\t性别\t 生日 年 月 日\t\t职位\t\t月工资\n");if(fp!=NULL){int a=1;while(p->next!=NULL){fprintf(fp,"%d %s\t\t%s\t\t%s %s %s \t\t%s\t\t%.1f\n",a,p->next->name,p->next->sex,p->next->birth.year,p->next->birth.month,p->next->birth.day,p->next->position,p->next->wage);p=p->next;a++;}}fclose(fp);printf("保存成功!\n");system("pause");}void Read(Staff*head){SF *p;p=head;FILE *in= fopen("员工信息.txt", "r");char buf[1000];int a=0;char z[50],x[50],j[50];int c,v,b;char n[50];float m;while(fgetc(in)!=EOF){fgets(buf,1000,in);if(a==0){a=0;}else{sscanf(buf,"%s %s %04d %02d %02d %s %f",z,x,&c,&v,&b,n,&m);while(p->next==NULL){// itoa(c,p->next->birth.year,10);// itoa(v,p->next->birth.month,10);// itoa(b,p->next->birth.day,10);// strcpy(p->next->name,z);strcpy(p->next->sex,x);// strcpy(p->next->position,n);// p->next->wage=m;p=p->next;}printf("%s %s %d %d %d %s %f\n",z,x,c,v,b,n,m);}a++;}fclose(in);printf("读取成功\n");system("pause");return;}void Sort(Staff*head){SF*p;int judge = 666;SF sorting;while (1){judge = 777;p= head->next;while (p->next){if (p->wage< p->next->wage){judge = 233;sorting.wage= p->wage;p->wage = p->next->wage;p->next->wage = sorting.wage;}p = p->next;};if (!judge)break;}printf("排序成功!\n");system("pause");}int main(){system("color 1a");char a;Staff *head=(Staff*)malloc(sizeof(Staff));head->next=NULL;while(1){system("cls");printf("\t\t***************员工管理软件*************\n");printf("\t\t\t\t1.新增员工信息\n");printf("\t\t\t\t2.删除员工信息\n");printf("\t\t\t\t3.员工信息搜索\n");printf("\t\t\t\t4.员工信息统计\n");printf("\t\t\t\t5.员工信息分类存储\n");printf("\t\t\t\t6.员工信息导入\n");printf("\t\t\t\t7.按工资排序\n");printf("\t\t\t\t8.退出\n");printf("\t\t****************************************\n");printf("\t\t\t\t请选择\n");a=getch();fflush(stdin);switch(a){case '1':Input(head);break;case '2':Delete(head);break;case '3':Seek(head);break;case '4':system("cls");Show(head);break;case '5':Save(head);break;case '6':Read(head);break;case '7':Sort(head);break;case '8':exit(1);default:printf("输入错误。\n");system("pause");}}}
