C语言实现车辆出租管理系统

IT教程2年前 (2022)发布 tang
309 0 0
马哥源码

马哥资源网
这篇文章主要为大家详细介绍了C语言实现车辆出租管理系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

这个项目是我今年的C语言课设。做这个项目一个人大概用了一天的时间来完成,整体将近700行,量不是很多,所以也没用多文件什么的,当然也是采用了模块化设计的思路,在代码中写了几个函数来实现特定的功能。

以下是这个项目的一些要求和全部源码。

一、软件开发目的

该软件主要是使用C语言设计开发一个简单的车辆租赁管理系统,实现租赁信息的查询、修改、删除、添加以及订单的查询等功能。

二、数据结构

程序中采用结构体数组存储租赁信息。租赁结构体成员包括:订单号、身份证号、车牌号、费用。数组的长度不超过100。

三、软件功能说明

1.租赁信息的录入和保存:

输入租赁信息包括:订单号、身份证号、车牌号、费用。还车前费用为0。在录入数据的同时,系统将对信息的合法性进行检验,若录入了不合法的数据系统应作出提示,并且要求重新输入。

2.显示单条租赁信息:

将租赁信息在屏幕上列表输出。要求先显示提示信息“订单号、身份证号、车牌号、费用”,然后再显示租赁信息,每行显示一条租赁信息。

3.查询单条租赁信息

输入身份证号进行查询,输出符合条件的租赁信息,输出订单号、身份证号、车牌号、费用。

4.查询每辆车的租赁费用:

输入车牌号进行查询,输出该车所有租赁的总费用。输出车牌号、总费用。

5.添加租赁信息

输入新的租赁信息,将新的信息插入原租赁信息清单中,并将新的列表输出,以方便用户确认。

6.修改、删除租赁信息

通过身份证号对某条租赁信息进行进行修改和删除,并将租赁信息列表输出,以方便用户确认。

7.统计:

(1)统计输出当月订单总金额
(2)统计输出订单金额最高的车牌号

8.退出系统,结束任务。

