本文實例為大家分享了c/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
|
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <conio.h> #include <windows.h> #define N 100 struct type{ char ISBN[N]; //ISBN編號(一般為13位) char bookName[N]; //書名 char subject[N]; //科目 char editor[N]; //主編 float price; //價格 char publish[N]; //出版社 char date[N]; //日期 int num; //數量 struct type *next; }Book; typedef struct type * BooksManage; void color( short x); //字體顏色 int password(); //管理員密碼 void AdministratorMenu(); //管理員菜單 void VisitorMenu(); //游客菜單 void SaveBooksdata(BooksManage head); //將數據保存到文件中 void AddBooks(BooksManage *head); //添加圖書信息 void ReadBooksdata(BooksManage *head); //將數據從文件中讀取 void DelBooks_Subject(BooksManage head); //按所屬學科刪除圖書信息 void DelBooks_ISBN(BooksManage head); //按ISBN刪除圖書信息 void ModifyBooks(BooksManage head); //修改圖書信息 void FindBooks(BooksManage head); //查詢圖書信息 void PrintBooks(BooksManage head); //顯示所有圖書信息 void SumBooks(BooksManage head); //求全部圖書價值 int main() { color(10); printf ( "\t\t\t\t\t* * * * * * * * * * * * * *\n" ); color(14); printf ( "\t\t\t\t\t* 題目:圖書信息管理系統 *\n" ); color(11); printf ( "\t\t\t\t\t* 班級: *\n" ); color(12); printf ( "\t\t\t\t\t* 組員 *\n" ); color(11); printf ( "\t\t\t\t\t* 姓名 學號 *\n" ); color(10); printf ( "\t\t\t\t\t* 張三 100001 *\n" ); color(11); printf ( "\t\t\t\t\t* 李四 100002 *\n" ); color(14); printf ( "\t\t\t\t\t* 王五 100003 *\n" ); color(12); printf ( "\t\t\t\t\t* 日期 : 2019.03.19 *\n" ); color(10); printf ( "\t\t\t\t\t* * * * * * * * * * * * * *\n" ); system ( "title 圖書信息管理系統" ); color(10); BooksManage head = NULL; ReadBooksdata(&head); int choice,z,c; printf ( "\n\n\n" ); printf ( "\t\t\t※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n" ); printf ( "\t\t\t\t\t\t歡迎光臨圖書信息管理系統\n" ); printf ( "\t\t\t--------------------------------------------------------\n" ); printf ( "\t\t\t\t\t\t【1】游客\n" ); printf ( "\t\t\t\t\t\t【2】管理員\n" ); printf ( "\t\t\t\t\t\t【3】退出系統\n" ); printf ( "\t\t\t--------------------------------------------------------\n" ); while ( printf ( "\t\t\t\t\t\t請選擇身份:" )&& scanf ( "%d" ,&c)!=EOF) { if (c==1) { VisitorMenu(); while ( printf ( "\t\t\t\t\t\t請輸入選擇項(1-3):" )&& scanf ( "%d" ,&choice)!=EOF) { switch (choice) { case 1: /*查詢圖書信息*/ FindBooks(head); break ; case 2: /*顯示所有圖書信息*/ PrintBooks(head); break ; case 3: /*返回登錄界面*/ main(); break ; case 4: exit (0); default : printf ( "\t\t\t\t\t輸入錯誤!!!\n" ); system ( "pause" ); break ; } VisitorMenu(); } } else if (c==2) { z = password(); AdministratorMenu(); while ( printf ( "\t請輸入選擇項(1-8):" ) && z == 1 && scanf ( "%d" ,&choice) != EOF) { switch (choice) { case 1: /*錄入圖書信息*/ AddBooks(&head); break ; case 2: /*刪除圖書信息*/ int sign; system ( "cls" ); color(10); printf ( "\t\t\t* * * * * * * * * * * * * * *\n" ); color(11); printf ( "\t\t\t*---------------------------*\n" ); color(12); printf ( "\t\t\t* 輸入選擇刪除圖書的方式 *\n" ); color(14); printf ( "\t\t\t*---------------------------*\n" ); color(11); printf ( "\t\t\t*【 1】按所屬學科刪除圖書 *\n" ); color(12); printf ( "\t\t\t*---------------------------*\n" ); color(14); printf ( "\t\t\t*【 2】按圖書ISBN號刪除圖書 *\n" ); color(11); printf ( "\t\t\t*---------------------------*\n" ); color(10); printf ( "\t\t\t* * * * * * * * * * * * * * *\n" ); scanf ( "\t\t\t%d" ,&sign); if (sign == 1) DelBooks_Subject(head); else if (sign == 2) DelBooks_ISBN(head); break ; case 3: ModifyBooks(head); break ; case 4: FindBooks(head); break ; case 5: PrintBooks(head); break ; case 6: SumBooks(head); break ; case 7: main(); break ; case 8: SaveBooksdata(head); exit (0); default : printf ( "\t輸入錯誤!!!\n" ); system ( "pause" ); break ; } AdministratorMenu(); } } else if (c==3) exit (0); else { printf ( "\t\t\t輸入錯誤!!!\n\n" ); } } return 0; } /**管理員密碼*/ int password() { int i=0; char user[10]= "admin" ; char Code[10]= "admin" ; char getuser[10]; char Getskey[10]; while (1) { printf ( "\t\t\t請輸入賬號:" ); scanf ( "%s" ,getuser); printf ( "\t\t\t請輸入密碼:" ); while (1) { Getskey[i]=getch(); /*getch()函數在頭文件conio.h中,函數作用為輸入的內容不會在屏幕上顯示*/ if (Getskey[i]== '\r' ) /* \b = 退格鍵(backspace)*/ break ; /* \r = 回車鍵(carrige return)*/ else if (Getskey[i]== '\b' ) { if (i==0) continue ; printf ( "\b" ); printf ( " " ); printf ( "\b" ); i--; } else { printf ( "*" ); i++; } } Getskey[i]= '\0' ; if ( strcmp (user, getuser) == 0 && strcmp (Code, Getskey) == 0){ printf ( "\n\n\n\t\t\t密碼正確,請稍等" ); printf ( "." ); Sleep(300); printf ( "." ); Sleep(300); printf ( "." ); Sleep(300); printf ( "." ); Sleep(300); printf ( "." ); Sleep(300); printf ( "." ); Sleep(300); return 1; } else { printf ( "\n\n\t\t\t賬號不存在或密碼輸入錯誤,請重新輸入\n" ); i = 0; } } } /**管理員菜單*/ void AdministratorMenu() { system ( "cls" ); //清屏 printf ( "\n\n\n\n\n" ); printf ( "\t************************************************************\n" ); printf ( "\t* *\n" ); printf ( "\t* 歡迎來到圖書信息管理系統 *\n" ); printf ( "\t* *\n" ); printf ( "\t* *\n" ); printf ( "\t* 主菜單 *\n" ); printf ( "\t* *\n" ); printf ( "\t* 1.錄入圖書信息 *\n" ); printf ( "\t* *\n" ); printf ( "\t* 2.刪除圖書信息 *\n" ); printf ( "\t* *\n" ); printf ( "\t* 3.修改圖書信息 *\n" ); printf ( "\t* *\n" ); printf ( "\t* 4.查詢圖書信息 *\n" ); printf ( "\t* *\n" ); printf ( "\t* 5.顯示所有圖書信息 *\n" ); printf ( "\t* *\n" ); printf ( "\t* 6.全部圖書的總價值 *\n" ); printf ( "\t* *\n" ); printf ( "\t* 7.返回登錄界面 *\n" ); printf ( "\t* *\n" ); printf ( "\t* 8.保存數據并退出系統 *\n" ); printf ( "\t* *\n" ); printf ( "\t************************************************************\n\n" ); } /**游客菜單*/ void VisitorMenu() { system ( "cls" ); printf ( "\n\n\n\n\n" ); printf ( "\t************************************************************\n" ); printf ( "\t* *\n" ); printf ( "\t* 歡迎來到圖書信息管理系統 *\n" ); printf ( "\t* *\n" ); printf ( "\t* *\n" ); printf ( "\t* 主菜單 *\n" ); printf ( "\t* *\n" ); printf ( "\t* 1.查詢圖書信息 *\n" ); printf ( "\t* *\n" ); printf ( "\t* 2.顯示所有圖書信息 *\n" ); printf ( "\t* *\n" ); printf ( "\t* 3.返回登錄界面 *\n" ); printf ( "\t* *\n" ); printf ( "\t* 4.退出系統 *\n" ); printf ( "\t* *\n" ); printf ( "\t************************************************************\n\n" ); } /*將數據保存到文件中*/ void SaveBooksdata(BooksManage head) { BooksManage p; FILE *fp; fp = fopen ( "BooksDatabase.txt" , "w" ); p = head->next; while (p->next != NULL){ fprintf (fp, "%s\t" ,p->ISBN); fprintf (fp, "%s\t" ,p->bookName); fprintf (fp, "%s\t" ,p->subject); fprintf (fp, "%s\t" ,p->editor); fprintf (fp, "%.2f\t" ,p->price); fprintf (fp, "%s\t" ,p->publish); fprintf (fp, "%s\t" ,p->date); fprintf (fp, "%d\n" ,p->num); p=p->next; } if (p->next == NULL){ fprintf (fp, "%s\t" ,p->ISBN); fprintf (fp, "%s\t" ,p->bookName); fprintf (fp, "%s\t" ,p->subject); fprintf (fp, "%s\t" ,p->editor); fprintf (fp, "%.2f\t" ,p->price); fprintf (fp, "%s\t" ,p->publish); fprintf (fp, "%s\t" ,p->date); fprintf (fp, "%d" ,p->num); } fclose (fp); return ; } /**將數據從文件中讀取*/ void ReadBooksdata(BooksManage *head) { int n; BooksManage s, p; FILE *fp; fp= fopen ( "BooksDatabase.txt" , "r" ); if (NULL == fp) { head = NULL; return ; } *head = (BooksManage) calloc (1, sizeof (Book)); p = *head; while (! feof (fp)) { s = (BooksManage) calloc (1, sizeof (Book)); fscanf (fp, "%s" ,s->ISBN); /*為下個結點分配內存空間 */ fscanf (fp, "%s" ,s->bookName); fscanf (fp, "%s" ,s->subject); fscanf (fp, "%s" ,s->editor); fscanf (fp, "%f" ,&s->price); fscanf (fp, "%s" ,s->publish); fscanf (fp, "%s" ,s->date); fscanf (fp, "%d" ,&s->num); p->next=s; /*保存該結點*/ p=p->next; /*切換到下一個結點*/ p->next=NULL; /*保證最后一個結點為NULL*/ } fclose (fp); /*關閉文件 */ return ; } /**字體顏色*/ void color( short x) { if (x>=0 && x<=15) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), x); else SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7); } /**添加圖書信息*/ void AddBooks(BooksManage *head) { int i; BooksManage p, s; system ( "cls" ); if (*head == NULL) { *head = (BooksManage) calloc (1, sizeof (Book)); p = *head; } else { p = *head; while (p->next) p = p->next; } printf ( "\n\n\n" ); printf ( "\t※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n" ); printf ( "\t\t\t請問添加幾本書:" ); scanf ( "%d" ,&i); printf ( "\t--------------------------------------------------------\n" ); while (i) { s = (BooksManage) calloc (1, sizeof (Book)); printf ( "\t\t\t請輸入ISBN號:" ); scanf ( "%s" ,s->ISBN); printf ( "\t--------------------------------------------------------\n" ); printf ( "\t\t\t請輸入書名:" ); scanf ( "%s" ,s->bookName); printf ( "\t--------------------------------------------------------\n" ); printf ( "\t\t\t請輸入書本的所屬學科:" ); scanf ( "%s" ,s->subject); printf ( "\t--------------------------------------------------------\n" ); printf ( "\t\t\t請輸入主編:" ); scanf ( "%s" ,s->editor); printf ( "\t--------------------------------------------------------\n" ); printf ( "\t\t\t請輸入價格:" ); scanf ( "%f" ,&s->price); printf ( "\t--------------------------------------------------------\n" ); printf ( "\t\t\t請輸入出版社:" ); scanf ( "%s" ,s->publish); printf ( "\t--------------------------------------------------------\n" ); printf ( "\t\t\t請輸入出版日期:" ); scanf ( "%s" ,s->date); printf ( "\t--------------------------------------------------------\n" ); printf ( "\t\t\t請輸入數量:" ); scanf ( "%d" ,&s->num); printf ( "\t--------------------------------------------------------\n" ); printf ( "\n" ); printf ( "\t--------------------------------------------------------\n" ); i--; p->next = s; /*保存輸進去的這個結點*/ p = p->next; /*切換到下一個結點*/ p->next = NULL; /*最后一個結點為NULL*/ } printf ( "\t\t\t圖書添加成功!!!\n" ); system ( "pause" ); } /*按所屬學科刪除圖書信息*/ void DelBooks_Subject(BooksManage head) { system ( "cls" ); int flag=0; char name[100],ch[10]; BooksManage p, t; /**如果表頭為空 */ if (head == NULL || head->next == NULL) { printf ( "沒有記錄圖書信息!\n" ); system ( "pause" ); return ; } p = head; printf ( "\n\n\n" ); printf ( "※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n" ); printf ( "請輸入要刪除的學科名字;" ); scanf ( "%s" ,&name); printf ( "------------------------------------------------------------------------------------\n" ); printf ( "ISBN\t書名\t所屬學科\t主編\t價格\t出版單位\t出版時間\t數量\n" ); printf ( "------------------------------------------------------------------------------------\n" ); while (p->next) { t=p; p=p->next; /*轉換到下一個結點*/ if ( strcmp (name,p->subject)==0) { flag=1; printf ( "%s\t%s\t%s\t\t%s\t%.2f\t%s\t\t%s\t%d\n" ,p->ISBN,p->bookName,p->subject,p->editor,p->price,p->publish,p->date,p->num); break ; } } if (flag==1) { printf ( "是否刪除該本圖書信息(y/n)" ); scanf ( "%s" ,ch); printf ( "----------------------------------------------------------------------\n" ); if ( strcmp (ch, "Y" ) == 0 || strcmp (ch, "y" ) == 0) { t->next = p->next; free (p); printf ( "該書已刪除!\n" ); } else return ; } else if (flag == 0) printf ( "沒找到那本書!\n" ); system ( "pause" ); } /*按ISBN刪除圖書信息*/ void DelBooks_ISBN(BooksManage head) { system ( "cls" ); int flag=0; char ch[10]; char ISBN[N]; BooksManage p, t; /**如果表頭為空 */ if (head == NULL || head->next == NULL) { printf ( "沒有記錄圖書信息!\n" ); system ( "pause" ); return ; } p = head; printf ( "\n\n\n" ); printf ( "※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n" ); printf ( "請輸入要刪除圖書的ISBN號;" ); scanf ( "%s" ,ISBN); printf ( "------------------------------------------------------------------------------------\n" ); printf ( "ISBN\t書名\t所屬學科\t主編\t價格\t出版單位\t出版時間\t數量\n" ); printf ( "------------------------------------------------------------------------------------\n" ); while (p->next) { t=p; p=p->next; /*轉換到下一個結點*/ if ( strcmp (ISBN,p->ISBN)==0) { flag=1; printf ( "%s\t%s\t%s\t\t%s\t%.2f\t%s\t\t%s\t%d\n" ,p->ISBN,p->bookName,p->subject,p->editor,p->price,p->publish,p->date,p->num); break ; } } if (flag==1) { printf ( "是否刪除該本圖書信息(y/n)" ); scanf ( "%s" ,ch); printf ( "----------------------------------------------------------------------\n" ); if ( strcmp (ch, "Y" ) == 0 || strcmp (ch, "y" ) == 0) { t->next = p->next; free (p); printf ( "該書已刪除!\n" ); } else return ; } else if (flag == 0) printf ( "沒找到那本書!\n" ); system ( "pause" ); } /*修改圖書信息*/ void ModifyBooks(BooksManage head) { system ( "cls" ); int flag=0; char name[100],ch[5]; BooksManage p, t; /* 如果表頭為空 */ if (head == NULL || head->next == NULL) { printf ( "沒有記錄圖書信息!\n" ); system ( "pause" ); return ; } p = head; printf ( "\n\n\n" ); printf ( "※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n" ); printf ( "請輸入要修改的書名:" ); scanf ( "%s" ,name); printf ( "--------------------------------------------------------------------\n" ); while (p->next) { p=p->next; /*切換到下一個結點*/ if ( strcmp (name,p->bookName)==0) { flag = 1; t = p; printf ( "ISBN\t書名\t所屬學科\t主編\t價格\t出版單位\t出版時間\t數量\n" ); printf ( "------------------------------------------------------------------------------------\n" ); printf ( "%s\t%s\t%s\t\t%s\t%.2f\t%s\t\t%s\t%d\n" ,p->ISBN,p->bookName,p->subject,p->editor,p->price,p->publish,p->date,p->num); } } if (flag==1) { printf ( "--------------------------------------------------------------------\n" ); printf ( "\t\t是否修改該本圖書信息(y/n):" ); scanf ( "%s" ,ch); printf ( "\t--------------------------------------------------------------------\n" ); if ( strcmp (ch, "Y" )==0|| strcmp (ch, "y" )==0) { int c; printf ( "\t\t【1】ISBN號\n" ); printf ( "--------------------------------------------------------------------\n" ); printf ( "\t\t【2】書名\n" ); printf ( "--------------------------------------------------------------------\n" ); printf ( "\t\t【3】所屬學科\n" ); printf ( "--------------------------------------------------------------------\n" ); printf ( "\t\t【4】主編\n" ); printf ( "--------------------------------------------------------------------\n" ); printf ( "\t\t【5】價格\n" ); printf ( "--------------------------------------------------------------------\n" ); printf ( "\t\t【6】出版社\n" ); printf ( "--------------------------------------------------------------------\n" ); printf ( "\t\t【7】出版日期\n" ); printf ( "--------------------------------------------------------------------\n" ); printf ( "\t\t【8】數量\n" ); printf ( "--------------------------------------------------------------------\n" ); printf ( "\t請輸入你要修改的內容;" ); scanf ( "%d" ,&c); printf ( "--------------------------------------------------------------------\n" ); p = t; switch (c) { case 1: printf ( "\t請輸入ISBN號:" ); scanf ( "%s" ,p->ISBN); break ; case 2: printf ( "\t請輸入書名:" ); scanf ( "%s" ,p->bookName); break ; case 3: printf ( "\t請輸入所屬學科:" ); scanf ( "%s" ,p->subject); break ; case 4: printf ( "\t請輸入主編:" ); scanf ( "%s" ,p->editor); break ; case 5: printf ( "\t請輸入價格:" ); scanf ( "%f" ,&p->price); break ; case 6: printf ( "\t請輸入出版社:" ); scanf ( "%s" ,p->publish); break ; case 7: printf ( "\t請輸入出版日期:" ); scanf ( "%s" ,p->date); break ; case 8: printf ( "\t請輸入數量:" ); scanf ( "%d" ,&p->num); break ; } printf ( "--------------------------------------------------------------------\n" ); printf ( "\t修改成功!!!\n" ); } } else if (flag == 0) printf ( "對不起,該書庫沒有該書\n" ); system ( "pause" ); } /**顯示所有圖書信息*/ void PrintBooks(BooksManage head) { BooksManage p; system ( "cls" ); /**如果表頭為空 */ if (head == NULL || head->next == NULL) { printf ( "沒有記錄圖書信息!\n" ); system ( "pause" ); //提示任意鍵繼續 return ; } p = head->next; printf ( "\n\n\n" ); printf ( "※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n" ); printf ( " 圖書列表\n" ); printf ( "------------------------------------------------------------------------------------\n" ); printf ( "ISBN\t書名\t所屬學科\t主編\t價格\t出版單位\t出版時間\t數量\n" ); printf ( "------------------------------------------------------------------------------------\n" ); do { printf ( "%s\t%s\t%s\t\t%s\t%.2f\t%s\t\t%s\t%d\n" ,p->ISBN,p->bookName,p->subject,p->editor,p->price,p->publish,p->date,p->num); p = p->next; } while (p!=NULL); system ( "pause" ); } /**求全部圖書價值*/ void SumBooks(BooksManage head){ float sum = 0; system ( "cls" ); BooksManage p; /* 如果表頭為空 */ if (head == NULL || head->next == NULL) { printf ( "\t\t\t\t沒有圖書信息!\n" ); return ; } for (p = head;p != NULL; p = p->next){ sum += p->price * p->num; } printf ( "\n\n\n\n\n\n" ); printf ( "\t\t\t***********************************\n" ); color(12); printf ( "\t\t\t* 全部圖書的總價值為:%.2f *\n" ,sum); color(10); printf ( "\t\t\t***********************************\n" ); system ( "pause" ); } /*查詢圖書信息*/ void FindBooks(BooksManage head) { system ( "cls" ); int choose,flag = 0; BooksManage p; char b[100]; char ISBN[N]; /* 如果表頭為空 */ if (head == NULL || head->next == NULL) { printf ( "沒有記錄圖書信息!\n" ); system ( "pause" ); return ; } do { system ( "cls" ); printf ( "\n\n\n" ); printf ( "※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n" ); printf ( "\t\t1.按書名查找\n" ); printf ( "----------------------------------------------------------------------\n" ); printf ( "\t\t2.按ISBN號查找\n" ); printf ( "----------------------------------------------------------------------\n" ); printf ( "\t\t返回主菜單(其他數字)\n" ); printf ( "----------------------------------------------------------------------\n" ); printf ( "\t\t請輸入您的選擇:" ); scanf ( "%d" ,&choose); printf ( "----------------------------------------------------------------------\n" ); p=head; if (choose == 1) { printf ( "輸入所查書名:" ); scanf ( "%s" ,b); printf ( "----------------------------------------------------------------------\n\n" ); while (p->next) { p=p->next; /*轉換到下一個結點*/ if ( strcmp (b,p->bookName)==0) /*判斷是否找到并輸出*/ { flag=1; printf ( "※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n" ); printf ( "ISBN\t書名\t所屬學科\t主編\t價格\t出版單位\t出版時間\t數量\n" ); printf ( "------------------------------------------------------------------------------------\n" ); printf ( "%s\t%s\t%s\t\t%s\t%.2f\t%s\t\t%s\t%d\n" ,p->ISBN,p->bookName,p->subject,p->editor,p->price,p->publish,p->date,p->num); } } if (flag==0) printf ( "不存在該信息\n" ); } else if (choose==2) { printf ( "輸入所查ISBN號:" ); scanf ( "%s" ,ISBN); printf ( "----------------------------------------------------------------------\n\n" ); while (p->next) { p=p->next; /*轉換到下一個結點*/ if ( strcmp (p->ISBN,ISBN) == 0) /*判斷是否找到并輸出*/ { flag=1; printf ( "※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n" ); printf ( "ISBN\t書名\t所屬學科\t主編\t價格\t出版單位\t出版時間\t數量\n" ); printf ( "------------------------------------------------------------------------------------\n" ); printf ( "%s\t%s\t%s\t\t%s\t%.2f\t%s\t\t%s\t%d\n" ,p->ISBN,p->bookName,p->subject,p->editor,p->price,p->publish,p->date,p->num); } } if (flag == 0) printf ( "不存在該信息\n" ); } else return ; system ( "pause" ); } while (1); } |
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:https://blog.csdn.net/qq_21579293/article/details/88886373