本文实例为大家分享了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
|
#include<stdio.h> #include<windows.h> #include<string.h> #include<conio.h> #define N 100 int res = 0; struct Lodginghouse { char Lodginghouse_type[20]; //公寓类型 } Lodginghouse[100]; struct CommonHouse { char building_style[20]; //住宅建筑风格 } CommonHouse[100]; struct Villa { char villa_style[20]; //别墅建筑材料 } villa[100]; struct House { char type[100]; //房屋类型 int number; //房屋编号 // int buildtime; //已经建立多长时间 char sold[100]; //是否售出 int price; //售卖价格 int area; //占地面积(平方米) // int postion; //房屋位置,例如北京三环 // char balcony[20]; //阳台朝向 // int total_floors; //房屋总层数 } house[100]; void main(); void menu(); void input(); void save( int ); void display(); void del(); void add(); void array(); void search(); void search_num(); void search_name(); void yusuan(); void modify(); void start(); /*定义各函数*/ void start() //开始界面 { system ( "cls" ); //清屏 system ( "color 1F" ); //设置文字颜色为黄色 背景色蓝色 printf ( "\n\n\n\n\n\n\n\n\n\n\n\n" ); printf ( "\t\t********************************************************************************\n" ); printf ( "\n\n" ); printf ( "\t\t************************欢迎使用我们的房屋销售管理系统*************************" ); printf ( "\n\n" ); printf ( "\t\t********************************************************************************\n\n\n\n\n" ); printf ( "\t\t\t\t 制作人: \n" ); printf ( "\t\t\t\t XXX XXX XXX\n" ); printf ( "\t\t\t\t XXX XXX \n" ); printf ( "\t\t\t\t XXX XX \n" ); printf ( "\t\t\t\t XX\n" ); printf ( "\t\t\t\t 制作时间: \n" ); printf ( "\t\t\t\t 2018年6月\n" ); printf ( "\t\t\t ***按任意键进入***\n" ); } void menu() //菜单界面 { system ( "cls" ); system ( "color 1F" ); printf ( "\n\n\n\n\n\n\n\n\n\n\n\n" ); printf ( "\t\t\t\t\t************************\n\n" ); printf ( "\t\t\t\t\t**********菜单**********\n\n" ); printf ( "\t\t\t\t\t************************\n\n" ); printf ( ">>>>>>>>>>>>>>>>>>>>>>>>> 1 输入 \n\n" ); printf ( ">>>>>>>>>>>>>>>>>>>>>>>>> 2 显示 \n\n" ); printf ( ">>>>>>>>>>>>>>>>>>>>>>>>> 3 查找 \n\n" ); printf ( ">>>>>>>>>>>>>>>>>>>>>>>>> 4 删除 \n\n" ); printf ( ">>>>>>>>>>>>>>>>>>>>>>>>> 5 添加 \n\n" ); printf ( ">>>>>>>>>>>>>>>>>>>>>>>>> 6 修改 \n\n" ); printf ( ">>>>>>>>>>>>>>>>>>>>>>>>> 7 预算 \n\n" ); printf ( ">>>>>>>>>>>>>>>>>>>>>>>>> 8 排序 \n\n" ); printf ( ">>>>>>>>>>>>>>>>>>>>>>>>> 9 退出 \n\n" ); printf ( "注意:\n" ); printf ( "首次使用该系统,请选择输入选项,且输入选项会覆盖原有信息。" ); } void input() /*录入函数*/ { int i,m; system ( "cls" ); printf ( "需要录入的房屋个数(1--100):\n" ); scanf ( "%d" ,&m); for (i = res; i < m + res; i++) { printf ( "请输入房屋类型(公寓,普通住宅,别墅): " ); scanf ( "%s" ,&house[i].type); printf ( "请输入房屋编号: " ); scanf ( "%d" ,&house[i].number); // printf("请输入已经建立多长时间: "); // scanf("%d",&house[i].buildtime); printf ( "请输入是否售出(是/否): " ); scanf ( "%s" ,&house[i].sold); printf ( "请输入售卖价格: " ); scanf ( "%d" ,&house[i].price); printf ( "请输入占地面积: " ); scanf ( "%d" ,&house[i].area); // printf("请输入房屋位置(例如三环输入3): "); // scanf("%d",&house[i].postion); // printf("请输入阳台朝向(东南西北): "); // scanf("%s",&house[i].balcony); // printf("请输入房屋总层数: "); // scanf("%d",&house[i].total_floors); if ( strcmp (house[i].type, "公寓" ) == 0) { printf ( "请输入公寓类型: " ); scanf ( "%s" ,&Lodginghouse[i].Lodginghouse_type); } else if ( strcmp (house[i].type, "普通住宅" ) == 0) { printf ( "普通住宅建筑风格: " ); scanf ( "%s" ,&CommonHouse[i].building_style); } else { printf ( "请输入别墅建筑材料: " ); scanf ( "%s" ,&villa[i].villa_style); } printf ( "\n" ); } res = i; printf ( "\n创建完毕!\n" ); save(m); //保存房屋总数m } void save( int m) /*保存文件函数*/ { int i, type; FILE *fp1, *fp2, *fp3; //声明fp是指针,用来指向FILE类型的对象 if ((fp1= fopen ( "Lodginghouse" , "wb" ))==NULL) //打开房屋列表文件为空 { printf ( "打开失败\n" ); exit (0); } if ((fp2= fopen ( "Ordinary house" , "wb" ))==NULL) //打开房屋列表文件为空 { printf ( "打开失败\n" ); exit (0); } if ((fp3= fopen ( "Villa" , "wb" ))==NULL) //打开房屋列表文件为空 { printf ( "打开失败\n" ); exit (0); } for (i=0; i<m; i++) /*将内存中房屋的信息输出到磁盘文件中去*/ { if ( strcmp (house[i].type, "公寓" ) == 0) { if ( fwrite (&house[i], sizeof ( struct House),1,fp1)!=1) //写入数据块 &em[i]:是要输出数据的地址 sizeof(struct clerk):获取一个单体的长度 1:数据项的个数 fp:目标文件指针 printf ( "文件读写错误\n" ); if ( fwrite (&Lodginghouse[i], sizeof ( struct Lodginghouse),1,fp1)!=1) printf ( "文件读写错误\n" ); } else if ( strcmp (house[i].type, "普通住宅" ) == 0) { if ( fwrite (&house[i], sizeof ( struct House),1,fp2)!=1) //写入数据块 &em[i]:是要输出数据的地址 sizeof(struct clerk):获取一个单体的长度 1:数据项的个数 fp:目标文件指针 printf ( "文件读写错误\n" ); if ( fwrite (&CommonHouse[i], sizeof ( struct CommonHouse),1,fp2)!=1) printf ( "文件读写错误\n" ); } else { if ( fwrite (&house[i], sizeof ( struct House),1,fp3)!=1) //写入数据块 &em[i]:是要输出数据的地址 sizeof(struct clerk):获取一个单体的长度 1:数据项的个数 fp:目标文件指针 printf ( "文件读写错误\n" ); if ( fwrite (&villa[i], sizeof ( struct Villa),1,fp3)!=1) printf ( "文件读写错误\n" ); } } fclose (fp1); // 缓冲区内最后剩余的数据输出到磁盘文件中,并释放文件指针和有关的缓冲区 fclose (fp2); fclose (fp3); } int load( int type) /*导入函数 int型*/ { int k; FILE *fp; int i=0; if (type == 1) //公寓 { if ((fp= fopen ( "Lodginghouse" , "rb" ))==NULL) { printf ( "cannot open file\n" ); exit (0); } while ( feof (fp)==0) //检测流上的文件结束符 { fread (&house[i], sizeof ( struct House),1,fp); //读取 fread (&Lodginghouse[i], sizeof ( struct Lodginghouse),1,fp); i++; } } else if (type == 2) //普通住宅 { if ((fp= fopen ( "Ordinary house" , "rb" ))==NULL) { printf ( "cannot open file\n" ); exit (0); } while ( feof (fp)==0) { fread (&house[i], sizeof ( struct House),1,fp); //读取 fread (&CommonHouse[i], sizeof ( struct CommonHouse),1,fp); i++; } } else //别墅 { if ((fp= fopen ( "Villa" , "rb" ))==NULL) { printf ( "cannot open file\n" ); exit (0); } while ( feof (fp)==0) { fread (&house[i], sizeof ( struct House),1,fp); //读取 fread (&villa, sizeof ( struct Villa),1,fp); i++; } } fclose (fp); return i - 1; //返回该类房屋个数 } void search() /*查询函数*/ { int t,button; system ( "cls" ); //清屏 do { printf ( "\n按1 查询\n按2 回主菜单\n" ); scanf ( "%d" ,&t); if (t>=1&&t<=2) { button=1; break ; } else { button=0; printf ( "输入错误" ); } } while (button==0); //回到查询选择项 while (button==1) { switch (t) //选择查询方式 { case 1: printf ( "正在查询\n" ); search_num(); break ; case 2: main(); break ; default : break ; } } } void search_num() //按房屋编号查询 { int a, k; int i,t; int m; char s[20]; printf ( "请输入要查询的房屋类型:\n" ); scanf ( "%s" , &s); if ( strcmp (s, "公寓" ) == 0) k=1; else if ( strcmp (s, "普通住宅" ) == 0) k=2; else k=3; m=load(k); printf ( "请输入要查找的房屋编号:\n" ); scanf ( "%d" ,&a); for (i=0; i<m; i++) if (a==house[i].number) { printf ( "房屋类型 房屋编号 是否售出 价格(元) 面积(平方米) 位置(环) 阳台朝向 总层数(层)" ); if (k == 1) printf ( " 公寓类型" ); else if (k == 2) printf ( " 住宅风格" ); else printf ( " 别墅材料" ); printf ( "\n" ); printf ( "\n %-6s %-6d %-8s %-7d" , house[i].type, house[i].number, house[i].sold, house[i].price); printf ( " %-8d " , house[i].area); if (k == 1) printf ( " %s" , Lodginghouse[i].Lodginghouse_type); else if (k == 2) printf ( " %s" , CommonHouse[i].building_style); else printf ( " %s" , villa[i].villa_style); break ; } if (i==m) printf ( "\n没有查询到该房\n" ); printf ( "\n" ); printf ( "返回查询函数请按1,继续查询房屋编号请按2\n" ); scanf ( "%d" ,&t); switch (t) { case 1: search(); break ; case 2: break ; default : break ; } } void display() /*浏览函数*/ { int sold, unsold; sold = 0; //各类房屋已售数量 int i, type; char s[20]; printf ( "请输入要显示的房屋的种类:" ); scanf ( "%s" , &s); if ( strcmp (s, "公寓" ) == 0) type=1; else if ( strcmp (s, "普通住宅" ) == 0) type=2; else type=3; int m=load(type); system ( "cls" ); printf ( "房屋类型 房屋编号 是否售出 价格(元) 面积(平方米) 位置(环) 阳台朝向 总层数(层)" ); if (type == 1) printf ( " 公寓类型" ); else if (type == 2) printf ( " 住宅风格" ); else printf ( " 别墅材料" ); printf ( "\n" ); for (i=0; i<m+res - 1; i++) { if ( strcmp (house[i].sold, "是" ) == 0) sold++; printf ( "\n %-6s %-6d %-8s %-7d" , house[i].type, house[i].number, house[i].sold, house[i].price); printf ( " %-8d " , house[i].area); if (type == 1) printf ( " %s" , Lodginghouse[i].Lodginghouse_type); else if (type == 2) printf ( " %s" , CommonHouse[i].building_style); else printf ( " %s" , villa[i].villa_style); } printf ( "\n该类楼房已售数量为:%d" , sold); printf ( "\n该类楼房未售数量为:%d" , m + res - 1 -sold); } void add() /*添加函数*/ { FILE *fp; int n; int type; int count=0; int i; char s[20]; printf ( "请输入要增添的房屋的种类:" ); scanf ( "%s" , &s); if ( strcmp (s, "公寓" ) == 0) type=1; else if ( strcmp (s, "普通住宅" ) == 0) type=2; else type=3; int m=load(type); printf ( "\n 原来的房屋信息:\n" ); display(); printf ( "\n" ); printf ( "请输入想增加的房屋数:\n" ); //确定要加入的房屋数n scanf ( "%d" ,&n); for (i=m; i<(m+n); i++) //添加n个房屋的信息 { printf ( "请输入房屋类型(公寓,普通住宅,别墅): " ); scanf ( "%s" ,&house[i].type); printf ( "请输入房屋编号: " ); scanf ( "%d" ,&house[i].number); printf ( "请输入是否售出(是/否): " ); scanf ( "%s" ,&house[i].sold); printf ( "请输入售卖价格: " ); scanf ( "%d" ,&house[i].price); printf ( "请输入占地面积: " ); scanf ( "%d" ,&house[i].area); if (type == 1) { printf ( "请输入公寓类型: " ); scanf ( "%s" ,&Lodginghouse[i].Lodginghouse_type); } else if (type == 2) { printf ( "普通住宅建筑风格: " ); scanf ( "%s" ,&CommonHouse[i].building_style); } else { printf ( "请输入别墅建筑材料: " ); scanf ( "%s" ,&villa[i].villa_style); } printf ( "\n" ); count=count+1; printf ( "已增加的房屋数:\n" ); printf ( "%d\n" ,count); } save(m + n); printf ( "\n添加成功\n" ); printf ( "\n增加后的所有房屋信息:\n" ); display(); //显示添加后的信息 } void modify() /*修改函数*/ { int k; char s[100]; char type[100]; int number; char sold[100]; int price; int area; char Lodginghouse_type[100]; char building_style[20]; char villa_style[20]; int b,c,i,n,t,button; printf ( "请输入要修改的房屋所属种类:" ); scanf ( "%s" , &s); if ( strcmp (s, "公寓" ) == 0) k=1; else if ( strcmp (s, "普通住宅" ) == 0) k=2; else k=3; int m=load(k); system ( "cls" ); printf ( "\n 原来的房屋信息:\n" ); display(); printf ( "\n" ); printf ( "请输入要修改的房屋的编号:\n" ); scanf ( "%d" ,&number); for (button=1,i=0; button&&i<m; i++) { if (house[i].number == number) { printf ( "\n该房屋原始记录为:\n" ); printf ( "房屋类型 房屋编号 是否售出 价格(元) 面积(平方米) " ); if (k == 1) printf ( " 公寓类型" ); else if (k == 2) printf ( " 住宅风格" ); else printf ( " 别墅材料" ); printf ( "\n %-6s %-6d %-8s %-7d" , house[i].type, house[i].number, house[i].sold, house[i].price); printf ( " %-8d " , house[i].area); if (k == 1) printf ( " %s" , Lodginghouse[i].Lodginghouse_type); else if (k == 2) printf ( " %s" , CommonHouse[i].building_style); else printf ( " %s" , villa[i].villa_style); printf ( "\n确定 按1 ; 不修改请按0\n" ); scanf ( "%d" ,&n); if (n==1) { printf ( "\n需要进行修改的选项\n 1.房屋类型 2.房屋编号4.是否售出 5.价格 6.面积" ); if (k==1) printf ( "10.公寓类型 " ); else if (k == 2) printf ( "10.住宅风格 " ); else printf ( "10.别墅材料 " ); printf ( "11.返回上层\n" ); printf ( "请选择序号1-11:\n" ); scanf ( "%d" ,&c); if (c>11||c<1) printf ( "\n选择错误,请重新选择!\n" ); } button=0; } } if (button==1) printf ( "\n没有查到该房屋\n" ); do { switch (c) /*因为当找到第i个房屋时,for语句后i自加了1,所以下面的应该把改后的信息赋值给第i-1个*/ { case 1: printf ( "房屋类型改为: " ); scanf ( "%s" ,&type); strcpy (house[i - 1].type,type); break ; case 2: printf ( "房屋编号改为: " ); scanf ( "%d" ,&number); house[i-1].number=number; break ; case 4: printf ( "该房屋是否售出改为: " ); scanf ( "%s" ,&sold); strcpy (house[i-1].sold, sold); break ; case 5: printf ( "房屋价格改为: " ); scanf ( "%d" ,&price); house[i-1].price=price; break ; case 6: printf ( "房屋面积改为:" ); scanf ( "%d" , &area); house[i-1].area=area; break ; case 10: if (k == 1) { printf ( "公寓类型改为:" ); scanf ( "%s" , &Lodginghouse_type); strcpy (Lodginghouse[i-1].Lodginghouse_type, Lodginghouse_type); break ; } else if (k == 2) { printf ( "住宅风格改为:" ); scanf ( "%s" , &building_style); strcpy (CommonHouse[i-1].building_style, building_style); break ; } else { printf ( "别墅建筑材料改为:" ); scanf ( "%s" , &villa_style); strcpy (villa[i-1].villa_style, villa_style); break ; } break ; case 11: modify(); break ; } printf ( "\n" ); printf ( "\n\n 确定修改 请按1 ; 重新修改 请按2: \n" ); scanf ( "%d" ,&b); } while (b==2); printf ( "\n修改后的所有房屋信息:\n" ); printf ( "\n" ); save(m); display(); printf ( "\n按1 继续修改 ,不再修改请按0\n" ); scanf ( "%d" ,&t); switch (t) { case 1: modify(); break ; case 0: break ; default : break ; } } void del() /*删除函数 */ { int type; char s[100]; int i,j,n,t,button; int number; printf ( "请输入需要删除的房屋所属种类:" ); scanf ( "%s" , &s); if ( strcmp (s, "公寓" ) == 0) type=1; else if ( strcmp (s, "普通住宅" ) == 0) type=2; else type=3; int m=load(type); printf ( "\n 原来的房屋信息:\n" ); display(); //显示删除前的房屋信息 printf ( "\n" ); printf ( "请输入需要删除的房屋的编号:\n" ); scanf ( "%d" ,&number); for (button=1,i=0; button&&i<m; i++) //主函数中确定button==1时各函数才可以被调用 { if (house[i].number == number) //按员工姓名查找到某员工 并调出其资料 { printf ( "\n该房屋原始记录为:\n" ); //显示选定员工的信息 printf ( "房屋类型 房屋编号 是否售出 价格(元) 面积(平方米) " ); if (type == 1) printf ( " 公寓类型" ); else if (type == 2) printf ( " 住宅风格" ); else printf ( " 别墅材料" ); printf ( "\n %-6s %-6d %-8d %-8s %-7d" , house[i].type, house[i].number, house[i].sold, house[i].price); printf ( " %-8d " , house[i].area); if (type == 1) printf ( " %s" , Lodginghouse[i].Lodginghouse_type); else if (type == 2) printf ( " %s" , CommonHouse[i].building_style); else printf ( " %s" , villa[i].villa_style); printf ( "\n确定删除 请按1,不删除请按0\n" ); scanf ( "%d" ,&n); if (n==1) { for (j=i; j<m-1; j++) //从第i项开始 将后一项的各值赋给前一项各对应的 完成对第i项的删除 { strcpy (house[j].type,house[j+1].type); house[j].number=house[j+1].number; // house[j].buildtime=house[j+1].buildtime; strcpy (house[j].sold, house[j+1].sold); house[j].price=house[j+1].price; house[j].area=house[j+1].area; //house[j].postion=house[j+1].postion; // strcpy(house[j].balcony, house[j+1].balcony); //house[j].total_floors=house[j+1].total_floors; if (type == 1) strcpy (Lodginghouse[j].Lodginghouse_type, Lodginghouse[j+1].Lodginghouse_type); else if (type == 2) strcpy (CommonHouse[j].building_style, CommonHouse[j+1].building_style); else strcpy (villa[j].villa_style, villa[j+1].villa_style); } button=0; } } } if (!button) //button==0表明删除已完成 m=m-1; //总房屋数减少一人 else printf ( "\n查无此房屋!\n" ); printf ( "\n 删除后的所有房屋信息:\n" ); save(m); //调用保存函数 display(); //调用浏览函数 printf ( "\n继续删除请按1,不再删除请按0\n" ); scanf ( "%d" ,&t); switch (t) { case 1: del(); break ; case 0: break ; default : break ; } } void yusuan() { int i; int type; char s[100]; int ayusuan = 0; //代表预算 printf ( "请输入需要预算的房屋种类:" ); scanf ( "%s" , &s); if ( strcmp (s, "公寓" ) == 0) type=1; else if ( strcmp (s, "普通住宅" ) == 0) type=2; else type=3; int m=load(type); for (i=0; i<m; i++) { ayusuan += house[i].price; } if (type == 1) printf ( "公寓全部卖出的预算为:" ); else if (type == 2) printf ( "普通住宅全部卖出的预算为:" ); else printf ( "别墅全部卖出的预算为:" ); printf ( "%d\n" , ayusuan); } void sort_realw() { int i,j,k,m,l; char s; printf ( "请输入需要排序的房屋所属种类:" ); scanf ( "%s" ,&s); if ( strcmp (s, "公寓" ) == 0) l=1; else if ( strcmp (s, "普通住宅" ) == 0) l=2; else l=3; m=load(k); struct House replace; struct House *p; p=house; for (i=0;i<m-1;i++) { k=i; for (j=i+1;j<m;j++) { if (p[k].price<p[j].price) k=j; replace=house[k]; house[k]=house[i]; house[i]=replace; } } for (i=0;i<m;i++) { printf ( "房间号 面积 价格 类型 销售状态 \n" ); printf ( "\n %-6d %-6d %-8d %-8s %-8s " ,house[i].number,house[i].area,house[i].price,house[i].type,house[i].sold); } } void main() //主函数 { int n, m, button; char a; start(); getch(); menu(); do { printf ( "功能选择(1—9 ):\n" ); scanf ( "%d" ,&n); if (n>=1&&n<=8) { button=1; break ; } else if (n == 9) { exit (0); } else { button=0; printf ( "您输入有误,请重新选择!" ); } } while (button==0); while (button==1) { switch (n) { case 1: input(); break ; case 2: display(); break ; case 3: search(); break ; case 4: del(); break ; case 5: add(); break ; case 6: modify(); break ; case 7: yusuan(); break ; case 8: yusuan(); break ; case 9: exit (0); break ; default : break ; } getchar (); printf ( "\n" ); printf ( "按任意键继续\n" ); getch(); system ( "cls" ); /*清屏*/ menu(); /*调用菜单函数*/ printf ( "功能选择(1--9):\n" ); scanf ( "%d" ,&n); printf ( "\n" ); } } |
注意:计算房屋的总数的时候,一定注意全局变量数值的初始化与更新
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/qq_41179817/article/details/82720554