加入nysec时写的第一个项目,比起之后写的差太多了,但是很有纪念意义,是克服众多困难后的产物
    员工管理系统

    1. #include <stdio.h>
    2. #include <stdlib.h>
    3. #include <conio.h>
    4. #include <windows.h>
    5. #include <iostream>
    6. struct Date
    7. {
    8. char year[5],month[3],day[3];
    9. };
    10. typedef struct Staff
    11. {
    12. char name[50];
    13. char sex[5];
    14. Date birth;
    15. char position[10];
    16. float wage;
    17. int work;
    18. struct Staff *next;
    19. }SF;
    20. void Input(Staff*head)
    21. {
    22. char a;
    23. SF *p=head;
    24. SF *p1=(Staff*)malloc(sizeof(Staff));
    25. printf("请输入姓名\n");
    26. scanf("%s",&p1->name);
    27. fflush(stdin);
    28. while(p->next!=NULL)
    29. {
    30. SF*b=p->next;
    31. while(strcmp(b->name,p1->name)==0)
    32. {
    33. printf("该员工已存在!\n");
    34. getch();
    35. return;
    36. }
    37. p=p->next;
    38. }
    39. int m=0;
    40. while(m==0)
    41. {
    42. printf("性别:1.男 2.女\t\r");
    43. a=getch();
    44. fflush(stdin);
    45. switch(a)
    46. {
    47. case('1'):
    48. strcpy(p1->sex,"男");
    49. printf("性别:男 \t\t\t\r");
    50. m=1;
    51. continue;
    52. case('2'):
    53. strcpy(p1->sex,"女");
    54. printf("性别:女 \t\t\t\r");
    55. m=1;
    56. continue;
    57. default:
    58. printf("\t\t输入错误\t\t\t\r");
    59. m=0;
    60. continue;
    61. }
    62. }
    63. printf("\n请输入生日: \r");
    64. char x[5]={'0','0','0','0','\0'},b[3]={'0','0','\0'},c[3]={'0','0','\0'};
    65. int i=0;
    66. while(i<=7)
    67. {
    68. if(i>=0&&i<4)
    69. {
    70. x[i]=getch();
    71. if(i>0&&i<4&&x[i]=='\b')
    72. {
    73. x[i]='0';
    74. x[i-1]='0';
    75. i=i-1;
    76. 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]);
    77. continue;
    78. }
    79. 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')
    80. {
    81. printf("无效的年份: \r");
    82. x[i]='0';
    83. continue;
    84. }
    85. }else
    86. if(i>=4&&i<6)
    87. {
    88. b[i-4]=getch();
    89. if(i==4&&b[0]=='\b')
    90. {
    91. b[0]='0';
    92. x[i-1]='0';
    93. i=i-1;
    94. 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]);
    95. continue;
    96. }
    97. if(i>4&&b[i-4]=='\b')
    98. {
    99. b[i-4]='0';
    100. b[i-5]='0';
    101. i=i-1;
    102. 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]);
    103. continue;
    104. }
    105. if(i==4&&(b[0]!='0'&&b[0]!='1'))
    106. {
    107. printf("无效的月份: \r");
    108. b[0]='0';
    109. continue;
    110. }
    111. 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')) ))
    112. {
    113. printf("无效的月份: \r");
    114. b[1]='0';
    115. continue;
    116. }
    117. }
    118. else
    119. if(i>=6&&i<=7)
    120. {
    121. c[i-6]=getch();
    122. if(i==6&&c[0]=='\b')
    123. {
    124. c[0]='0';
    125. b[1]='0';
    126. i=i-1;
    127. 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]);
    128. continue;
    129. }
    130. if(i==7&&c[1]=='\b')
    131. {
    132. c[0]='0';
    133. c[1]='0';
    134. i=i-1;
    135. 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]);
    136. continue;
    137. }
    138. if(i==6&&(c[0]!='0'&&c[0]!='1'&&c[0]!='2'&&c[0]!='3'))
    139. {
    140. printf("无效的日期1: \r");
    141. c[0]='0';
    142. continue;
    143. }
    144. 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'))))
    145. {
    146. printf("无效的日期2: \r");
    147. c[1]='0';
    148. continue;
    149. }
    150. }
    151. 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]);
    152. i=i+1;
    153. }
    154. strcpy(p1->birth.year,x);
    155. strcpy(p1->birth.month,b);
    156. strcpy(p1->birth.day,c);
    157. 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]);
    158. int n=0;
    159. while(n==0)
    160. {
    161. printf("职位:1.经理 2.临时工 3.工人 4.销售人员\r");
    162. int M;
    163. a=getch();
    164. fflush(stdin);
    165. switch(a)
    166. {
    167. case('1'):
    168. strcpy(p1->position,"经理");
    169. p1->wage=300000;
    170. printf("职位:经理 \t\t\t\t\t\t\t\t\t\t\t\t\t\t\r");
    171. n=1;
    172. break;
    173. case('2'):
    174. int f;
    175. strcpy(p1->position,"临时工");
    176. while(1)
    177. {
    178. printf("\t\t\t\t\t\t\t\t\r");
    179. printf("请输入总工作时长: ");
    180. scanf("%d",&M);
    181. if(M>0&M<=720)
    182. {
    183. p1->wage=M*30;
    184. }else
    185. {
    186. printf("无效的时长\t\t\r");
    187. char k;
    188. k=getch();
    189. fflush(stdin);
    190. continue;
    191. }
    192. printf("总工作时长: %d\n",M);
    193. printf("职位:临时工 \t\t\t\t\t\t\t\t\t\t\t\t\t\t\r");
    194. break;
    195. }
    196. n=1;
    197. break;
    198. case('3'):
    199. strcpy(p1->position,"工人");
    200. while(1)
    201. {
    202. int base=3000;
    203. printf("\t\t\t\t\t\t\t\t\r");
    204. printf("请输入总工作天数: ");
    205. scanf("%d",&M);
    206. if(M>0&M<=30)
    207. {
    208. p1->wage=base+M*30;
    209. }else
    210. {
    211. printf("无效的天数\t\t\t\r");
    212. char k;
    213. k=getch();
    214. fflush(stdin);
    215. continue;
    216. }
    217. break;
    218. }
    219. printf("总工作天数: %d\n",M);
    220. printf("职位:工人 \t\t\t\t\t\t\t\t\t\t\t\t\t\t\r");
    221. n=1;
    222. break;
    223. case('4'):
    224. strcpy(p1->position,"销售人员");
    225. while(1)
    226. {
    227. printf("\t\t\t\t\t\t\t\t\r");
    228. printf("请输入销售数量: ");
    229. scanf("%d",&M);
    230. if(M>0&M<=500)
    231. {
    232. p1->wage=M*300;
    233. }else
    234. {
    235. printf("无效的销售数量\t\t\r");
    236. char k;
    237. k=getch();
    238. fflush(stdin);
    239. continue;
    240. }
    241. break;
    242. }
    243. printf("销售数量: %d\n",M);
    244. printf("职位:销售人员 \t\t\t\t\t\t\t\t\t\t\t\t\t\t\r");
    245. n=1;
    246. break;
    247. default:
    248. printf("\t\t\t\t\t输入错误\r");
    249. continue;
    250. }
    251. }
    252. p->next=p1;
    253. p1->next=NULL;
    254. printf("\n存储成功\n");
    255. system("pause");
    256. }
    257. void Delete(Staff*head)
    258. {
    259. Staff *p1,*p2;
    260. p1=head;
    261. p2=p1->next;
    262. char name[50];
    263. printf("请输入姓名:");
    264. scanf("%s",name);
    265. while(p2!=NULL)
    266. {
    267. while(strcmp(p2->name,name)==0)
    268. {
    269. p1->next=p2->next;
    270. free(p2);
    271. printf("%s",p2->name);
    272. printf("删除成功\n");
    273. system("pause");
    274. return;
    275. }
    276. p1=p2;
    277. p2=p2->next;
    278. }
    279. printf("查无此人\n");
    280. system("pause");
    281. }
    282. void Seek(Staff*head)
    283. {
    284. SF *p=head;
    285. char name[50];
    286. printf("请输入要查找的姓名:");
    287. scanf("%s",&name);
    288. while(p->next!=NULL)
    289. {
    290. while(strcmp(p->next->name,name)==0)
    291. {
    292. printf("姓名:%s\n",p->next->name);
    293. printf("性别:%s\n",p->next->sex);
    294. printf("生日:%s年%s月%s日\n",p->next->birth.year,p->next->birth.month,p->next->birth.day);
    295. printf("职位:%s\n",p->next->position);
    296. printf("月工资:%.2f\n",p->next->wage);
    297. system("pause");
    298. return;
    299. }
    300. p=p->next;
    301. }
    302. printf("未找到该员工信息!");
    303. system("pause");
    304. return;
    305. }
    306. void Show(Staff*head)
    307. {
    308. printf("\t\t\t员工统计\n");
    309. SF *p = head->next;
    310. printf("***********************************************************************\n");
    311. printf("姓名\t\t性别\t 生日 年 月 日\t\t职位\t\t月工资\n");
    312. while (p)
    313. {
    314. 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);
    315. p = p->next;
    316. }
    317. system("pause");
    318. }
    319. void Save(Staff*head)
    320. {
    321. SF *p;
    322. p=head;
    323. FILE*fp = fopen("员工信息.txt","w");
    324. fprintf(fp," 姓名\t\t性别\t 生日 年 月 日\t\t职位\t\t月工资\n");
    325. if(fp!=NULL)
    326. {
    327. int a=1;
    328. while(p->next!=NULL)
    329. {
    330. 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);
    331. p=p->next;
    332. a++;
    333. }
    334. }
    335. fclose(fp);
    336. printf("保存成功!\n");
    337. system("pause");
    338. }
    339. void Read(Staff*head)
    340. {
    341. SF *p;
    342. p=head;
    343. FILE *in= fopen("员工信息.txt", "r");
    344. char buf[1000];
    345. int a=0;
    346. char z[50],x[50],j[50];
    347. int c,v,b;
    348. char n[50];
    349. float m;
    350. while(fgetc(in)!=EOF)
    351. {
    352. fgets(buf,1000,in);
    353. if(a==0)
    354. {
    355. a=0;
    356. }else
    357. {
    358. sscanf(buf,"%s %s %04d %02d %02d %s %f",z,x,&c,&v,&b,n,&m);
    359. while(p->next==NULL)
    360. {
    361. // itoa(c,p->next->birth.year,10);
    362. // itoa(v,p->next->birth.month,10);
    363. // itoa(b,p->next->birth.day,10);
    364. // strcpy(p->next->name,z);
    365. strcpy(p->next->sex,x);
    366. // strcpy(p->next->position,n);
    367. // p->next->wage=m;
    368. p=p->next;
    369. }
    370. printf("%s %s %d %d %d %s %f\n",z,x,c,v,b,n,m);
    371. }
    372. a++;
    373. }
    374. fclose(in);
    375. printf("读取成功\n");
    376. system("pause");
    377. return;
    378. }
    379. void Sort(Staff*head)
    380. {
    381. SF*p;
    382. int judge = 666;
    383. SF sorting;
    384. while (1)
    385. {
    386. judge = 777;
    387. p= head->next;
    388. while (p->next)
    389. {
    390. if (p->wage< p->next->wage)
    391. {
    392. judge = 233;
    393. sorting.wage= p->wage;
    394. p->wage = p->next->wage;
    395. p->next->wage = sorting.wage;
    396. }
    397. p = p->next;
    398. };
    399. if (!judge)
    400. break;
    401. }
    402. printf("排序成功!\n");
    403. system("pause");
    404. }
    405. int main()
    406. {
    407. system("color 1a");
    408. char a;
    409. Staff *head=(Staff*)malloc(sizeof(Staff));
    410. head->next=NULL;
    411. while(1)
    412. {
    413. system("cls");
    414. printf("\t\t***************员工管理软件*************\n");
    415. printf("\t\t\t\t1.新增员工信息\n");
    416. printf("\t\t\t\t2.删除员工信息\n");
    417. printf("\t\t\t\t3.员工信息搜索\n");
    418. printf("\t\t\t\t4.员工信息统计\n");
    419. printf("\t\t\t\t5.员工信息分类存储\n");
    420. printf("\t\t\t\t6.员工信息导入\n");
    421. printf("\t\t\t\t7.按工资排序\n");
    422. printf("\t\t\t\t8.退出\n");
    423. printf("\t\t****************************************\n");
    424. printf("\t\t\t\t请选择\n");
    425. a=getch();
    426. fflush(stdin);
    427. switch(a)
    428. {
    429. case '1':
    430. Input(head);
    431. break;
    432. case '2':
    433. Delete(head);
    434. break;
    435. case '3':
    436. Seek(head);
    437. break;
    438. case '4':
    439. system("cls");
    440. Show(head);
    441. break;
    442. case '5':
    443. Save(head);
    444. break;
    445. case '6':
    446. Read(head);
    447. break;
    448. case '7':
    449. Sort(head);
    450. break;
    451. case '8':
    452. exit(1);
    453. default:
    454. printf("输入错误。\n");
    455. system("pause");
    456. }
    457. }
    458. }