本文实例为大家分享了C语言实现病例管理系统的具体代码,供大家参考,具体内容如下
通过十字交叉链表实现一个病例管理系统,可以查找、删除、更新信息。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
|
#include"stdio.h" #include"stdlib.h" #include"string.h" typedef struct hospital_info{ char dise_num[10]; /*病历编号*/ char ke[10]; /*门诊科别*/ char date[11]; /*门诊时间*/ char symptom[60]; /*症状*/ char diagnosis[60]; /*诊断*/ char treatment[60]; /*治疗意见*/ char doctor[10]; /*医师姓名*/ struct hospital_info *next; }hospitals; typedef struct disease_info{ char dise_num[10]; /*病历编号*/ char employee[10]; /*姓名*/ char sex; /*性别*/ char unit[30]; /*工作单位*/ char date[11]; /*出生日期*/ char drug_allergy[30]; /*药物过敏史*/ char phone[12]; /*联系电话*/ char addr[30]; /*住址*/ hospitals *head_hosp; struct disease_info *next; }diseases; typedef struct unit_info{ char unit_num[10]; /*单位编号*/ char unit[30]; /*单位名称*/ char manager[20]; /*负责人*/ char phone[12]; /*联系电话*/ int total; diseases *head_disease; struct unit_info *next; }units; void create_cross_list(units**head); void save_cross_list(units*head); void traverse_cross_list(units*head); void load_cross_list(units **head); void Revise_unit(units *head); void Revise_dise(units *head); void Revise_hosp(units *head); void Insert_unit(units *head); void Insert_dise(units *head); void Insert_hosp(units *head); void Delete_unit(units *head); void Delete_dise(units *head); void Delete_hosp(units *head); void Search_unit(units *head); void Search_dise(units *head); void Search_hosp(units *head); void Display_no_hosp(units *head); void Sortmonth(units *head); void SortTotal(units *head); void Sortpeople(units *head); void main( void ) { units *head=NULL; short choice; printf ( "-----the unit information manage system!------\n" ); printf ( "< 1----------create the cross list >\n" ); printf ( "< 2----------save the cross list >\n" ); printf ( "< 3----------traverse the cross list >\n" ); printf ( "< 4----------load the cross list >\n" ); printf ( "< 5-----------Revise information >\n" ); printf ( "< 6-----------Insert information >\n" ); printf ( "< 7-----------Delete information >\n" ); printf ( "< 8-----------Search information >\n" ); printf ( "< 9--------------- tong ji >\n" ); printf ( "< 10---------------退出 >\n" ); printf ( "--------------------------------------------->\n" ); f: while (1){ printf ( "请选择要进行的操作:(1-10)" ); scanf ( "%hd" ,&choice); getchar (); /*用于吸收换行符*/ switch (choice) { case 1:create_cross_list(&head); break ; case 2:save_cross_list(head); break ; case 3:traverse_cross_list(head); break ; case 4:load_cross_list(&head); break ; case 5: { printf ( " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n" ); printf ( " ---------修改函数菜单-----------\n" ); printf ( " 1----------------Revise_unit\n" ); printf ( " 2----------------Revise_dise\n" ); printf ( " 3----------------Revise_hosp\n" ); printf ( " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n" ); while (1){ printf ( "**请选择子菜单操作:(1-4)" ); scanf ( "%hd" ,&choice); getchar (); /*用于吸收换行符*/ switch (choice) { case 1:Revise_unit(head); break ; case 2:Revise_dise(head); break ; case 3:Revise_hosp(head); break ; case 4: goto f; } } } case 6: { printf ( " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n" ); printf ( " ---------插入函数菜单-----------\n" ); printf ( " 1----------------Insert_unit\n" ); printf ( " 2----------------Insert_dise\n" ); printf ( " 3----------------Insert_hosp\n" ); printf ( " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n" ); while (1){ printf ( "**请选择子菜单操作:(1-4)" ); scanf ( "%hd" ,&choice); getchar (); /*用于吸收换行符*/ switch (choice) { case 1:Insert_unit(head); break ; case 2:Insert_dise(head); break ; case 3:Insert_hosp(head); break ; case 4: goto f; } } } case 7: { printf ( " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n" ); printf ( " ---------删除函数菜单-----------\n" ); printf ( " 1---------------Delete_unit\n" ); printf ( " 2---------------Delete_dise\n" ); printf ( " 3---------------Delete_hosp\n" ); printf ( " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n" ); while (1){ printf ( "**请选择子菜单操作(1-4):" ); scanf ( "%hd" ,&choice); getchar (); /*用于吸收换行符*/ switch (choice) { case 1:Delete_unit(head); break ; case 2:Delete_dise(head); break ; case 3:Delete_hosp(head); break ; case 4: goto f; } } } case 8: { printf ( " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n" ); printf ( " ---------查询函数菜单-----------\n" ); printf ( " 1---------------Search_unit\n" ); printf ( " 2---------------Search_dise\n" ); printf ( " 3---------------Search_hosp\n" ); printf ( " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n" ); while (1){ printf ( "**请选择子菜单操作(1-4):" ); scanf ( "%hd" ,&choice); getchar (); /*用于吸收换行符*/ switch (choice) { case 1:Search_unit(head); break ; case 2:Search_dise(head); break ; case 3:Search_hosp(head); break ; case 4: goto f; } } } case 9: { printf ( " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n" ); printf ( " ---------统计函数菜单-----------\n" ); printf ( " 1---------------Display_no_hosp\n" ); printf ( " 2---------------Sortmonth\n" ); printf ( " 3---------------SortTotal\n" ); printf ( " 4---------------Sortpeople\n" ); printf ( " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n" ); while (1){ printf ( "**请选择子菜单操作(1-5):" ); scanf ( "%hd" ,&choice); getchar (); /*用于吸收换行符*/ switch (choice) { case 1:Display_no_hosp(head); break ; case 2:Sortmonth(head); break ; case 3:SortTotal(head); break ; case 4:Sortpeople(head); break ; case 5: goto f; } } } case 10: goto down; } } down: ; } /*创建十字交叉链表,并录入信息*/ void create_cross_list(units **head) { units *hp=NULL,*p; diseases *pcrs; hospitals *phs; char ch; loop: p=(units *) malloc ( sizeof (units)); /*创建单位信息结点*/ printf ( "请输入单位的编号:" ); scanf ( "%s" ,p->unit_num); printf ( "请输入单位名称:" ); scanf ( "%s" ,p->unit); printf ( "请输入负责人:" ); scanf ( "%s" ,p->manager); printf ( "请输入联系电话:" ); scanf ( "%s" ,p->phone); /*输入各项数据*/ getchar (); /*用于读scanf输入中的换行符*/ p->head_disease=NULL; p->next=hp; hp=p; printf ( "继续输入%s下单位的病例基本信息(Y/N)?\n" ,p->unit); scanf ( "%c" ,&ch); getchar (); while (ch== 'y' ||ch== 'Y' ) { pcrs=(diseases *) malloc ( sizeof (diseases)); printf ( "请输入病例编号:" ); gets (pcrs->dise_num); printf ( "请输入病人姓名:" ); gets (pcrs->employee); printf ( "请输入性别:" ); scanf ( "%s" ,&pcrs->sex); getchar (); printf ( "请输入出生日期:" ); gets (pcrs->date); printf ( "请输入药物过敏史:" ); gets (pcrs->drug_allergy); printf ( "请输入联系电话:" ); gets (pcrs->phone); printf ( "请输入住址:" ); gets (pcrs->addr); /*输入各项数据*/ strcpy (pcrs->unit,p->unit); pcrs->head_hosp=NULL; pcrs->next=p->head_disease; /*头指针值赋给新结点的指针域*/ p->head_disease=pcrs; /*头指针指向新结点*/ printf ( "继续输入%s的门诊信息(Y/N)?\n" ,pcrs->employee); ch= getchar (); getchar (); while (ch== 'y' ||ch== 'Y' ) { /*是,循环创建信息链*/ phs=(hospitals *) malloc ( sizeof (hospitals)); printf ( "请输入门诊科别:" ); scanf ( "%s" ,phs->ke); printf ( "请输入门诊时间:" ); scanf ( "%s" ,phs->date); printf ( "请输入症状:" ); scanf ( "%s" ,phs->symptom); printf ( "请输入诊断:" ); scanf ( "%s" ,phs->diagnosis); printf ( "请输入治疗意见:" ); scanf ( "%s" ,phs->treatment); printf ( "请输入医师姓名:" ); scanf ( "%s" ,phs->doctor); /*输入各项数据*/ getchar (); strcpy (phs->dise_num,pcrs->dise_num); phs->next=pcrs->head_hosp; /*头指针值赋给新结点的指针域*/ pcrs->head_hosp=phs; /*头指针指向新结点*/ printf ( "继续输入%s的下一条病例信息(Y/N)?\n" ,pcrs->employee); ch= getchar (); getchar (); /*是否继续创建下一个基本信息结点*/ } printf ( "继续输入下一个病例的基本信息(Y/N)?\n" ); ch= getchar (); getchar (); /*是否继续创建下一个基本信息结点*/ } printf ( "继续输入下一个单位的信息(Y/N)?\n" ); ch= getchar (); getchar (); if (ch== 'y' ||ch== 'Y' ) goto loop; (*head)=hp; p=(*head); } /*保存十字交叉链表数据到磁盘文件*/ void save_cross_list(units *head) { FILE *out1,*out2,*out3; units *p=head; diseases *pcrs; hospitals *phs; if ((out1= fopen ( "c:\\unit.dat" , "wb+" ))==NULL) /*以只写方式将单位基本信息文件创建在c盘下的unit.text文本文件,并使out1指向它*/ exit (-1); if ((out2= fopen ( "c:\\disease.dat" , "wb+" ))==NULL) /*打开病历信息文件*/ exit (-1); if ((out3= fopen ( "c:\\hospital.dat" , "wb+" ))==NULL) /*打开门诊信息文件*/ exit (-1); while (p!=NULL) { fwrite (p, sizeof (units),1,out1); /*写单位基本信息记录*/ pcrs=p->head_disease; /*病历遍历指针指向病历链链头*/ while (pcrs!=NULL) { /*遍历病历信息链*/ fwrite (pcrs, sizeof (diseases),1,out2); /*写病历记录*/ phs=pcrs->head_hosp; /*门诊遍历指针指向门诊链链头*/ while (phs!=NULL) { fwrite (phs, sizeof (hospitals),1,out3); /*写门诊链*/ phs=phs->next; } pcrs=pcrs->next; /*指向下一个病历链*/ } p=p->next; /*指向下一个单位基本信息结点*/ } fclose (out1); /*关闭基本信息文件*/ fclose (out2); /*关闭病历信息文件*/ fclose (out3); /*关闭门诊信息文件*/ printf ( "记录已被保存.\n" ); } /*遍历十字交叉链表,输出各项基本信息*/ void traverse_cross_list(units *head) { units *p=head; diseases *pcrs; hospitals *phs; printf ( "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n" ); while (p!=NULL) { /*遍历单位基本信息链*/ printf ( "%s\t%s\t%s\t%s\n" ,p->unit_num,p->unit,p->manager,p->phone); pcrs=p->head_disease; while (pcrs!=NULL) { /*遍历病历基本信息链与门诊信息链*/ printf ( "%s\t%s\t%c\t%s\t%s\t%s\t%s\t%s\n" ,pcrs->dise_num,pcrs->employee,\ pcrs->sex,pcrs->unit,pcrs->date,pcrs->drug_allergy,pcrs->phone,pcrs->addr); phs=pcrs->head_hosp; while (phs!=NULL) { printf ( "%s\t%s\t%s\t%s\t%s\t%s\t%s\n" ,phs->dise_num,phs->ke,phs->date,\ phs->symptom,phs->diagnosis,phs->treatment,phs->doctor); phs=phs->next; } pcrs=pcrs->next; } p=p->next; } printf ( "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n" ); } /*从磁盘文件中读取*/ void load_cross_list(units **head) { FILE *in1,*in2,*in3; units *hp=NULL,*p; diseases *pcrs; hospitals *phs; if ((in1= fopen ( "c:\\unit.dat" , "rb" ))==NULL) exit (-1); if ((in2= fopen ( "c:\\disease.dat" , "rb" ))==NULL) exit (-1); if ((in3= fopen ( "c:\\hospital.dat" , "rb" ))==NULL) exit (-1); while (! feof (in1)) { p=(units *) malloc ( sizeof (units)); fread (p, sizeof (units),1,in1); if (! feof (in1)) { p->head_disease=NULL; p->next=hp; hp=p; } } (*head)=hp; while (! feof (in2)) { pcrs=(diseases *) malloc ( sizeof (diseases)); fread (pcrs, sizeof (diseases),1,in2); if (! feof (in2)) { p=(*head); pcrs->head_hosp=NULL; while (p!=NULL) { if (! strcmp (p->unit,pcrs->unit)) { pcrs->next=p->head_disease; p->head_disease=pcrs; break ; } else p=p->next; } } } (*head)=hp; while (! feof (in3)) { phs=(hospitals *) malloc ( sizeof (hospitals)); fread (phs, sizeof (hospitals),1,in3); if (! feof (in3)) { p=(*head); while (p!=NULL) { pcrs=p->head_disease; while (pcrs!=NULL) { if (! strcmp (phs->dise_num,pcrs->dise_num)) { phs->next=pcrs->head_hosp; pcrs->head_hosp=phs; break ; } else pcrs=pcrs->next; } p=p->next; } } } fclose (in1); fclose (in2); fclose (in3); } //修改一个单位基本信息 void Revise_unit(units *head) { units *p,*q; char num[10]; char choice; char update[30]; p=q=head; printf ( "please input 要修改的单位编号:" ); scanf ( "%s" ,num); getchar (); while ( strcmp (num,p->unit_num)!=0&&p->next!=0) /*查找需要修改信息的单位编号*/ { q=p; p=p->next; } if ( strcmp (num,p->unit_num)==0) { printf ( " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n" ); printf ( " ***a---------to revise unit_num\n" ); printf ( " ***b---------to revise unit_name\n" ); printf ( " ***c---------to revise unit_manager\n" ); printf ( " ***d---------to revise unit_phone\n" ); printf ( " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n" ); loop: printf ( "please input要选择的操作:(a-d)" ); choice= getchar (); getchar (); printf ( "please input更新后的信息:" ); switch (choice) { case 'a' : scanf ( "%s" ,update); strncpy (p->unit_num,update, strlen (update)+1); goto loop; case 'b' : scanf ( "%s" ,update); strncpy (p->unit,update, strlen (update)+1); goto loop; case 'c' : scanf ( "%s" ,update); strncpy (p->manager,update, strlen (update)+1); goto loop; case 'd' : scanf ( "%s" ,update); strncpy (p->phone,update, strlen (update)+1); goto loop; default : break ; } printf ( "修改成功!\n" ); } else printf ( "not find!\n" ); } //修改一个病历基本信息 void Revise_dise(units *head) { units *p; diseases *pcrs; char num[10]; char update[30]; char choice; p=head; printf ( "please input 要修改信息的员工编号:" ); scanf ( "%s" ,num); getchar (); pcrs=p->head_disease; while (p!=NULL) { while (pcrs!=NULL) { if ( strcmp (pcrs->dise_num,num)==0) goto loop1; pcrs=pcrs->next; } p=p->next; pcrs=p->head_disease->next; } if (p==NULL) { printf ( "not find the unit" ); goto end; } loop1: printf ( " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n" ); printf ( " ***a--------to revise the dise num\n" ); printf ( " ***b--------to revise the employee\n" ); printf ( " ***c--------to revise the sex\n" ); printf ( " ***d--------to revise the unit\n" ); printf ( " ***e--------to revise the date\n" ); printf ( " ***f---------to revise the drug_allergy\n" ); printf ( " ***g---------to revise the phone\n" ); printf ( " ***h---------to revise the addr\n" ); printf ( " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n" ); loop2: printf ( "please input要选择的操作:(a-h)" ); choice= getchar (); getchar (); printf ( "请输入修改后的信息:" ); switch (choice) { case 'a' : scanf ( "%s" ,update); strncpy (pcrs->dise_num,update, sizeof (update)+1); goto loop2; case 'b' : scanf ( "%s" ,update); strncpy (pcrs->employee,update, sizeof (update)+1); goto loop2; case 'c' : scanf ( "%c" ,&pcrs->sex); goto loop2; case 'd' : scanf ( "%s" ,update); strncpy (pcrs->unit,update, strlen (update)+1); goto loop2; case 'e' : scanf ( "%s" ,update); strncpy (pcrs->date,update, strlen (update)+1); goto loop2; case 'f' : scanf ( "%s" ,update); strncpy (pcrs->drug_allergy,update, strlen (update)+1); goto loop2; case 'g' : scanf ( "%s" ,update); strncpy (pcrs->phone,update, strlen (update)+1); goto loop2; case 'h' : scanf ( "%s" ,update); strncpy (pcrs->addr,update, strlen (update)+1); goto loop2; default : break ; } printf ( "修改成功!\n" ); end: ; } /*修改一个门诊基本信息*/ void Revise_hosp(units *head) { units *p; diseases *pcrs; hospitals *phs; char num[10],date[11]; char choice; char update[30]; p=head; printf ( "please input 要修改信息的病历编号:" ); scanf ( "%s" ,num); pcrs=p->head_disease; while (p!= NULL) { while (pcrs!= NULL) { if ( strcmp (pcrs->dise_num,num)==0) goto loop1; pcrs=pcrs->next; } p=p->next; pcrs=p->head_disease->next; } if (p==NULL) { printf ( "not find the unit" ); goto end; } loop1: printf ( "please input 要修改信息的门诊时间:" ); scanf ( "%s" ,date); phs=pcrs->head_hosp; while (phs!= NULL) { if ( strcmp (phs->date,date)==0) goto loop2; phs=phs->next; } if (phs==NULL) { printf ( "not find " ); goto end; } loop2: printf ( " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n" ); printf ( " ***a---------revise the dise_num\n" ); printf ( " ***b--------revise the ke\n" ); printf ( " ***c--------revise the date\n" ); printf ( " ***d--------revise the symptom\n" ); printf ( " ***e--------revise the diagnosis\n" ); printf ( " ***f--------revise the treatment\n" ); printf ( " ***g--------revise the doctor\n" ); printf ( " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n" ); loop3: printf ( "please input要进行的操作:" ); choice= getchar (); getchar (); printf ( "please input the update information:" ); scanf ( "%s" ,update); switch (choice) { case 'a' : strncpy (phs->dise_num,update, strlen (update)+1); goto loop3; case 'b' : strncpy (phs->ke,update, strlen (update)+1); goto loop3; case 'c' : strncpy (phs->date,update, strlen (update)+1); goto loop3; case 'd' : strncpy (phs->symptom,update, strlen (update)+1); goto loop3; case 'e' : strncpy (phs->diagnosis,update, strlen (update)+1); goto loop3; case 'f' : strncpy (phs->treatment,update, strlen (update)+1); goto loop3; case 'g' : strncpy (phs->doctor,update, strlen (update)+1); goto loop3; default : break ; } printf ( "修改成功!\n" ); end: ; } //按单位编号由小到大在链表中插入一个单位新结点 void Insert_unit(units *head) { units *p1,*p2; int state; loop: p1=head; p2= malloc ( sizeof (units)); p2->next=NULL; p2->head_disease= malloc ( sizeof (diseases)); p2->head_disease->next=NULL; printf ( "请输入单位编号:" ); scanf ( "%s" ,p2->unit_num); a: while (p1->next!=NULL) { p1=p1->next; if ( strcmp (p1->unit_num,p2->unit_num)==0) { state = 1; break ; } else { state=0; break ; } } switch (state) { case 0: if ( strcmp (p1->unit_num,p2->unit_num)>0) { if (p1==head->next) { head->next=p2; p2->next=p1; } else { p1->next=p2; p2->next=p1->next; } break ; } else goto a; case 1: printf ( "the unit num already exit,pleae input another one\n" ); goto loop; } printf ( "请输入单位名称:" ); scanf ( "%s" ,p2->unit); printf ( "请输入负责人:" ); scanf ( "%s" ,p2->manager); printf ( "请输入联系电话:" ); scanf ( "%s" ,p2->phone); printf ( "插入成功!\n" ); } //按病历编号由小到大插入一个员工病历信息结点 void Insert_dise(units *head) { units *p; diseases *pcrs1,*pcrs2; int state; char name[30]; printf ( "请输入单位名称:" ); scanf ( "%s" ,name); p=head; while (p->next!= NULL) { p=p->next; if ( strcmp (p->unit,name)==0) break ; } if (p==NULL) { printf ( "not find the unit!" ); goto end; } pcrs1=p->head_disease; pcrs2= malloc ( sizeof (diseases)); pcrs2->next = NULL; pcrs2->head_hosp= malloc ( sizeof (hospitals)); pcrs2->head_hosp->next=NULL; strcpy (pcrs2->unit,name); loop: printf ( "请输入病例编号:" ); scanf ( "%s" ,pcrs2->dise_num); if (pcrs1==NULL) p->head_disease->next = pcrs2; else { a: while (pcrs1 ->next != NULL) { pcrs1= pcrs1->next; if ( strcmp (pcrs1->dise_num,pcrs2->dise_num)==0) { state = 1; break ; } else { state=0; break ; } } switch (state) { case 0: if ( strcmp (pcrs1->dise_num,pcrs2->dise_num)>0) { if (pcrs1=p->head_disease->next) { p->head_disease->next=pcrs2; pcrs2->next=pcrs1; } else { pcrs1->next=pcrs2; pcrs2->next=pcrs1->next; } break ; } else goto a; case 1: printf ( "the disease number already exit,please input another one\n" ); goto loop; } } printf ( "请输入姓名:" ); scanf ( "%s" ,pcrs2->employee); printf ( "请输入性别:" ); scanf ( "%c" ,pcrs2->sex); printf ( "请输入出生日期" ); scanf ( "%s" ,pcrs2->date); printf ( "请输入药物过敏史:" ); scanf ( "%s" ,pcrs2->drug_allergy); printf ( "请输入联系电话:" ); scanf ( "%s" ,pcrs2->phone); printf ( "请输入住址:" ); scanf ( "%s" ,pcrs2->addr); printf ( "插入成功!\n" ); end: ; } //按门诊时间由小到大插入一个员工门诊信息结点 void Insert_hosp(units *head) { units *p; diseases *pcrs; hospitals *phs1,*phs2; char number[10]; printf ( "请输入单位编号:" ); scanf ( "%s" ,number); p=head; while (p->next!= NULL) { p=p->next; if ( strcmp (p->unit_num,number)==0) break ; } if (p==NULL) { printf ( "not find the unit\n" ); goto end; } pcrs=p->head_disease; printf ( "请输入病例编号:" ); scanf ( "%s" ,number); while (pcrs->next!=NULL) { pcrs=pcrs->next; if ( strcmp (pcrs->dise_num,number)==0) break ; } if (pcrs==NULL) { printf ( "not find the question \n" ); goto end; } phs1=pcrs->head_hosp->next; phs2= malloc ( sizeof (hospitals)); phs2->next=NULL; if (phs1==NULL) pcrs->head_hosp->next =phs2; else { while (phs1->next!=NULL) phs1=phs1->next; phs1->next=phs2; } strncpy (phs2->dise_num,number, strlen (number)+1); printf ( "请输入科别:" ); scanf ( "%s" ,phs2->ke); printf ( "请输入诊断时间:" ); scanf ( "%s" ,phs2->date); printf ( "请输入主诉:" ); scanf ( "%s" ,phs2->symptom); printf ( "请输入初步诊断:" ); scanf ( "%s" ,phs2->diagnosis); printf ( "请输入治疗意见:" ); scanf ( "%s" ,phs2->treatment); printf ( "请输入医师姓名:" ); scanf ( "%s" ,phs2->doctor); printf ( "插入成功!\n" ); end: ; } /*删除一条单位信息记录*/ void Delete_unit(units *head) { units *p,*q; char name[30]; printf ( "please input 要删除的单位名称:" ); scanf ( "%s" ,name); getchar (); p=q=head; while ( strcmp (name,p->unit)!=0&&p->next!=0) /*p指的不是要找的结点,并且后面还有结点*/ { q=p; p=p->next; } /*p后移一个结点*/ if ( strcmp (name,p->unit)==0) { /*找要删除位置*/ if (p==head) head=p->next; /*若p指向的是首结点,把第二个结点地址赋予head*/ else q->next=p->next; /*否则将下一个结点地址赋给前一结点地址*/ free (p); printf ( "删除成功!\n" ); } else printf ( "%s not been found!\n" ,name); /*找不到该结点*/ } /*删除一条病历信息记录*/ void Delete_dise(units *head) { units *p,*q; diseases *pcrs,*t; char name[10],employee[30]; printf ( "please input 要删除信息的单位名称:" ); scanf ( "%s" ,name); getchar (); p=q=head; while ( strcmp (name,p->unit)!=0&&p->next!=0) /*p指的不是要找的结点,并且后面还有结点*/ { q=p; p=p->next; } /*p后移一个结点*/ if ( strcmp (name,p->unit)==0) { printf ( "please input 要删除信息的员工姓名:" ); scanf ( "%s" ,employee); getchar (); pcrs=t=p->head_disease; while ( strcmp (employee,pcrs->employee)!=0&&pcrs->next!=0) { t=pcrs; pcrs=pcrs->next; } /*pcrs后移一个结点*/ if ( strcmp (employee,pcrs->employee)==0) { if (pcrs==p->head_disease) p->head_disease=pcrs->next; /*若pcrs指向的是首结点,把第二个结点地址赋予head*/ else t->next=pcrs->next; /*否则将下一个结点地址赋给前一结点地址*/ free (pcrs); printf ( "删除成功!\n" ); } } else printf ( "%s not been found!\n" ,employee); } //删除一条门诊信息记录 void Delete_hosp(units *head) { units *p,*q; diseases *pcrs,*t1; hospitals *phs,*t2; char name[30],employee[10],date[11]; printf ( "please input 要删除信息的单位名称:" ); scanf ( "%s" ,name); getchar (); p=q=head; while ( strcmp (name,p->unit)!=0&&p->next!=0) /*p指的不是要找的结点,并且后面还有结点*/ { q=p; p=p->next; } /*p后移一个结点*/ if ( strcmp (name,p->unit)==0) { printf ( "please input 要删除信息的员工姓名:" ); scanf ( "%s" ,employee); getchar (); pcrs=t1=p->head_disease; while ( strcmp (employee,pcrs->employee)!=0&&pcrs->next!=0) { t1=pcrs; pcrs=pcrs->next; } /*pcrs后移一个结点*/ if ( strcmp (employee,pcrs->employee)==0) { printf ( "please input 要删除信息的病历时间:" ); scanf ( "%s" ,date); getchar (); phs=t2=pcrs->head_hosp; while ( strcmp (date,phs->date)!=0&&phs->next!=0) { t2=phs; phs=phs->next; } if ( strcmp (date,phs->date)==0) { if (phs==pcrs->head_hosp) pcrs->head_hosp=phs->next; else t2->next=phs->next; free (phs); printf ( "删除成功!\n" ); } } } else printf ( "%s not been found!\n" ,date); } /*查询一条单位信息记录并输出信息*/ void Search_unit(units *head) { units *p,*q; char num[10]; p=q=head; printf ( "please input 要查询的单位编号:" ); scanf ( "%s" ,num); getchar (); while ( strcmp (num,p->unit_num)!=0&&p->next!=0) /*p指的不是要查询的结点并且后面还有结点*/ { q=p; p=p->next; } /*p后移一个结点*/ if ( strcmp (num,p->unit_num)==0) { /*找要查询的结点,输出各项基本信息*/ printf ( "单位编号:%s\n" ,p->unit_num); printf ( "单位名称:%s\n" ,p->unit); printf ( "负责人:%s\n" ,p->manager); printf ( "联系电话:%s\n" ,p->phone); } else printf ( "%s not been found!\n" ,num); /*找不到要查询的结点*/ } //查询一条病历信息链并输出信息 void Search_dise(units *head) { units *p,*q; diseases *pcrs,*t; char name[10],num[10]; p=q=head; printf ( "please input 要查询的单位名称:" ); scanf ( "%s" ,name); getchar (); while ( strcmp (name,p->unit)!=0&&p->next!=0) { q=p; p=p->next; } /*p后移一个结点*/ if ( strcmp (name,p->unit)==0) /*找要查询的结点*/ { pcrs=t=p->head_disease; printf ( "please input 要查询的病历编号:" ); scanf ( "%s" ,num); getchar (); while ( strcmp (num,pcrs->dise_num)!=0&&pcrs->next!=0) { t=pcrs; pcrs=pcrs->next; } /*p后移一个结点*/ if ( strcmp (num,pcrs->dise_num)==0) { /*找要查询的结点*/ printf ( "病历编号:%s\n" ,pcrs->dise_num); printf ( "姓名:%s\n" ,pcrs->employee); printf ( "性别:%c\n" ,pcrs->sex); printf ( "工作单位:%s\n" ,pcrs->unit); printf ( "出生日期:%s\n" ,pcrs->date); printf ( "药物过敏史:%s\n" ,pcrs->drug_allergy); printf ( "联系电话:%s\n" ,pcrs->phone); printf ( "住址:%s\n" ,pcrs->addr); } } else printf ( "not been found!\n" ); /*找不到要查询的结点*/ } //查询一条门诊信息链并输出信息 void Search_hosp(units *head) { units *p,*q; diseases *pcrs,*t1; hospitals *phs,*t2; char name[10],num[10],date[11]; p=q=head; printf ( "please input 要查询的单位名称:" ); scanf ( "%s" ,name); getchar (); while ( strcmp (name,p->unit)!=0&&p->next!=0) { q=p; p=p->next; } /*p后移一个结点*/ if ( strcmp (name,p->unit)==0) /*找要查询的结点*/ { pcrs=t1=p->head_disease; printf ( "please input 要查询的病历编号:" ); scanf ( "%s" ,num); getchar (); while ( strcmp (num,pcrs->dise_num)!=0&&pcrs->next!=0) { t1=pcrs; pcrs=pcrs->next; } /*p后移一个结点*/ if ( strcmp (num,pcrs->dise_num)==0) /*找要查询的结点*/ { phs=t2=pcrs->head_hosp; printf ( "please input 要查询的门诊时间:" ); scanf ( "%s" ,date); getchar (); while ( strcmp (date,phs->date)!=0&&phs->next!=0) { t2=phs; phs=phs->next; } /*p后移一个结点*/ if ( strcmp (date,phs->date)==0) { printf ( "病历编号:%s\n" ,phs->dise_num); printf ( "诊断科别:%s\n" ,phs->ke); printf ( "门诊时间:%s\n" ,phs->date); printf ( "主诉:%s\n" ,phs->symptom); printf ( "初步诊断:%s\n" ,phs->diagnosis); printf ( "治疗意见:%s\n" ,phs->treatment); printf ( "医师姓名:%s\n" ,phs->doctor); } } } else printf ( "not been found!\n" ); /*找不到要查询的结点*/ } /*列出从未门诊的员工信息(单位.姓名.住址.电话)*/ void Display_no_hosp(units *head) { units *p=head; diseases *pcrs; hospitals *phs; while (p!=NULL) { printf ( "%s\n" ,p->unit); //输出各个单位名称 printf ( "员工姓名\t电话\t住址\n" ); pcrs=p->head_disease; while (pcrs!=NULL) { phs=pcrs->head_hosp; //如果phs是空链,则该员工从未门诊过 if (phs==NULL) printf ( "%s\t%s\t%s\n" ,pcrs->employee,pcrs->phone,pcrs->addr); else ; //否则门诊过,执行空语句 pcrs=pcrs->next; } p=p->next; } } /*统计一年中各月的门诊量并按降序排列后输出*/ void Sortmonth(units *head) { units *p=head; diseases *pcrs; hospitals *phs; int s[12],i,j,t,count; char year[10],month[10]; for (i=0;i<12;i++) s[i]=0; printf ( "--请输入要统计的年份:" ); //手动输入要统计的年份 scanf ( "%s" ,year); getchar (); printf ( "--请输入要统计的月份:" ); for (i=0;i<12;i++) { count=0; //统计一年中各月的门诊量 scanf ( "%s" ,month); while (p!=NULL) { pcrs=p->head_disease; while (pcrs!=NULL) { phs=pcrs->head_hosp; while (phs!=NULL) { j=0; while (phs->date[j]==year[j]&&(j<4)) j++; //判断是否为要统计的年份 if (j==4) //是,比较是否为在该月的门诊 if (phs->date[j+1]==month[0]&&phs->date[j+2]==month[1]) count++; else ; //不是,执行空语句 phs=phs->next; } pcrs=pcrs->next; } p=p->next; } s[i]=count; } for (i=0;i<12;i++) //输出各月的总门诊量 printf ( "%d\t" ,s[i]); printf ( "\n" ); for (i=0;i<11;i++) //降序排序 for (j=0;j<11-i;j++) if (s[j]<s[j+1]) t=s[j],s[j]=s[j+1];s[j+1]=t; printf ( "请输出按降序排列后的统计量:\n" ); for (i=0;i<12;i++) //输出排列后的各月总门诊量 printf ( "%d\t" ,s[i]); printf ( "\n" ); } /*统计各单位员工的总门诊量并按降序排列后输出*/ void SortTotal(units *head) { units *p=head,*q; diseases *pcrs; hospitals *phs; int count,i,j,t,len=0; while (p!=NULL) { //计算各单位员工的总门诊量 p->total=0; count=0; pcrs=p->head_disease; while (pcrs!=NULL) { phs=pcrs->head_hosp; while (phs!=NULL) { count++; phs=phs->next; } pcrs=pcrs->next; } p->total=count; printf ( "%s\t" ,p->unit); //输出各个单位名称 p=p->next; } printf ( "\n" ); p=head; //遍历指针p指向头指针 while (p!=NULL) { //输出统计数 printf ( "%d\t" ,p->total); p=p->next; } printf ( "\n" ); p=head; while (p!=NULL) { //计算单位信息链表长度 len++; p=p->next; } for (i=0,p=head;i<len-1;i++,p=p->next) //对统计量降序排序 for (j=i+1,q=p->next;j<len;j++,q=q->next) if (p->total<q->total) { t=p->total; p->total=q->total; q->total=t; } p=head; printf ( "请输出按降序排列后的统计量:\n" ); while (p!=NULL) { //输出排序后的统计量 printf ( "%d\t" ,p->total); p=p->next; } printf ( "\n" ); } //统计各单位员工总人数并输出 void Sortpeople(units *head) { units *p=head; diseases *pcrs; int count; while (p!=NULL) { p->total=0; count=0; pcrs=p->head_disease; while (pcrs!=NULL) { count++; pcrs=pcrs->next; } p->total=count; p=p->next; } p=head; while (p!=NULL) { printf ( "输出单位名称:%s" ,p->unit); printf ( "统计单位总人数:%d\n" ,p->total); p=p->next; } } |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。