前言
此系统为博主大一上学期C语言课程设计的大作业,由于当时初步接触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
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
|
#include<stdio.h> #include<stdlib.h> #include<string.h> //------------------------------------------------------结构体区域 typedef struct { char name[20]; //电器名称 char brandName[20]; //品牌名称 int num; //库存数量 int unitPrice; //单价 int year; int month; int day; char manName[20]; }stock; //库存 stock s[10000],t[10000],x[10000],y[10000],in[10000],out[10000],no[10000],no1[10000],no2[10000]; //全局变量 //-------------------------------------------------------函数声明区域 void menu( void ); //主菜单函数 void write( void ); //创建仓库函数 void find( void ); //查询库存函数 void findPart( void ); //部分查询函数 void findOne( void ); //按电器名查询 void findTwo( void ); //按品牌名查询 void findThree( void ); //按提货人查询 void findFour( void ); //按送货人查询 void findFive( void ); //按电器名称大小顺序输出所有库存 void findSix( void ); //按库存数量由高到低输出所有库存 void deposit( void ); //存入仓库函数 void takeout( void ); //取出仓库函数 void tongji( void ); //统计函数 void tongji1( void ); //第一种统计函数 void tongji2( void ); //第二种统计函数 void tongji3( void ); //第三种统计函数 void tongji4( void ); //第四种统计函数 int readFile( void ); //读取库存记录文件中所有结构体的数目 int readFile1( void ); //读取入库记录文件中所有结构体的数目 int readFile2( void ); //读取出库记录文件中所有结构体的数目 void end( void ); //结束退出函数 //-------------------------------------------------------主函数 int main() { menu(); return 0; } void menu( void ) { int n,l=0; printf ( "============================================================\n" ); printf ( " \n" ); printf ( " -----*****欢 迎 使 用 仓 库 物 资 管 理 系 统 ! *****----- \n" ); printf ( " \n" ); printf ( "============================================================\n" ); printf ( " \n" ); printf ( " 您可以进行以下操作: \n" ); printf ( " \n" ); printf ( " 1. 仓库初始化 \n" ); printf ( " \n" ); printf ( " 2. 查询库存 \n" ); printf ( " \n" ); printf ( " 3. 物资存入 \n" ); printf ( " \n" ); printf ( " 4. 物资取出 \n" ); printf ( " \n" ); printf ( " 5. 统计物资 \n" ); printf ( " \n" ); printf ( " 0. 退出系统 \n" ); printf ( " \n" ); printf ( " \n" ); printf ( "============================================================\n" ); printf ( "现在请选择您要进行的操作:(请输入操作前的数字)" ); while ( scanf ( "%d" ,&n)!=EOF) { switch (n) { case 1: system ( "CLS" );write(); break ; case 2: system ( "CLS" );find(); break ; case 3: system ( "CLS" );deposit(); break ; case 4: system ( "CLS" );takeout(); break ; case 5: system ( "CLS" );tongji(); break ; case 0: system ( "CLS" );end(); exit (0); default : printf ( "没有此选项!\n 请重新输入!\n" ); } } } void write( void ) //right { FILE *fp; int i,n; fp= fopen ( "库存记录.dat" , "wb" ); rewind (fp); printf ( "============================================================\n" ); printf ( "请输入仓库中电器信息的组数!\n ps:相同电器但是不同品牌电器算多种!\n" ); scanf ( "%d" ,&n); for (i=0;i<n;i++) { printf ( "开始写入第%d组\n" ,i+1); printf ( "请输入电器名称:" ); scanf ( "%s" ,s[i].name); printf ( "请输入电器品牌名称:" ); scanf ( "%s" ,s[i].brandName); printf ( "请输入电器数量:" ); scanf ( "%d" ,&s[i].num); printf ( "请输入电器单价:" ); scanf ( "%d" ,&s[i].unitPrice); printf ( "请输入存货时间: <年月日之间用空格隔开>例:2016 12 01\n" ); scanf ( "%d%d%d" ,&s[i].year,&s[i].month,&s[i].day); printf ( "请输入存货人:" ); scanf ( "%s" ,s[i].manName); } fwrite (s, sizeof (stock),n,fp); fclose (fp); printf ( "当前库存记录:(请仔细核对)\n" ); for (i=0;i<n;i++) { printf ( "%s\n%s\n%d\n%d\n%d.%d.%d\n%s\n" ,s[i].name,s[i].brandName,s[i].num,s[i].unitPrice,s[i].year,s[i].month,s[i].day,s[i].manName); } printf ( "电器信息写入完成!\n 请按回车键返回主界面!\n" ); getchar (); getchar (); system ( "CLS" ); menu(); } void findOne( void ) { char name[10],ch= 'y' ; int i,k,n,bn; bn=readFile(); do { system ( "CLS" ); printf ( "============================================================\n" ); printf ( "请输入要查询的电器名称:\n" ); getchar (); gets (name); k=-1; for (i=0;i<bn;i++) { if ( strcmp (t[i].name,name)==0) { printf ( "该电器信息如下:\n" ); k=i; printf ( "电器名称:%s,电器品牌:%s,库存数量:%d,电器单价:%d,入库时间:%d.%d.%d,存货人:%s\n" ,t[k].name,t[k].brandName,t[k].num,t[k].unitPrice,t[k].year,t[k].month,t[k].day,t[k].manName); } } if (k==-1) { printf ( "抱歉,本仓库中无此电器!\n" ); } printf ( "\n是否继续查询?<y/n>\n" ); ch= getchar (); } while (ch== 'y' ||ch== 'Y' ); printf ( "将返回上一级菜单!\n 请按回车键确认!\n" ); getchar (); getchar (); system ( "CLS" ); findPart(); } void findTwo( void ) { char brandName[10],ch= 'y' ; int i,k,n,bn; bn=readFile(); do { system ( "CLS" ); printf ( "============================================================\n" ); printf ( "请输入要查询的品牌名称:\n" ); getchar (); gets (brandName); k=-1; for (i=0;i<bn;i++) { if ( strcmp (t[i].brandName,brandName)==0) { printf ( "该电器信息如下:\n" ); k=i; printf ( "电器名称:%s,电器品牌:%s,库存数量:%d,电器单价:%d,入库时间:%d.%d.%d,存货人:%s\n" ,t[k].name,t[k].brandName,t[k].num,t[k].unitPrice,t[k].year,t[k].month,t[k].day,t[k].manName); } } if (k==-1) { printf ( "抱歉,本仓库中无此电器!\n" ); } printf ( "\n是否继续查询?<y/n>\n" ); ch= getchar (); } while (ch== 'y' ||ch== 'Y' ); printf ( "将返回上一级菜单!\n 请按回车键确认!\n" ); getchar (); getchar (); system ( "CLS" ); findPart(); } void findThree( void ) // 按送货人查询 入库 { char manName[10],ch= 'y' ; int i,k,n,bn1; bn1=readFile1(); FILE *fp1; fp1= fopen ( "入库记录.dat" , "rb+" ); if (fp1==NULL) { printf ( "该仓库中未添加任何电器!\n" ); exit (0); } fread (&y, sizeof (stock),bn1,fp1); fclose (fp1); do { system ( "CLS" ); printf ( "============================================================\n" ); printf ( "请输入要查询的存货人:\n" ); getchar (); gets (manName); k=-1; for (i=0;i<bn1;i++) { if ( strcmp (y[i].manName,manName)==0) { printf ( "该电器信息如下:\n" ); k=i; printf ( "电器名称:%s,电器品牌:%s,库存数量:%d,电器单价:%d,入库时间:%d.%d.%d,存货人:%s\n" ,y[k].name,y[k].brandName,y[k].num,y[k].unitPrice,y[k].year,y[k].month,y[k].day,y[k].manName); } } if (k==-1) { printf ( "抱歉,本仓库中无此存货人存入的电器!\n" ); } printf ( "\n是否继续查询?<y/n>\n" ); ch= getchar (); } while (ch== 'y' ||ch== 'Y' ); printf ( "将返回上一级菜单!\n 请按回车键确认!\n" ); getchar (); getchar (); system ( "CLS" ); findPart(); } void findFour( void ) //按提货人查询 出库 { char manName[10],ch= 'y' ; int i,k,n,bn2; bn2=readFile2(); FILE *fp2; fp2= fopen ( "出库记录.dat" , "rb+" ); if (fp2==NULL) { printf ( "该仓库中未提出任何电器!\n" ); exit (0); } fread (&x, sizeof (stock),bn2,fp2); fclose (fp2); do { system ( "CLS" ); printf ( "============================================================\n" ); printf ( "请输入要查询的提货人:\n" ); getchar (); gets (manName); k=-1; for (i=0;i<bn2;i++) { if ( strcmp (x[i].manName,manName)==0) { printf ( "该电器信息如下:\n" ); k=i; printf ( "电器名称:%s,电器品牌:%s,库存数量:%d,电器单价:%d,出库时间:%d.%d.%d,提货人:%s\n" ,x[k].name,x[k].brandName,x[k].num,x[k].unitPrice,x[k].year,x[k].month,x[k].day,x[k].manName); } } if (k==-1) { printf ( "抱歉,本仓库中无此提货人提出的电器!\n" ); } printf ( "\n是否继续查询?<y/n>\n" ); ch= getchar (); } while (ch== 'y' ||ch== 'Y' ); printf ( "将返回上一级菜单!\n 请按回车键确认!\n" ); getchar (); getchar (); system ( "CLS" ); findPart(); } void findFive( void ) //电器名称大小顺序输出所有库存 { int bn; bn=readFile(); printf ( "============================================================\n" ); FILE *fp; fp= fopen ( "库存记录.dat" , "rb+" ); if (fp==NULL) { printf ( "该仓库中无库存!\n" ); exit (0); } fread (&s, sizeof (stock),bn,fp); int i,j; for (i=0;i<bn-1;i++) for (j=0;j<bn-1-i;j++) { if (s[j].name<s[j+1].name) { t[1]=s[j+1]; s[j+1]=s[j]; s[j]=t[1]; } } for (i=0;i<bn;i++) printf ( "%d. 电器名称:%s,电器品牌:%s,库存数量:%d,电器单价:%d,入库时间:%d.%d.%d,存货人:%s\n" ,i+1,s[i].name,s[i].brandName,s[i].num,s[i].unitPrice,s[i].year,s[i].month,s[i].day,s[i].manName); printf ( "\n输出完成!请按回车键返回上一级!\n" ); getchar (); getchar (); system ( "CLS" ); findPart(); } void findSix( void ) //按库存数量由高到低输出所有库存 { int bn; bn=readFile(); printf ( "============================================================\n" ); FILE *fp; fp= fopen ( "库存记录.dat" , "rb+" ); if (fp==NULL) { printf ( "该仓库中无库存!\n" ); exit (0); } fread (&s, sizeof (stock),bn,fp); int i,j; for (i=0;i<bn-1;i++) for (j=0;j<bn-1-i;j++) { if (s[j].num<s[j+1].num) { t[1]=s[j+1]; s[j+1]=s[j]; s[j]=t[1]; } } for (i=0;i<bn;i++) printf ( "%d. 电器名称:%s,电器品牌:%s,库存数量:%d,电器单价:%d,入库时间:%d.%d.%d,存货人:%s\n" ,i+1,s[i].name,s[i].brandName,s[i].num,s[i].unitPrice,s[i].year,s[i].month,s[i].day,s[i].manName); printf ( "\n输出完成!请按回车键返回上一级!\n" ); getchar (); getchar (); system ( "CLS" ); findPart(); } void findPart( void ) { int n; printf ( "============================================================\n" ); printf ( "1. 按电器名查询\n" ); printf ( "2. 按品牌名查询\n" ); printf ( "3. 按送货人查询\n" ); printf ( "4. 按提货人查询\n" ); printf ( "5. 按电器名称由大到小顺序输出所有库存\n" ); printf ( "6. 按库存数量由高到低输出所有库存\n" ); printf ( "0. 返回主菜单\n" ); while ( scanf ( "%d" ,&n)!=EOF) switch (n) { case 1: system ( "CLS" );findOne(); break ; case 2: system ( "CLS" );findTwo(); break ; case 3: system ( "CLS" );findThree(); break ; case 4: system ( "CLS" );findFour(); break ; case 5: system ( "CLS" );findFive(); break ; case 6: system ( "CLS" );findSix(); break ; case 0: system ( "CLS" );menu(); break ; default : printf ( "没有此选项!\n 请重新输入!\n" ); } } void find( void ) { int i,bn; FILE *fp; fp= fopen ( "库存记录.dat" , "rb+" ); if (fp==NULL) { printf ( "该仓库中无库存!\n" ); exit (0); } rewind (fp); bn=readFile(); fread (&t, sizeof (stock),bn,fp); getchar (); findPart(); fclose (fp); } void deposit( void ) //入库 { printf ( "============================================================\n" ); int bn,bn1; stock jia; FILE *fp1,*fp; int i=0,j,n=0; char ch= 'y' ; printf ( "请输入要加入仓库的电器信息:\n" ); do { fp1= fopen ( "入库记录.dat" , "ab+" ); if (fp1==NULL) { printf ( "该仓库中未添加任何电器!\n" ); exit (0); } fp= fopen ( "库存记录.dat" , "ab+" ); bn=readFile(); bn1=readFile1(); printf ( "请输入电器名称:" ); scanf ( "%s" ,jia.name); printf ( "请输入电器品牌:" ); scanf ( "%s" ,jia.brandName); printf ( "请输入电器数量:" ); scanf ( "%d" ,&jia.num); printf ( "请输入电器单价:" ); scanf ( "%d" ,&jia.unitPrice); printf ( "请输入送货时间: <ps: 年月日之间用空格隔开> 例:2016 12 01\n" ); scanf ( "%d%d%d" ,&jia.year,&jia.month,&jia.day); printf ( "请输入送货人:" ); scanf ( "%s" ,jia.manName); fwrite (&jia, sizeof (stock),1,fp1); fwrite (&jia, sizeof (stock),1,fp); fclose (fp1); fclose (fp); printf ( "是否继续输入?<y/n>\n" ); getchar (); ch= getchar (); } while (ch== 'y' ||ch== 'Y' ); printf ( "将返回上一级菜单!\n 请按回车键确认!\n" ); getchar (); system ( "CLS" ); menu(); } void takeout( void ) //出库 { stock jian; printf ( "==============================================================\n" ); int bn,bn2,i,j; char ch= 'y' ; FILE *fp,*fp2; bn=readFile(); bn2=readFile2(); printf ( "请输入要提出仓库的电器信息:\n" ); do { fp= fopen ( "库存记录.dat" , "rb+" ); if (fp==NULL) { printf ( "无法打开此文件!\n" ); exit (0); } for (i=0;i<bn;i++) { fread (&s[i], sizeof (stock),1,fp); } fclose (fp); fp2= fopen ( "出库记录.dat" , "wb+" ); if (fp2==NULL) { printf ( "无法打开此文件!\n" ); exit (0); } printf ( "请输入电器名称:" ); scanf ( "%s" ,jian.name); printf ( "请输入电器品牌:" ); scanf ( "%s" ,jian.brandName); printf ( "请输入电器数量:" ); scanf ( "%d" ,&jian.num); printf ( "请输入电器单价:" ); scanf ( "%d" ,&jian.unitPrice); printf ( "请输入提货时间: <ps: 年月日之间用空格隔开> 例:2016 12 01\n" ); scanf ( "%d%d%d" ,&jian.year,&jian.month,&jian.day); printf ( "请输入提货人:" ); scanf ( "%s" ,jian.manName); getchar (); fwrite (&jian, sizeof (stock),1,fp2); fclose (fp2); for (i=0;i<bn;i++) { if (( strcmp (jian.name,s[i].name)==0)&&( strcmp (jian.brandName,s[i].brandName)==0)) { if (jian.num<=s[i].num) { s[i].num=s[i].num-jian.num; } else { printf ( "库存不足!无法提出!\n" ); printf ( "请按回车键返回!" ); getchar (); system ( "CLS" ); menu(); } } } fopen ( "库存记录.dat" , "wb+" ); for (i=0;i<bn;i++) { fwrite (&s[i], sizeof (stock),1,fp); } fclose (fp); printf ( "\n出库完成! 是否继续输入?<y/n>\n" ); getchar (); ch= getchar (); } while (ch== 'y' ||ch== 'Y' ); printf ( "将返回上一级菜单!\n 请按回车键确认!\n" ); getchar (); system ( "CLS" ); menu(); } void tongji( void ) { int n; system ( "CLS" ); printf ( "==============================================================\n" ); printf ( "1. 入库电器总价值\n" ); printf ( "2. 出库电器总利润\n" ); printf ( "3.统计该月每种电器的出库数目\n" ); printf ( "4.统计该月每种品牌的电器的出库数目\n" ); printf ( "0. 返回主菜单\n" ); printf ( "请选择要进行的操作:(0到4)\n" ); scanf ( "%d" ,&n); getchar (); while (n!=0&&n!=1&&n!=2&&n!=3&&n!=4) { printf ( "没有此选项!\n 请重新输入!\n" ); scanf ( "%d" ,&n); getchar (); } switch (n) { case 1:tongji3(); break ; //第三种统计函数 case 2:tongji4(); break ; //第四种统计函数 case 3:tongji1(); break ; //第一种统计函数 case 4:tongji2(); break ; //第二种统计函数 case 0: system ( "CLS" );menu(); break ; } } void tongji2( void ) //第二种统计函数 { FILE *fp; int bn1,i,year,month,k=0; bn1=readFile1(); system ( "CLS" ); printf ( "==============================================================\n" ); fp= fopen ( "出库记录.dat" , "rb+" ); if (fp==NULL) { printf ( "无法打开此文件!\n" ); exit (0); } for (i=0;i<bn1;i++) { fread (&s, sizeof (stock),bn1,fp); } printf ( "请输入一个日期(年 月 如 2017 01):\n" ); scanf ( "%d%d" ,&year,&month); for (i=0;i<bn1;i++) { if ((s[i].year==year)&&(s[i].month==month)) { printf ( "电器名称:%s\n品牌名称:%s\n出库数目:%d\n" ,s[i].name,s[i].brandName,s[i].num); k+=1; } } if (k==0) printf ( "库存记录中不存在此种电器!\n" ); fclose (fp); printf ( "统计完成,请按回车键返回!\n" ); getchar (); getchar (); system ( "CLS" ); tongji(); } void tongji1( void ) //第一种统计函数 { FILE *fp; int bn1,i,year,month,k=0; bn1=readFile1(); system ( "CLS" ); printf ( "==============================================================\n" ); fp= fopen ( "出库记录.dat" , "rb+" ); if (fp==NULL) { printf ( "无法打开此文件!\n" ); exit (0); } for (i=0;i<bn1;i++) { fread (&s, sizeof (stock),bn1,fp); } printf ( "请输入一个日期(年 月 如 2017 01 ):\n" ); scanf ( "%d%d" ,&year,&month); for (i=0;i<bn1;i++) { if ((s[i].year==year)&&(s[i].month==month)) { printf ( "电器名称:%s\n出库数目:%d\n" ,s[i].name,s[i].num); k+=1; } } if (k==0) printf ( "库存记录中不存在此种电器!\n" ); fclose (fp); printf ( "统计完成,请按回车键返回!\n" ); getchar (); getchar (); system ( "CLS" ); tongji(); } void tongji3( void ) //第三种统计函数 { FILE *fp; int bn1,i; long long int total=0; bn1=readFile1(); system ( "CLS" ); printf ( "==============================================================\n" ); fp= fopen ( "入库记录.dat" , "rb+" ); if (fp==NULL) { printf ( "无法打开此文件!\n" ); exit (0); } for (i=0;i<bn1;i++) { fread (&s[i], sizeof (stock),1,fp); } fclose (fp); for (i=0;i<bn1;i++) { total+=(s[i].num*s[i].unitPrice); } printf ( "商品总价值为%d\n" ,total); printf ( "统计完成,请按回车键返回!\n" ); getchar (); system ( "CLS" ); tongji(); } void tongji4( void ) //第四种统计函数 { FILE *fp1,*fp2; int bn,bn2,i; long long int money=0; bn=readFile(); bn2=readFile2(); system ( "CLS" ); printf ( "==============================================================\n" ); fp1= fopen ( "库存记录.dat" , "rb+" ); if (fp1==NULL) { printf ( "无法打开此文件!\n" ); exit (0); } for (i=0;i<bn;i++) { fread (&s[i], sizeof (stock),1,fp1); } fclose (fp1); fp2= fopen ( "出库记录.dat" , "rb+" ); if (fp2==NULL) { printf ( "无法打开此文件!\n" ); exit (0); } for (i=0;i<bn2;i++) { fread (&t[i], sizeof (stock),1,fp2); } fclose (fp2); for (i=0;i<bn2;i++) { money+=((t[i].unitPrice-s[i].unitPrice)*t[i].num); } printf ( "总利润为%d\n" ,money); printf ( "统计完成,请按回车键返回!\n" ); getchar (); system ( "CLS" ); tongji(); } void end( void ) { printf ( "==============================================================\n" ); printf ( " \n" ); printf ( " \n" ); printf ( " \n" ); printf ( " 感 谢 使 用 本 系 统 ! \n" ); printf ( " \n" ); printf ( " 再 见 ! \n" ); printf ( " \n" ); printf ( " \n" ); printf ( " \n" ); printf ( " \n" ); printf ( "==============================================================\n" ); } int readFile( void ) //库存记录文件中结构体的个数 { FILE *fb; int bn=0; fb= fopen ( "库存记录.dat" , "rb+" ); if (fb==NULL) { return bn; } while (! feof (fb)) { if ( fread (&no[bn], sizeof (stock),1,fb)) bn++; } fclose (fb); return bn; } int readFile1( void ) //入库记录文件中结构体的个数 { FILE *fb; int bn1=0; fb= fopen ( "入库记录.dat" , "rb+" ); if (fb==NULL) { return bn1; } while (! feof (fb)) { if ( fread (&no1[bn1], sizeof (stock),1,fb)) bn1++; } fclose (fb); return bn1; } int readFile2( void ) //出库记录文件中结构体的个数 { FILE *fb; int bn2=0; fb= fopen ( "出库记录.dat" , "rb+" ); if (fb==NULL) { return bn2; } while (! feof (fb)) { if ( fread (&no2[bn2], sizeof (stock),1,fb)) bn2++; } fclose (fb); return bn2; } |
运行截图
总结
两年前写的程序了,大体运行了一下,存在一点小bug,还有一些设计不合理的地方以及没有解决非法输入的问题。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/qq_42254342/article/details/102616853