以下是该程序的全部代码

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
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
#include<conio.h>
#include<string.h>
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
int loop = 0;
int menu();
int menu_2();
int menu_3();
void gotoxy();
void HideCursor();
void InsertInformation();
void PrintInformation();
void IdSearch();
void PlateNumber();
void ExitSystem();
void ReviseInformation();
void DeleteInformation();
void AddInformation();
void MoneySum();
void ChampionCar();
struct information{
 int theOrderNumber;
 char IdNumber[20];
 char PlateNumber[10];
 double Cost;
}car[999999];
int key;
int main(){
 HideCursor();
 menu();
 key = menu();
 switch(key){
 case 1:
  InsertInformation();
  break;
 case 2:
  PrintInformation();
  break;
 case 3:
  menu_2();
  switch(menu_2()){
  case 1:
   MoneySum();
   break;
  case 2:
   ChampionCar();
   break;
  case 3:
   system("cls");
   main();
   break;
  case 4:
   ExitSystem();
   break;
  }
  break;
 case 4:
  ReviseInformation();
  break;
 case 5:
  DeleteInformation();
  break;
 case 6:
  AddInformation();
  break;
 case 7:
  menu_3();
  switch(menu_3()){
  case 1:
   MoneySum();
   break;
  case 2:
   ChampionCar();
   break;
  case 3:
   system("cls");
   main();
   break;
  case 4:
   ExitSystem();
   break;
  }
  break;
 case 8:
  ExitSystem();
  break;
 }
 return 0;
}
void gotoxy(short x, short y) {
 COORD coord = { x,y };/*定义结构体变量coord*/
 SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
void HideCursor() {
 CONSOLE_CURSOR_INFO cursor_info = { 1,0 };
 SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
}
int menu(void){
 int i,choose;
 gotoxy(50,5);
 for(i = 0;i < 20 ; i++){
 printf("-");
 }
 for(i = 0;i <5; i++){
 gotoxy(49 - 2 * i,6 + i);
 printf("/");
 }
 for(i = 0;i < 50;i++){
 gotoxy(25+i,10);
 printf("-");
 }
 for(i = 0;i < 5;i++){
 gotoxy(25,11+i);
 printf("|");
 }
 gotoxy(35,13);
 printf("欢迎使用汽车租赁管理系统");
 gotoxy(40,15);
 printf("[1]信息录入");
 gotoxy(40,16);
 printf("[2]信息显示");
 gotoxy(40,17);
 printf("[3]查询信息");
 gotoxy(40,18);
 printf("[4]修改信息");
 gotoxy(40,19);
 printf("[5]删除信息");
 gotoxy(40,20);
 printf("[6]追加信息");
 gotoxy(40,21);
 printf("[7]统计信息");
 gotoxy(40,22);
 printf("[8]退出");
 gotoxy(40,26);
 printf("Zenith 版权所有");
 gotoxy(40,23);
 printf("请选择(1-8):");
 scanf("%d",&choose);
 while(choose<1 || choose>8){
 printf("请输入范围为1-8的整数");
 gotoxy(40,23);
 printf("请选择(1-8):");
 scanf("%d",&choose);
 }
 return choose;
}
int menu_2(void){
 system("cls");
 int i,choose;
 gotoxy(50,5);
 for(i = 0;i < 20 ; i++){
 printf("-");
 }
 for(i = 0;i <5; i++){
 gotoxy(49 - 2 * i,6 + i);
 printf("/");
 }
 for(i = 0;i < 50;i++){
 gotoxy(25+i,10);
 printf("-");
 }
 for(i = 0;i < 5;i++){
 gotoxy(25,11+i);
 printf("|");
 }
 gotoxy(35,13);
 printf("欢迎使用汽车租赁管理系统");
 gotoxy(40,15);
 printf("[1]按照身份证号检索");
 gotoxy(40,16);
 printf("[2]按照车牌号检索");
 gotoxy(40,17);
 printf("[3]返回主菜单");
 gotoxy(40,18);
 printf("[4]退出系统");
 gotoxy(40,26);
 printf("Zenith 版权所有");
 gotoxy(40,23);
 printf("请选择(1-4):");
 scanf("%d",&choose);
 while(choose<1 || choose>8){
 printf("请输入范围为1-4的整数");
 gotoxy(40,23);
 printf("请选择(1-4):");
 scanf("%d",&choose);
 }
 return choose;
}
int menu_3(void){
 system("cls");
 int i,choose;
 gotoxy(50,5);
 for(i = 0;i < 20 ; i++){
 printf("-");
 }
 for(i = 0;i <5; i++){
 gotoxy(49 - 2 * i,6 + i);
 printf("/");
 }
 for(i = 0;i < 50;i++){
 gotoxy(25+i,10);
 printf("-");
 }
 for(i = 0;i < 5;i++){
 gotoxy(25,11+i);
 printf("|");
 }
 gotoxy(35,13);
 printf("欢迎使用汽车租赁管理系统");
 gotoxy(40,15);
 printf("[1]查看车辆总收入");
 gotoxy(40,16);
 printf("[2]查看盈利冠军车辆");
 gotoxy(40,17);
 printf("[3]返回主菜单");
 gotoxy(40,18);
 printf("[4]退出系统");
 gotoxy(40,26);
 printf("Zenith 版权所有");
 gotoxy(40,23);
 printf("请选择(1-4):");
 scanf("%d",&choose);
 while(choose<1 || choose>8){
 printf("请输入范围为1-4的整数");
 gotoxy(40,23);
 printf("请选择(1-4):");
 scanf("%d",&choose);
 }
 return choose;
}
void InsertInformation(){
 system("cls");
 int a,k,j,x,one;
 double cost;
 int i = 0;
 do{
 printf("\n----------------------------------------------------\n");
 printf("\t ———信息录入———\n\n");
 fflush(stdin);     //清空缓冲区
 printf("请输入订单号(1-999999):");
 scanf("%d", &x);
 while( x<1 || x>100){
  printf("订单号范围为1~100:");
  scanf("%d", &x);
 }
 one=0;
 for(j=0;j < loop;j++){
  if(x==car[j].theOrderNumber){
  one=1;
  printf("\n记录中已有!不得重复添加...");
  getch();
  system("cls");
  menu();
  }
 }
 if(one==0){
  car[loop].theOrderNumber = x;
 }
 printf("请输入身份证号:");
 getchar();
 gets(car[loop].IdNumber);
 printf("请输入车牌号:");
 scanf("%s",&car[loop].PlateNumber);
 printf("请输入费用:");
 scanf("%lf", &cost);
 car[loop].Cost = cost;
 loop++;
 printf("\n添加完毕! 目前共有%d辆车!\n按1回到主界面!按2继续添加信息!按其他键退出程序! ",loop);
 scanf("%d", &a);
 }while(a==2);
 if (a == 1){
 system("cls");
 main();
 }
 if (a != 1){
 ExitSystem();
 }
}
void PrintInformation(){
 system("cls");
 int a,j;
 printf("\n----------------------------------------------------\n");
 printf("\t ———信息显示———\n\n");
 if(loop == 0){
 printf("Error,无数据,请添加数据后再试\n");
 }
 else{
 gotoxy(3,5);
 printf("订单号");
 gotoxy(10,5);
 printf("身份证号");
 gotoxy(32,5);
 printf("车牌号");
 gotoxy(45,5);
 printf("费用");
 for(j = 0;j < loop;j++ ){
  gotoxy(3,7+j);
  printf("%d",car[j].theOrderNumber);
  gotoxy(10,7+j);
  printf("%s",car[j].IdNumber);
  gotoxy(32,7+j);
  printf("%s",car[j].PlateNumber);
  gotoxy(45,7+j);
  printf("%f",car[j].Cost);
 }
 }
 printf("\n显示完毕! 目前共有%d辆车!\n按1回到主界面!按其他键退出程序! ",loop);
 scanf("%d", &a);
 if (a == 1){
 system("cls");
 main();
 }
 if (a != 1){
 ExitSystem();
 }
}
void IdSearch(){
 char idnumber[20];
 int i,j,a;
 do{
 system("cls");
 printf("\n----------------------------------------------------\n");
 printf("\t ———查询(按照身份证号)———\n\n");
 if(loop == 0){
  gotoxy(3,5);
  printf("无数据,请录入数据后查询,输入任意键返回主菜单");
  getch();
  system("cls");
  main();
 }
 gotoxy(3,5);
 printf("请输入需要查询的身份证号:");
 scanf("%s",&idnumber);
 j = 0;
 for(i=0;i < loop;i++){
  if(strcmp(idnumber,car[i].IdNumber) == 0){
  j=1;
  gotoxy(3,7);
  printf("订单号");
  gotoxy(10,7);
  printf("身份证号");
  gotoxy(32,7);
  printf("车牌号");
  gotoxy(45,7);
  printf("费用");
  gotoxy(3,9);
  printf("%d",car[i].theOrderNumber);
  gotoxy(10,9);
  printf("%s",car[i].IdNumber);
  gotoxy(32,9);
  printf("%s",car[i].PlateNumber);
  gotoxy(45,9);
  printf("%f",car[i].Cost);
  break;
  }
  if(j == 0){
  gotoxy(3,7);
  printf("对不起,未查询到您输入的身份证号,请核实后重新输入");
  break;
  }
 }
 gotoxy(3,11);
 printf("查询完成,输入1继续查询,输入2返回主菜单,按其他键退出程序!");
 scanf("%d",&a);
 }while(a == 1);
 if (a == 2){
 system("cls");
 main();
 }
 if (a != 1){
 ExitSystem();
 }
}
void PlateNumber(){
 char platenumber[10];
 int i,j,a;
 do{
 system("cls");
 printf("\n----------------------------------------------------\n");
 printf("\t ———查询(按照车牌号)———\n\n");
 if(loop == 0){
  gotoxy(3,5);
  printf("无数据,请录入数据后查询,输入任意键返回主菜单");
  getch();
  system("cls");
  main();
 }
 gotoxy(3,5);
 printf("请输入需要查询的车牌号:");
 scanf("%s",&platenumber);
 j = 0;
 for(i=0;i < loop;i++){
  if(strcmp(platenumber,car[i].PlateNumber) == 0){
  j=1;
  gotoxy(3,7);
  printf("订单号");
  gotoxy(10,7);
  printf("身份证号");
  gotoxy(32,7);
  printf("车牌号");
  gotoxy(45,7);
  printf("费用");
  gotoxy(3,9);
  printf("%d",car[i].theOrderNumber);
  gotoxy(10,9);
  printf("%s",car[i].IdNumber);
  gotoxy(32,9);
  printf("%s",car[i].PlateNumber);
  gotoxy(45,9);
  printf("%f",car[i].Cost);
  break;
  }
  if(j == 0){
  gotoxy(3,7);
  printf("对不起,未查询到您输入的车牌号,请核实后重新输入");
  break;
  }
 }
 gotoxy(3,11);
 printf("查询完成,输入1继续查询,输入2返回主菜单,按其他键退出程序!");
 scanf("%d",&a);
 }while(a == 1);
 if (a == 2){
 system("cls");
 main();
 }
 if (a != 1){
 ExitSystem();
 }
}
void ReviseInformation(){
 char idnumber[20];
 int i,j,a,b,c,cost;
 do{
 system("cls");
 printf("\n----------------------------------------------------\n");
 printf("\t ———信息修改———\n\n");
 if(loop == 0){
  gotoxy(3,5);
  printf("无数据,请录入数据后查询,输入任意键返回主菜单");
  getch();
  system("cls");
  main();
 }
 gotoxy(3,5);
 printf("请输入需要修改的信息的身份证号:");
 scanf("%s",&idnumber);
 j = 0;
 for(i=0;i < loop;i++){
  if(strcmp(idnumber,car[i].IdNumber) == 0){
  j=1;
  do{
   system("cls");
   printf("\n----------------------------------------------------\n");
   gotoxy(3,6);
   printf("您想要修改的条目如下");
   gotoxy(3,7);
   printf("订单号");
   gotoxy(10,7);
   printf("身份证号");
   gotoxy(32,7);
   printf("车牌号");
   gotoxy(45,7);
   printf("费用");
   gotoxy(3,9);
   printf("%d",car[i].theOrderNumber);
   gotoxy(10,9);
   printf("%s",car[i].IdNumber);
   gotoxy(32,9);
   printf("%s",car[i].PlateNumber);
   gotoxy(45,9);
   printf("%f",car[i].Cost);
   printf("\n\n\t ———信息修改———\n\n");
   printf("请选择需要修改的项目\n");
   printf("\t[1]身份证号\n");
   printf("\t[2]车牌号\n");
   printf("\t[3]费用\n");
   scanf("%d",&b);
   switch(b){
   case 1:
    printf("\n请输入身份证号:");
    getchar();
    gets(car[i].IdNumber);
    break;
   case 2:
    printf("\n请输入车牌号:");
    scanf("%s",&car[i].PlateNumber);
    break;
   case 3:
    printf("请输入费用:");
    scanf("%lf", &cost);
    car[i].Cost = cost;
    break;
   }
   printf("修改完成,输入1继续修改,输入其他键结束对此条目的修改");
   scanf("%d",&c);
  }while(c == 1);
  break;
  }
  if(j == 0){
  gotoxy(3,7);
  printf("对不起,未查询到您输入的身份证号,请核实后重新输入");
  break;
  }
 }
 gotoxy(3,15);
 printf("输入1继续修改其他条目,输入2返回主菜单,按其他键退出程序!");
 scanf("%d",&a);
 }while(a == 1);
 if (a == 2){
 system("cls");
 main();
 }
 if (a != 1){
 ExitSystem();
 }
}
void DeleteInformation(){
 int j,x,k;
 char idnumber[20];
 system("cls");
 printf("\n----------------------------------------------------\n");
 printf("\t ———信息删除———\n\n");
 printf("\t 请输入需要删除的条目的身份证号:");
 scanf("%s",idnumber);
 k=0;
 for(j=0;j <= loop;j++){
 if(strcmp(idnumber,car[j].IdNumber)==0){
  k=1;
  for( x = j; x<=loop ; x++){
  car[x]=car[x+1];
  }
  loop--;
  printf("\n\t 删除成功!");
  break;
 }
 }
 if(k==0){
 printf("\t 对不起,记录中没有此条目...");
 printf("输入任意键退出");
 getch();
 system("cls");
 main();
 }
 printf("输入任意键退出");
 getch();
 system("cls");
 main();
}
void AddInformation(){
 int i,x,j,one,row;
 double cost;
 loop++;
 system("cls");
 printf("\n----------------------------------------------------\n");
 printf("\t ———信息追加———\n\n");
 gotoxy(3,5);
 if(loop == 1){
 printf("请在录入信息后选择此功能,按任意键退出!");
 getch();
 loop--;
 system("cls");
 main();
 }
 printf("请输入在第几行增添数据");
 scanf("%d",&row);
 if(row >= loop){
 do{
  printf("输入的行数必须小于已有的条目数!请重新输入:");
  scanf("%d",&row);
 }while(row<=loop);
 }
 for(i = loop;i >= row;i--){
 car[i] = car[i - 1];
 }
 printf("请输入订单号(1-100):");
 scanf("%d", &x);
 while( x<1 || x>100){
 printf("订单号范围为1~100:");
 scanf("%d", &x);
 }
 one=0;
 for(j=0;j < loop;j++){
 if(x==car[j].theOrderNumber){
  one=1;
  printf("\n记录中已有!不得重复添加...");
  getch();
  system("cls");
  main();
 }
 }
 if(one==0){
 car[row].theOrderNumber = x;
 }
 printf("请输入身份证号:");
 getchar();
 gets(car[row].IdNumber);
 printf("请输入车牌号:");
 scanf("%s",&car[row].PlateNumber);
 printf("请输入费用:");
 scanf("%lf", &cost);
 car[row].Cost = cost;
 printf("\n\t追加完成,请按任意键返回主菜单");
 getch();
 system("cls");
 main();
}
void MoneySum(){
 int i;
 double sum = 0;
 system("cls");
 printf("\n----------------------------------------------------\n");
 printf("\t ———信息统计(车辆总收入)———\n\n");
 for(i = 0;i <= loop ; i++){
 sum = sum + car[i].Cost;
 }
 gotoxy(3,5);
 printf("截至目前所有车辆总收入为%lf",sum);
 gotoxy(3,6);
 printf("按任意键返回主菜单");
 getch();
 system("cls");
 main();
}
void ChampionCar(){
 int i,j;
 double high = 0;
 system("cls");
 printf("\n----------------------------------------------------\n");
 printf("\t ———信息统计(盈利冠军车辆)———\n\n");
 for(i = 0;i < loop;i++){
 if(car[i].Cost >= high){
  high = car[i].Cost;
  j = i;
 }
 }
 gotoxy(3,5);
 printf("截止目前盈利冠军车辆为收入%lf元的%s",high,car[j].PlateNumber);
 gotoxy(3,6);
 printf("按任意键返回主菜单");
 getch();
 system("cls");
 main();
}
void ExitSystem(){
 system("cls");
 printf("\n退出系统中...");
 Sleep(1000);
 exit(0);
}
© 版权声明

相关文章

暂无评论

暂无评论...