-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsrc
1967 lines (1927 loc) · 55.3 KB
/
src
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
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<windows.h>
#include<time.h>
#define MAXDAY 30//最大借阅天数
#define rate 0.1//借阅超期费率
char adminID[20]="1";//管理员账号
char adminPassword[20]="1";//管理员密码
char stuID[20];//全局变量后续还需要通过这个账号获取其他信息 因此要一直保留
char admID[20];
struct readerInfo*stuNode=NULL;
struct tm* timeGet()
{
time_t second;
struct tm *stdtime = NULL;
second=time(NULL);//time函数返回的是1970 1.1 00:00至今的秒数
stdtime= localtime(&second);//localtime切割秒数,在结构体中存的是年份和1900的差值
return stdtime;
}
time
struct time
{
int year;
int month;
int day;
};
struct bookInfo
{
char isbn[20];
char bookName[40];
char writer[40];
char kind[20];
char press[40];
char time[20];
int amount;
double price;
struct bookInfo*next;
};
struct readerInfo
{
int no;
char id[20];
char readerName[40];
char password[20];
int maxAmount;
int keepAmount;
struct readerInfo*next;
};
struct borrowInfo
{
char readerId[20];
char readerName[40];
char isbn[20];
char bookName[40];
char writer[40];
char press[40];
char sign[10];
struct time borrowTime;
struct borrowInfo*next;
};
struct returnInfo
{
char readerId[20];
char readerName[40];
char isbn[20];
char bookName[40];
char writer[40];
char press[40];
struct time returnTime;
struct returnInfo*next;
};
//借阅时间计算 在time.h中difftime可以计算时间差值
int monthCount(int year,int month,int day)//计算当天是当年的第几天
{
int sumdays=0;
switch(month)
{
case 12:
sumdays+=30;
case 11:
sumdays+=31;
case 10:
sumdays+=30;
case 9:
sumdays+=31;
case 8:
sumdays+=31;
case 7:
sumdays+=30;
case 6:
sumdays+=31;
case 5:
sumdays+=30;
case 4:
sumdays+=31;
case 3:
sumdays+=28;
case 2:
sumdays+=31;
case 1:
sumdays+=day;
}
if(((year%4==0&&year%100!=0)||(year%400==0))&&month>2)
sumdays+=1;
return sumdays-1;
}
int yearCount(int yearStart,int yearEnd)//计算年份差距从而计算year*366 or year*365
{
int yearDaySum=0;
for(int i=yearStart+1;i<yearEnd;i++)
{
if((yearStart%4==0&&yearStart%100!=0)||yearStart%400==0)
yearDaySum+=366;
else yearDaySum+=365;
}
return yearDaySum;
}
int dayCount(int startYear,int startMonth,int startDay,int endYear,int endMonth,int endDay)//计算两个时间之间差的天数
{
int sum=365;
if((startYear%4==0&&startYear%100!=0)||startYear%400==0)
sum=366;
int startYearDay=monthCount(startYear,startMonth,startDay);
int endYearDay=monthCount(endYear,endMonth,endDay);
int day=yearCount(startYear,endYear);
if(startYear<endYear)
return sum-startYearDay+endYearDay+day;
else if(startYear==endYear)
return startYearDay-startYearDay;
}
//全局变量:用于加载图书信息 读者信息 借书信息 还书信息的头结点
struct bookInfo*head=(struct bookInfo*)malloc(sizeof(bookInfo));
struct readerInfo*rhead=(struct readerInfo*)malloc(sizeof(readerInfo));
struct borrowInfo*bohead=(struct borrowInfo*)malloc(sizeof(borrowInfo));
struct returnInfo*rehead=(struct returnInfo*)malloc(sizeof(returnInfo));
void memsetAll()
{
memset(head,0,sizeof(bookInfo));
memset(rhead,0,sizeof(readerInfo));
memset(bohead,0,sizeof(borrowInfo));
memset(rehead,0,sizeof(returnInfo));
}
void adminMenu();
void bookSearchMainMenu();
void mainMenu();
void modifyMenu();
void bookadminMenu();
void readeradminMenu();
void readeradminMenuBR();
void borrowInfoMenu();
void returnInfoMenu();
void readeruserMenu();
int istime(struct bookInfo*from,char*time);
void bookModifyView(struct bookInfo*current);
void bookInfocpy(struct bookInfo*from,struct bookInfo*to);
struct bookInfo*bookGetnode();
void initialSave();
void downloadBook();
struct bookInfo *bookSearch(char*isbn,char*bookName);
void bookSave();
void bookView(struct bookInfo*head);
void bookInsert();
void bookDelete();
void bookModify();
void bookSearchName();
void bookSearchWriter();
void bookSearchPress();
void bookSearchTime();
/************************************************************/
void readerModifyView(struct readerInfo*current);
struct readerInfo*readerGetnode();
void readerInitialSave();
void readerSave(struct readerInfo*rhead);
void downloadReader();
void readerInsert();
void readerDelete();
struct readerInfo*readerSearch(char *readerID);
void readerModifyMenu();
void readerModify();
void readerView();
/***********************************************************/
void borrowView(struct borrowInfo*head);
void downloadBorrowInfo();
void borrowSearch(int type,char*info);
void borrowSearchBook();
void borrowSearchReader();
void borrowSearchWriter();
struct borrowInfo*borrowSearchUB(char*stuid,char*bookisbn);
void returnView(struct returnInfo*head);
void returnSearch(int type,char*info);
void returnSearchReader();
void returnSearchBook();
void returnSearchWriter();
void downloadReturnInfo();
/*********************************************************/
void bookReturn();
void bookBorrow();
void bookReturnAdmin();
/********************************************************/
int adminLogin();
int readerLogin();
void userModify();
void signUp();
void userLoginMenu();
/********************************************************/
void readerFree();
void bookFree();
void borrowFree();
void adminMenu()
{
int choice;
system("cls");
printf("\t\t\t\t\t\t1.图书信息管理\n");
printf("\t\t\t\t\t\t2.读者信息管理\n");
printf("\t\t\t\t\t\t3.借阅信息管理\n\n");
printf("\t\t\t\t\t\t9.返回上一级\n");
printf("请选择:\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
bookadminMenu();
break;
case 2:
readeradminMenu();
break;
case 3:
readeradminMenuBR();
break;
case 9:
mainMenu();
break;
default:
printf("没有相应操作的选项!\n");
}
}
void readeradminMenu()
{
int choice;
char id[20];
struct readerInfo*current=NULL;
do
{
system("cls");
printf("\t\t\t\t\t# # # # #1.初始读者信息 # # # # #\n");
printf("\t\t\t\t\t# # # # #2.查看读者信息 # # # # #\n");
printf("\t\t\t\t\t# # # # #3.添加读者信息 # # # # #\n");
printf("\t\t\t\t\t# # # # #4.删除读者信息 # # # # #\n");
printf("\t\t\t\t\t# # # # #5.查找读者信息 # # # # #\n");
printf("\t\t\t\t\t# # # # #6.修改读者信息 # # # # #\n");
printf("\n\n");
printf("\t\t\t\t\t*********9.返回上一级 *********\n");
printf("\t\t\t\t\t*********0.返回主菜单 *********\n");
printf("请选择:\n");
scanf("%d",&choice);
fflush(stdin);
switch(choice)
{
case 1:
readerInitialSave();
break;
case 2:
readerView();
break;
case 3:
readerInsert();
break;
case 4:
readerDelete();
break;
case 5:
system("cls");
printf("请输入读者借阅号:\n");
gets(id);
fflush(stdin);
current=readerSearch(id);
if(current==NULL)
printf("系统没有您要查找的读者信息!\n");
else
{
printf("您要查询的读者信息为:\n");
readerModifyView(current);
}
break;
case 6:
readerModify();
break;
case 9:
adminMenu();
return;
case 0:
mainMenu();
return;
}
getchar();
}while(choice!=0||choice!=9);
}
void readeradminMenuBR()
{
int choice;
do{
system("cls");
printf("\t\t\t\t\t# # # # #1.借书信息查询 # # # # #\n");
printf("\t\t\t\t\t# # # # #2.还书信息查询 # # # # #\n");
printf("\t\t\t\t\t# # # # #3.归还逾期图书 # # # # #\n");
printf("\n\n");
printf("\t\t\t\t\t*********9.返回上一级 *********\n");
printf("\t\t\t\t\t*********0.返回主菜单 *********\n");
printf("请选择:\n");
scanf("%d",&choice);
fflush(stdin);
switch(choice)
{
case 1:
borrowInfoMenu();
getchar();
break;
case 2:
returnInfoMenu();
getchar();
break;
case 3:
bookReturnAdmin();
getchar();
break;
case 9:
adminMenu();
return;
case 0:
mainMenu();
return;
default:
printf("没有相应的选项!");
}
}while(choice!=0||choice!=9);
}
void bookadminMenu()
{
int choice;
do
{
system("cls");
printf("\t\t\t\t\t# # # # #1.图书初始化 # # # # #\n");
printf("\t\t\t\t\t# # # # #2.查看全部图书# # # # #\n");
printf("\t\t\t\t\t# # # # #3.添加新的图书# # # # #\n");
printf("\t\t\t\t\t# # # # #4.删除图书 # # # # #\n");
printf("\t\t\t\t\t# # # # #5.查找图书 # # # # #\n");
printf("\t\t\t\t\t# # # # #6.修改图书 # # # # #\n");
printf("\n\n");
printf("\t\t\t\t\t*********9.上一级 *********\n");
printf("\t\t\t\t\t*********0.返回主菜单 *********\n");
printf("请选择:\n");
scanf("%d",&choice);
fflush(stdin);
switch(choice)
{
case 1:
initialSave();
break;
case 2:
bookView(head);
break;
case 3:
bookInsert();
break;
case 4:
bookDelete();
break;
case 5:
bookSearchMainMenu();
break;
case 6:
bookModify();
break;
case 9:
adminMenu();
return ;
case 0:
mainMenu();
return ;
default:
printf("没有相应选项!");
}
getchar();
}while(choice!=0||choice!=9);
}
void bookSearchMainMenu()
{
int choice;
system("cls");
printf("\t\t\t\t\t 1.按书籍名查询 \n");
printf("\t\t\t\t\t 2.按作者名查询 \n");
printf("\t\t\t\t\t 3.按出版社名查询 \n");
printf("\t\t\t\t\t 4.按出版时间查询 \n");
printf("\n");
printf("请选择!\n");
scanf("%d",&choice);
fflush(stdin);
switch(choice)
{
case 1:
bookSearchName();
break;
case 2:
bookSearchWriter();
break;
case 3:
bookSearchPress();
break;
case 4:
bookSearchTime();
break;
default:
printf("没有相应查找方式!\n");
}
getchar();
}
void mainMenu()
{
int choice;
system("cls");
printf("\t\t\t\t\t*************1.管理员**************\n");
printf("\t\t\t\t\t*************2.读者****************\n\n");
printf("\t\t\t\t\t*************0.退出****************\n");
scanf("%d",&choice);
fflush(stdin);
switch(choice)
{
case 1:
if(adminLogin())
adminMenu();
else {
printf("密码或账号错误!按任意键继续!\n");
getchar();
system("cls");
mainMenu();
}
return;
case 2:
userLoginMenu();
break;
case 0:
return;
}
}
void borrowInfoMenu()
{
int choice;
system("cls");
printf("\t\t\t\t\t1.按书名查借书信息\n");
printf("\t\t\t\t\t2.按读者查询借书信息\n");
printf("\t\t\t\t\t3.按作者查询借书信息\n\n");
printf("请选择:\n");
scanf("%d",&choice);
fflush(stdin);
switch(choice)
{
case 1:
borrowSearchBook();
break;
case 2:
borrowSearchReader();
break;
case 3:
borrowSearchWriter();
break;
default:
printf("没有相应的选项\n");
}
}
void returnInfoMenu()
{
int choice;
system("cls");
printf("\t\t\t\t\t1.按书名查询还书信息\n");
printf("\t\t\t\t\t2.按读者查询还书信息\n");
printf("\t\t\t\t\t3.按作者查询还书信息\n\n");
printf("\t\t\t\t\t9.返回上一级\n");
printf("\t\t\t\t\t0.返回主菜单\n");
printf("请选择:\n");
scanf("%d",&choice);
fflush(stdin);
switch(choice)
{
case 1:
returnSearchBook();
getchar();
break;
case 2:
returnSearchReader();
getchar();
break;
case 3:
returnSearchWriter();
getchar();
break;
case 9:
readeradminMenuBR();
return;
case 0:
mainMenu();
return;
default:
printf("没有相应的选项\n");
}
}
void readeruserMenu()
{
int choice;
do
{
system("cls");
printf("\t\t\t\t\t# # # # #1.图书查找# # # # #\n");
printf("\t\t\t\t\t# # # # #2.借书功能# # # # #\n");
printf("\t\t\t\t\t# # # # #3.还书功能# # # # #\n");
printf("\t\t\t\t\t# # # # #4.修改信息# # # # #\n\n");
printf("\t\t\t\t\t*********9.返回上一级*******\n");
printf("请选择:\n");
scanf("%d",&choice);
fflush(stdin);
switch(choice)
{
case 1:
bookSearchMainMenu();
getchar();
break;
case 2:
bookBorrow();
getchar();
break;
case 3:
bookReturn();
getchar();
break;
case 4:
userModify();
getchar();
break;
case 9:
mainMenu();
return;
}
}while(choice!=9);
}
void userLoginMenu()
{
int choice;
system("cls");
printf("\t\t\t\t\t欢迎使用图书图书借阅系统\n\n");
printf("\t\t\t\t\t 1.读者登陆\n");
printf("\t\t\t\t\t 2.读者注册\n\n");
printf("\t\t\t\t\t 0.返回主菜单\n");
printf("请选择:\n");
scanf("%d",&choice);
fflush(stdin);
switch(choice)
{
case 1:
if(readerLogin())
readeruserMenu();
else
getchar();
userLoginMenu();
break;
case 2:
signUp();
getchar();
userLoginMenu();
break;
case 0:
mainMenu();
return ;
}
return ;
}
struct bookInfo *bookSearch(char*isbn)
{
struct bookInfo*current=head->next;
while(current!=NULL)
{
if(strcmp(current->isbn,isbn)==0)
return current;
current=current->next;
}
return NULL;
}
int istime(struct bookInfo*from,char*time)//判断时间是否准确,时间支持三种格式
{
int i=0;
while(i<strlen(time))
{
if(from->time[i]!=time[i])
return 0;
if(from->time[i]==time[i])
i++;
}
if(i==strlen(time))
return 1;
return 0;
}
void bookModifyView(struct bookInfo*current)//检查修改后的信息是否准确
{
if(current!=NULL)
{
printf("编号 书名 作者名 分类号 出版单位 出版时间 库存数量 价格\n\n");
printf("%-15s %-20s %-15s %-8s %-15s %-15s %-10d %-10.3lf\n",current->isbn,current->bookName,current->writer
,current->kind,current->press,current->time,current->amount,current->price);
}
}
void bookInfocpy(struct bookInfo*from,struct bookInfo*to)//信息查询时创建新的链表将信息复制
{
strcpy(to->isbn,from->isbn);
strcpy(to->bookName,from->bookName);
strcpy(to->writer,from->writer);
strcpy(to->kind,from->kind);
strcpy(to->press,from->press);
strcpy(to->time,from->time);
to->amount=from->amount;
to->price=from->price;
}
struct bookInfo*getnode()
{
struct bookInfo*current=(struct bookInfo*)malloc(sizeof(struct bookInfo));
memset(current,0,sizeof(bookInfo));
printf("请输入图书编号:\n");
gets(current->isbn);
fflush(stdin);
printf("请输入图书名称:\n");
gets(current->bookName);
fflush(stdin);
printf("请输入作者姓名:\n");
gets(current->writer);
fflush(stdin);
printf("请输入分类号:\n");
gets(current->kind);
fflush(stdin);
printf("请输入出版单位:\n");
gets(current->press);
fflush(stdin);
printf("请输入出版时间:\n");
gets(current->time);
fflush(stdin);
printf("请输入库存数量:\n");
scanf("%d",¤t->amount);
fflush(stdin);
printf("请输入价格:\n");
scanf("%lf",¤t->price);
fflush(stdin);
return current;
}
void initialSave()//格式化(首次使用)输入信息从而初始化
{
FILE *fp;
bookFree();
head->next=NULL;
struct bookInfo*tail=head;
struct bookInfo*newNode=NULL;
char judege[20];
system("cls");
if ((fp = fopen("bookinformation.txt", "w+"))==NULL)
{
printf("不能打开书目信息文件夹!");
return ;
}
do
{
system("cls");
newNode=getnode();
while(tail->next!=NULL&&strcmp(tail->next->isbn,newNode->isbn)<0)
tail=tail->next;
newNode->next=tail->next;
tail->next=newNode;
printf("按任意键继续,quit退出!");
gets(judege);
fflush(stdin);
}while(strcmp(judege,"quit")!=0);
printf("图书初始化完成!\n");
return ;
}
void downloadBook()//从书籍目录读取书籍信息
{
struct bookInfo*tail=head;
struct bookInfo*current=NULL;
FILE*fp;
if ((fp = fopen("bookinformation.txt", "r+"))==NULL)
printf("不能打开书目信息文件夹!");
else{
while(!feof(fp))
{
current=(struct bookInfo*)malloc(sizeof(bookInfo));
memset(current,0,sizeof(bookInfo));
if(fread(current,sizeof(bookInfo),1,fp)!=0)
{
tail->next=current;
tail=current;
}
else free(current);
}
}
return ;
fclose(fp);
}
void bookSave(struct bookInfo*head)
{
FILE*fp;
struct bookInfo*current=head->next;
struct bookInfo*temp=NULL;
if ((fp = fopen("bookinformation.txt", "w"))==NULL)
{
printf("不能打开书目信息文件夹,书籍信息保存失败!");
return ;
}
while(current!=NULL)
{
fwrite(current,sizeof(bookInfo),1,fp);
current=current->next;
}
fclose(fp);
printf("图书信息保存成功!\n");
}
void bookView(struct bookInfo*head)//浏览全部的图书信息
{
struct bookInfo*current=head->next;
printf("编号 书名 作者名 分类号 出版单位 出版时间 库存数量 价格\n\n");
while(current!=NULL)
{
printf("%-15s %-20s %-15s %-8s %-15s %-15s %-10d %-10.3lf\n",current->isbn,current->bookName,current->writer
,current->kind,current->press,current->time,current->amount,current->price);
current=current->next;
}
return ;
}
void bookInsert()//插入新的书籍
{
struct bookInfo*Newnode=NULL;
struct bookInfo*current=head;
char judege[20];
do{
system("cls");
printf("请输入插入书籍的相关信息:\n");
fflush(stdin);
Newnode=getnode();
while(current->next!=NULL&&strcmp(current->next->isbn,Newnode->isbn)<0)
current=current->next;
Newnode->next=current->next;
current->next=Newnode;
printf("按任意键继续添加书籍,输入quit退出!");
gets(judege);
fflush(stdin);
}while(strcmp(judege,"quit")!=0);
return ;
}
void bookDelete()//当有两个限制条件时,书籍唯一
{
struct bookInfo*current=head;
struct bookInfo*temp=NULL;
char bookName[20],isbn[20],judege[20];
printf("请输入待删除的图书编号:\n");
gets(isbn);
fflush(stdin);
if(current->next==NULL)
printf("书籍目录为空,无法进行删除操作!");
else if((temp=bookSearch(isbn))!=NULL)
{
printf("待删除的信息为:\n");
bookModifyView(temp);
printf("按任意键删除,输入quit退出!\n");
gets(judege);
if(strcmp(judege,"quit")==0)
{
bookadminMenu();
return ;
}
while(current->next!=NULL)
{
if(strcmp(current->next->isbn,isbn)==0)
{
temp=current->next;
current->next=temp->next;
free(temp);
return ;
}
current=current->next;
}
}
}
void modifyMenu()
{
printf("\t\t\t\t\t 1.修改编号\n");
printf("\t\t\t\t\t 2.修改书名\n");
printf("\t\t\t\t\t 3.修改作者名\n");
printf("\t\t\t\t\t 4.修改分类号\n");
printf("\t\t\t\t\t 5.修改出版单位\n");
printf("\t\t\t\t\t 6.修改出版时间\n");
printf("\t\t\t\t\t 7.修改库存数量\n");
printf("\t\t\t\t\t 8.修改价格\n");
}
void bookModify()
{
struct bookInfo*current=NULL;
int choice;
char isbn[20],bookName[20],judege[20],judege2[20];
system("cls");
printf("请输入图书编号:\n");
gets(isbn);
fflush(stdin);
current=bookSearch(isbn);
if(current==NULL)
printf("没有您要修改的的图书!\n");
else
{
printf("待修改的图书信息为:\n");
bookModifyView(current);
printf("按任意键继续,输入quit退出修改!\n");
gets(judege);
fflush(stdin);
if(strcmp(judege,"quit")==0)
return ;
else
{
modifyMenu();
do{
printf("请选择修改项目:\n");
scanf("%d",&choice);
fflush(stdin);
switch(choice)
{
case 1:
printf("请输入修改后的编号:\n");
scanf("%s",¤t->isbn);
fflush(stdin);
break;
case 2:
printf("请输入修改后的书名:\n");
scanf("%s",¤t->bookName);
fflush(stdin);
break;
case 3:
printf("请输入修改后的作者名:\n");
scanf("%s",¤t->writer);
fflush(stdin);
break;
case 4:
printf("请输入修改后的分类号:\n");
scanf("%s",¤t->kind);
fflush(stdin);
break;
case 5:
printf("请输入修改后的出版单位:\n");
scanf("%s",¤t->press);
fflush(stdin);
break;
case 6:
printf("请输入修改后的出版时间:\n");
scanf("%s",¤t->time);
fflush(stdin);
break;
case 7:
printf("请输入修改后的库存数量:\n");
scanf("%d",¤t->amount);
fflush(stdin);
break;
case 8:
printf("请输入修改后的价格:\n");
scanf("%lf",¤t->price);
fflush(stdin);
break;
default:
printf("没有相应的选项!\n");
}
printf("修改后的信息为;\n");
bookModifyView(current);
printf("按任意键继续修改当前书籍,输入quit退出修改!");
gets(judege2);
fflush(stdin);
}while(strcmp(judege2,"quit")!=0);
}
printf("修改完成!\n");
return ;
}
}
void bookSearchName()
{
struct bookInfo*current=head->next;
struct bookInfo*newNode=NULL;
struct bookInfo*bname_head=(struct bookInfo*)malloc(sizeof(bookInfo));
memset(bname_head,0,sizeof(bookInfo));
struct bookInfo*tail=bname_head;
char bname[20];
system("cls");
printf("请输入待查找书籍名称:\n");
gets(bname);
fflush(stdin);
while(current!=NULL)
{
if(strcmp(current->bookName,bname)==0)
{
newNode=(struct bookInfo*)malloc(sizeof(bookInfo));
memset(newNode,0,sizeof(bookInfo));
bookInfocpy(current,newNode);
while(tail->next!=NULL)
tail=tail->next;
tail->next=newNode;
newNode->next=NULL;
}
current=current->next;
}
if(bname_head->next==NULL)
printf("图书馆没有相应图书!\n");
else bookView(bname_head);
return ;
}
void bookSearchWriter()
{
struct bookInfo*current=head->next;
struct bookInfo*newNode=NULL;
struct bookInfo*wname_head=(struct bookInfo*)malloc(sizeof(bookInfo));
memset(wname_head,0,sizeof(bookInfo));
struct bookInfo*tail=wname_head;
char wname[20];
system("cls");
printf("请输入待查找作者名:\n");
gets(wname);
fflush(stdin);
while(current!=NULL)
{
if(strcmp(current->writer,wname)==0)
{
newNode=(struct bookInfo*)malloc(sizeof(bookInfo));
memset(newNode,0,sizeof(bookInfo));
bookInfocpy(current,newNode);
while(tail->next!=NULL)
tail=tail->next;
tail->next=newNode;
newNode->next=NULL;
}
current=current->next;
}
//这部分可以在search函数外面,直接调用这个函数从而查看相关信息
if(wname_head->next==NULL)
printf("图书馆没有相应作者的图书!\n");
else bookView(wname_head);
return ;
}
void bookSearchPress()
{
struct bookInfo*current=head->next;
struct bookInfo*newNode=NULL;
struct bookInfo*pname_head=(struct bookInfo*)malloc(sizeof(bookInfo));
memset(pname_head,0,sizeof(bookInfo));
struct bookInfo*tail=pname_head;
char pname[20];
system("cls");
printf("请输入待查找出版社名:\n");
gets(pname);
fflush(stdin);
while(current!=NULL)
{
if(strcmp(current->press,pname)==0)
{
newNode=(struct bookInfo*)malloc(sizeof(bookInfo));
memset(newNode,0,sizeof(bookInfo));
bookInfocpy(current,newNode);
while(tail->next!=NULL)
tail=tail->next;
tail->next=newNode;
newNode->next=NULL;
}
current=current->next;
}
if(pname_head->next==NULL)