服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - C/C++ - C语言实现单位车辆调度管理

C语言实现单位车辆调度管理

2022-10-20 13:30凡人的世界 C/C++

这篇文章主要为大家详细介绍了C语言实现单位车辆调度管理,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了C语言实现单位车辆调度管理的具体代码,供大家参考,具体内容如下

单位车辆信息包括:车牌号、车型、载重(客)量,车牌,生产厂家,出厂日期,购买日期,购买单价等;车辆调度信息还应包括:用车人,用车单位,调度人,出车车牌,出车司机,出车用途,出车日期,出车时间,收车日期,收车时间及出车费用等信息等。设计“车辆调度管理系统”,使之能提供以下功能:

系统以菜单方式工作;

车辆调度信息录入功能(车辆调度信息用文件vehicle.txt保存);

车辆信息及车辆调度信息浏览功能;

车辆调度查询和排序功能: 

车辆信息及车辆调度信息的删除与修改等功能。

代码如下,完全原创,代码功能完整!!

?
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
 
int feature;//定义输入的功能选项
char now_date[12];//定义系统当前日期存储缓冲区
SYSTEMTIME sys; //定义系统时间变量
 
//定义车辆数据结构
typedef struct Vehicle
{
    char *ver_id;//定义车辆编号
    char *ver_no;//定义车辆牌号
    char *weight;//定义车辆对应载重量
    char *ver_trand;//定义车牌
    char *factory;//定义车辆生产厂家
    char *outdate;//定义车辆出厂日期
    char *buydate;//定义车辆购买日期
    char *section;//定义车辆调用单位
    char *purpose;//定义车辆出车用途
    char *usedate;//定义车辆出车日期
    char *usetime;//定义车辆调度时长
    char *useprice;//定义车辆出车费用
    char *price;//定义车辆购买单价
    char *ver_type;//定义车辆类型
    char *ver_status;//定义车辆状态
    char *state;//定义车辆运营状态
    char *service;//定义车辆维修情况
    char *violation;//定义车辆违章情况
    char *ver_last_date;//定义车辆归还日期
    char *lender_name;//定义租车人姓名
    char *lender_id;//定义租车人身份证号码
    char *return_time;//定义归还时间
}Vehicle,*VData;
 
//定义车辆链表
typedef struct VNode
{
    Vehicle data;
    struct VNode *next;
}VNode,*VehicleList;
 
//声明函数
VehicleList select_vehicle(VehicleList L, char * key);//定义车辆查询函数
VehicleList InitList(VehicleList L);//定义链表初始化函数
VehicleList LoadData(VehicleList L, char *filename);//定义信息读取函数
void SaveData(VehicleList L, char *filename);//定义存储数据函数
int main_menu();//定义主菜单
int dispatch(VehicleList L, char *lender_name, char *lender_id, char *return_time, char *section,char *purpose,
             char *usedate,char *useprice,char *usetime);//定义车辆调度函数
void back_vehicle(VehicleList L, char * key, char *lender_name, char *lender_id);//定义车辆归还函数
void list_all(VehicleList L);//定义车辆总览函数
VehicleList select_vehicle(VehicleList L, char * key);//定义车辆查询函数
VehicleList register_vehicle(VehicleList L);//定义车辆登记函数
void delete_vehicle(VehicleList L, char * key);//定义车辆删除函数
int datecmp(char *a,char *b);//定义日期比较函数
int quit();//定义退出函数
char *getS();
 
//定义字符串输入接口函数
char *getS()
{
    char *c;
    char s[30];
    scanf("%s",s);
    c=(char*)malloc(sizeof(char)*(strlen(s)+1));
    strcpy(c,s);
    return c;
}
 
//定义链表初始化函数
VehicleList InitList(VehicleList L)
{
    L=(VehicleList)malloc(sizeof(VNode));
    L->next=NULL;
    return L;
}
 
//定义比较日期大小函数
int datecmp(char *a,char *b)
{
    int i;
    for(i=0;i<11;i++)
    {
        if(a[i]>b[i])
            return 1;
        else if(a[i]==b[i])
            continue;
        else
            return -1;
 
    }
    return 0;
}
 
//定义从文件加载数据函数
VehicleList LoadData(VehicleList L,char *filename)
{
    VehicleList p,q;
    //Vehicle v,v2,v3;
    Vehicle vdata;
    FILE *fp;//定义文件指针
    char ver_id[20],ver_no[20],weight[20],ver_trand[20],factory[20],outdate[20];
    char buydate[20],price[20],ver_type[20],ver_status[20],ver_date[20],usetime[20];
    char section[20],purpose[20],usedate[20],useprice[20];
    char state[20],service[20],violation[20];
    char lender_name[20],lender_id[20],return_time[20];
    q=L;
    if((fp = fopen(filename,"r+")) == NULL)
    {
        printf("文件数据读取失败!\n");
    }
    else
    {
        while (!feof(fp))//将文件中数据读取到链表中
        {
            fscanf(fp,"%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s\r\n",
                   ver_id,ver_no,weight,ver_trand,factory,outdate,buydate,price,ver_type,ver_status,
                   ver_date,purpose,usedate,usetime,useprice,state,service,violation,
                   lender_name,lender_id,return_time);
            vdata.ver_id=(char*)malloc(sizeof(char)*(strlen(ver_id)+1));
            vdata.ver_no=(char*)malloc(sizeof(char)*(strlen(ver_no)+1));
            vdata.weight=(char*)malloc(sizeof(char)*(strlen(weight)+1));
            vdata.ver_trand=(char*)malloc(sizeof(char)*(strlen(ver_trand)+1));
            vdata.factory=(char*)malloc(sizeof(char)*(strlen(factory)+1));
            vdata.outdate=(char*)malloc(sizeof(char)*(strlen(outdate)+1));
            vdata.buydate=(char*)malloc(sizeof(char)*(strlen(buydate)+1));
            vdata.price=(char*)malloc(sizeof(char)*(strlen(price)+1));
            //vdata.section=(char*)malloc(sizeof(char)*(strlen(section)+1));
            vdata.purpose=(char*)malloc(sizeof(char)*(strlen(purpose)+1));
            vdata.usedate=(char*)malloc(sizeof(char)*(strlen(usedate)+1));
            vdata.usetime=(char*)malloc(sizeof(char)*(strlen(usetime)+1));
            vdata.useprice=(char*)malloc(sizeof(char)*(strlen(useprice)+1));
            vdata.ver_type=(char*)malloc(sizeof(char)*(strlen(ver_type)+1));
            vdata.state=(char*)malloc(sizeof(char)*(strlen(state)+1));
            vdata.service=(char*)malloc(sizeof(char)*(strlen(service)+1));
            vdata.violation=(char*)malloc(sizeof(char)*(strlen(violation)+1));
            vdata.ver_status=(char*)malloc(sizeof(char)*(strlen(ver_status)+1));
            vdata.ver_last_date=(char*)malloc(sizeof(char)*(strlen(ver_date)+1));
            vdata.lender_name=(char*)malloc(sizeof(char)*(strlen(lender_name)+1));
            vdata.lender_id=(char*)malloc(sizeof(char)*(strlen(lender_id)+1));
            vdata.return_time=(char*)malloc(sizeof(char)*(strlen(return_time)+1));
            strcpy(vdata.ver_id,ver_id);
            strcpy(vdata.ver_no,ver_no);
            strcpy(vdata.weight,weight);
            strcpy(vdata.ver_trand,ver_trand);
            strcpy(vdata.factory,factory);
            strcpy(vdata.outdate,outdate);
            strcpy(vdata.buydate,buydate);
            strcpy(vdata.price,price);
            strcpy(vdata.purpose,purpose);
            strcpy(vdata.usedate,usedate);
            strcpy(vdata.usetime,usetime);
            strcpy(vdata.useprice,useprice);
            strcpy(vdata.ver_type,ver_type);
            strcpy(vdata.ver_status,ver_status);
            strcpy(vdata.state,state);
            strcpy(vdata.service,service);
            strcpy(vdata.violation,violation);
            strcpy(vdata.ver_last_date,ver_date);
            strcpy(vdata.lender_name,lender_name);
            strcpy(vdata.lender_id,lender_id);
            strcpy(vdata.return_time,return_time);
            p=(VehicleList)malloc(sizeof(VNode));
            p->data=vdata;
            q->next=p;
            q=p;
        }
        fclose(fp);
    }
    q->next=NULL;
    return L;
 
}
//定义存储数据函数
void SaveData(VehicleList L, char *filename)
{
    VehicleList p;
    FILE *fp;//定义文件指针
    p=L;
 
    if((fp = fopen(filename,"w+")) == NULL)
    {
        printf("文件写入失败!\n");
    }
    else
    {
        while (p->next != NULL)
        {
            fprintf(fp,"%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s\r\n",p->next->data.ver_id,
                    p->next->data.ver_no,p->next->data.weight,p->next->data.ver_trand,p->next->data.factory,
                    p->next->data.outdate,p->next->data.buydate,p->next->data.price,
                    p->next->data.usedate,p->next->data.useprice,
                    p->next->data.ver_type,p->next->data.ver_status,p->next->data.usetime,
                    p->next->data.state,p->next->data.service,p->next->data.violation,
                    p->next->data.ver_last_date,p->next->data.lender_name,
                    p->next->data.lender_id,p->next->data.return_time);
            p=p->next;
        }
    }
 
    fclose(fp);
 
}
 
 
//定义主菜单
int main_menu()
{
    int i;
    printf("******************************************************\n");
    printf("*                     汽车调度程序                   *\n");
    printf("*                                         韩力毅     *\n");
    printf("******************************************************\n");
    printf("*                      1.汽车调度                    *\n");
    printf("*                      2.汽车归还                    *\n");
    printf("*                      3.车辆总况一览                *\n");
    printf("*                      4.车辆查询                    *\n");
    printf("*                      5.新车登记                    *\n");
    printf("*                      6.车辆注销                    *\n");
    printf("*                      7.退出系统                    *\n");
    printf("******************************************************\n");
    printf("*                      请选择: 1-7                   *\n");
    printf("******************************************************\n");
    printf("请输入您的选项:");
    scanf("%d", &i);
    feature=i;
    return i;
}
 
//定义功能1--汽车调度
int dispatch(VehicleList L, char *lender_name, char *lender_id, char *return_time, char *section,char *purpose,
             char *usedate,char *useprice,char *usetime)
{
    char *vtype,*vid;//车型
    VehicleList p,q1,q2;
    char tmpdate[20];
    int i=0;
    p=L;
    q1=L;
    q2=L;
    strcpy(tmpdate,now_date);
    printf("\n请选择您需要的车型(A.大型车 B.中型车 C.小型车 E.返回主菜单 请输入大写字母!):");
    vtype = getS();
    if (strcmp("E",vtype) == 0) return 0;//如果输入E,返回主菜单
    printf("\n*************************************本次出车费用为200元*************************************\n");
    printf("\n****************************************可选车辆列表******************************************");
    printf("\n车辆编号   车牌号  载重量  车牌  车辆类型    车辆状态    上次出车时间(DDYYMM)\n");
    while (L->next != NULL)
    {//显示符合条件的在库车辆信息
        if (strcmp("出车中",L->next->data.ver_status) !=0 && strcmp(vtype,L->next->data.ver_type) ==0)
        {
            if(datecmp(tmpdate,L->next->data.ver_last_date) > -1)//调用比较未调度时间的函数
            {
                q1=L;//获得最长时间没有被调度的车的节点指针
                strcpy(tmpdate,q1->next->data.ver_last_date);
            }
 
            printf("%6s %10s %-10s %3s %8s %13s %15s\n",
                   L->next->data.ver_id,L->next->data.ver_no,L->next->data.weight,L->next->data.ver_trand,L->next->data.ver_type,
                   L->next->data.ver_status,L->next->data.ver_last_date);
        }
        if (strcmp("NEW",L->next->data.ver_last_date) ==0 && strcmp(vtype,L->next->data.ver_type) ==0)
        {
            i++;//计算新车数量
            q2=L;//获得新车的节点指针
        }
 
        L=L->next;
    }
    L=p;
    printf("**************************************************************************\n");
    printf("请输入车辆编号或输入W智能筛选(输入E返回主菜单):");
    vid = getS();
    if (strcmp("W",vid) == 0)
    {
        if(i>0)
        {
            printf("\n****************************************车辆调度结果****************************************");
            printf("\n已调出车辆:%s,载重量:%s,车牌:%s,出车日期:%s\n",q2->next->data.ver_id,q2->next->data.weight,q2->next->data.ver_trand,now_date);
            printf("**********************************************************************************************\n");
            q2->next->data.ver_status="出车中";//修改车辆状态和上次出车时间
            q2->next->data.ver_last_date=(char*)malloc(sizeof(char)*(strlen(now_date)+1));
            strcpy(q2->next->data.ver_last_date,now_date);
            strcpy(q2->next->data.lender_name,lender_name);
            strcpy(q2->next->data.lender_id,lender_id);
            strcpy(q2->next->data.return_time,return_time);
            strcpy(q2->next->data.section,section);
            strcpy(q2->next->data.purpose,purpose);
            strcpy(q2->next->data.usedate,usedate);
            strcpy(q2->next->data.useprice,useprice);
            strcpy(q2->next->data.usetime,usetime);
            return 1;
 
        }
        else
        {
            printf("\n****************************************车辆调度结果****************************************");
            printf("\n已调出车辆:%s,载重量:%s,车牌:%s,出车日期:%s\n",q1->next->data.ver_id,q1->next->data.weight,q1->next->data.ver_trand,now_date);
            printf("**********************************************************************************************\n");
            q1->next->data.ver_status="出车中";//修改车辆状态和上次出车时间
            q1->next->data.ver_last_date=(char*)malloc(sizeof(char)*(strlen(now_date)+1));
            strcpy(q1->next->data.ver_last_date,now_date);
            strcpy(q1->next->data.lender_name,lender_name);
            strcpy(q1->next->data.lender_id,lender_id);
            strcpy(q1->next->data.return_time,return_time);
            strcpy(q2->next->data.section,section);
            strcpy(q2->next->data.purpose,purpose);
            strcpy(q2->next->data.usedate,usedate);
            strcpy(q2->next->data.useprice,useprice);
            strcpy(q2->next->data.usetime,usetime);
            return 1;
 
        }
 
    }
    else if ((p=select_vehicle(L,vid)) != NULL)
    {
        p->next->data.ver_status="出车中";//修改车辆状态和上次出车时间
        p->next->data.ver_last_date=(char*)malloc(sizeof(char)*(strlen(now_date)+1));
        strcpy(p->next->data.ver_last_date,now_date);
        strcpy(p->next->data.lender_name,lender_name);
        strcpy(p->next->data.lender_id,lender_id);
        strcpy(p->next->data.return_time,return_time);
        strcpy(q2->next->data.section,section);
        strcpy(q2->next->data.purpose,purpose);
        strcpy(q2->next->data.usedate,usedate);
        strcpy(q2->next->data.useprice,useprice);
        strcpy(q2->next->data.usetime,usetime);
        printf("\n****************************************车辆调度结果****************************************");
        printf("\n已调出车辆:%s,载重量:%s,车牌:%s,出车日期:%s\n",p->next->data.ver_id,p->next->data.weight,p->next->data.ver_trand,now_date);
        printf("**********************************************************************************************\n");
        return 1;
    }
    else if (strcmp("E",vid) == 0)
    {
        return 0;
    }
    else
    {
        printf("输入错误,请返回!\n");
        return 4;
    }
    return 4;
}
 
//定义功能2--汽车归还
void back_vehicle(VehicleList L, char * key, char *lender_name,
                  char *lender_id)
{
    VehicleList p;
    if ((p=select_vehicle(L,key)) != NULL)
    {
        if (strcmp(lender_name,p->next->data.lender_name) == 0 &&
            strcmp(lender_id,p->next->data.lender_id) == 0)//姓名和身份证号输入正确才可还车
        {
            if (datecmp(now_date,p->next->data.return_time) < 1)//如果实际归还时间超出预定归还时间,提示到服务台办理
            {
                p->next->data.ver_status="可调出";//恢复车辆状态及租车人信息为初始状态
                p->next->data.lender_name="N/A";
                p->next->data.lender_id="N/A";
                p->next->data.return_time="N/A";
                printf("\n汽车归还成功!\n\n");
            }
            else
            {
                printf("\n归还失败,您的车辆已超期,请到总服务台办理超期还车手续!\n\n");
            }
        }
        else
        {
            printf("\n租车人姓名或身份证号输入有误!\n\n");
        }
 
    }else{
        printf("\n没有查询到编号为:%s的车辆信息!\n\n",key);
    }
 
}
 
//定义功能3--车辆总况一览
void list_all(VehicleList L)
{
    printf("\n车辆编号  车 牌 号  载重量  车 牌  生产厂家  出 厂 日 期  购 买 日 期  购买单价  车型  车辆状态  车辆运营状态  车辆维修情况  车辆违章情况  上次出车时间  租车人姓名  计划归还时间\n");
    while (L->next != NULL)
    {
        //显示所有已登记车辆信息
        //if(strcmp("出车中",L->next->data.ver_status) !=0)
        printf("%6s %10s %6s %8s %9s %11s %12s %9s %4s %10s %10s %12s %13s %13s %18s %14s\n",
               L->next->data.ver_id,L->next->data.ver_no,L->next->data.weight,
               L->next->data.ver_trand,L->next->data.factory,
               L->next->data.outdate,L->next->data.buydate,L->next->data.price,
               L->next->data.ver_type,L->next->data.ver_status,L->next->data.state,
               L->next->data.service,L->next->data.violation,L->next->data.ver_last_date,
               L->next->data.lender_name,L->next->data.return_time);
        L=L->next;
    }
    printf("\n");
    system("pause");
}
 
//定义功能4--车辆查询
VehicleList select_vehicle(VehicleList L, char * key)
{
    VehicleList p;
    p=L;
    while (p->next != NULL)
    {
        //如果查找到符合条件的车辆信息,则返回这个车辆信息节点的指针,strcmp,字符串比较函数
        if (strcmp(key,p->next->data.ver_id) == 0 || strcmp(key,p->next->data.ver_no) == 0)
        {
            return p;//P为该车辆信息节点的指针
        }
        else
        {
            p=p->next;
        }
    }
    return NULL;
}
 
//定义功能5--新车登记
VehicleList register_vehicle(VehicleList L)
{
    VehicleList p,q;
    Vehicle v;//定义新增车辆结构体
    int id=1001;//初始车辆编号起始ID
    char tmpID[5];//车辆编号格式化为字符串
    q=L;
    while (q->next != NULL)
    {
        q=q->next;//将指针调至链表尾部以插入新数据
    }
    //printf("请输入车辆编号: ");
    //v.ver_id=getS();
    printf("请输入车牌号: ");
    v.ver_no=getS();
    printf("请输入载重量: ");
    v.weight=getS();
    printf("请输入车牌: ");
    v.ver_trand=getS ();
    printf("请输入生产厂家: ");
    v.factory=getS();
    printf("请输入出厂日期:(格式,如2012-02-22) ");
    v.outdate=getS();
    printf("请输入购买日期:(格式,如2012-02-22) ");
    v.buydate=getS();
    printf("请输入购买单价: ");
    v.price=getS();
    printf("请选择车辆类型(A/B/C): ");
    v.ver_type=getS();
    printf("请输入车辆运营状态(正常/报废): ");
    v.state=getS();
    printf("请输入车辆维修情况(否/几次): ");
    v.service=getS();
    printf("请输入车辆违章情况(否/几次): ");
    v.violation=getS();
    v.ver_status="可调出";
    v.ver_last_date="NEW";
    v.lender_name=(char*)malloc(10);
    strcpy(v.lender_name, "N/A       ");
    v.lender_id=(char*)malloc(10);
    strcpy(v.lender_id, "N/A       ");
    v.return_time=(char*)malloc(10);
    strcpy(v.return_time, "N/A       ");
    v.section=(char*)malloc(10);
    strcpy(v.section,"N/A       ");
    v.purpose=(char*)malloc(10);
    strcpy(v.purpose,"N/A       ");
    v.usedate=(char*)malloc(10);
    strcpy(v.usedate,"N/A       ");
    v.useprice=(char*)malloc(10);
    strcpy(v.useprice,"N/A       ");
    v.usetime=(char*)malloc(10);
    strcpy(v.usetime,"N/A       ");
    //自动生成车辆编号
    sprintf(tmpID, "%d", id);
    while(select_vehicle(L,tmpID) != NULL)
    {
        id++;
        sprintf(tmpID, "%d", id);//将id转为字符串存储到tmpID中
    }
 
    v.ver_id=(char*)malloc(sizeof(char)*(strlen(tmpID)+1));//分配内存空间
    strcpy(v.ver_id,tmpID);//将tmpID拷贝到车辆信息结构中
    if(select_vehicle(L,v.ver_no) == NULL)
    {
        //检查是否已有该车牌号
        p=(VehicleList)malloc(sizeof(VNode));//创建新的车辆节点
        p->data=v;
        q->next=p;//连接新的车辆节点
        q=p;    //将q指针移至最后节点
        q->next=NULL;//将最后一个节点的next设为NULL
        printf("\n成功登记牌号为:%s的车辆,车辆编号为:%s!\n\n",v.ver_no,v.ver_id);
    }
    else
    {
        printf("\n已存在该车辆!\n\n");
    }
    return L;
}
 
//定义功能6--车辆注销
void delete_vehicle(VehicleList L, char * key)
{
    VehicleList p,q;
    p=L;
 
    if ((p=select_vehicle(L,key)) != NULL)
    {
        q=p->next;
        p->next=q->next;//将节点p连接到下下一个节点,即删除找到的节点
        free(q);
        printf("\n已注销编号为%s的车辆!\n\n",key);
 
    }
    else
    {
        printf("\n没有找到符合条件的车辆!\n\n");
    }
 
    system("pause");
}
 
//定义功能7--退出系统函数
int quit()
{
    char *temp;
    temp=getS();//接受用户输入
 
    if(strcmp("Y",temp)==0)
    {
        return 1;//返回1,为确实退出
    }
    else if(strcmp("N",temp)==0)
    {
        return 0;//返回0,则不退出,并清屏,加载主菜单
    }
    else
    {
        return 2;//返回2,说明输入错误,任意键返回主菜单
    }
 
    return 2;//默认返回2
 
}
 
int main()
{
    VehicleList L1,tmpL;
    char *vehicle_key,*lender_name,*lender_id,*return_time,*section,*purpose,*usedate,*useprice,*usetime;
    char *filename="vehicle.txt";//设置数据文件
    GetLocalTime(&sys);
    sprintf(now_date,"%4d-%02d-%02d",sys.wYear,sys.wMonth,sys.wDay);
 
    L1=(VehicleList)malloc(sizeof(VNode));
    L1=InitList(L1);
    L1=LoadData(L1,"vehicle.txt");
 
    main_menu:
    //SaveData(L1,filename);//每完成一个操作都保存数据到文件,默认选择7程序退出时才保存数据
    main_menu();//加载主菜单
    switch (feature)
    {
        case 1:
        {
            int i;
            printf("请输入租车人姓名: ");
            lender_name = getS();
            printf("请输入租车人身份证号: ");
            lender_id = getS();
            printf("请输入用车单位: ");
            section = getS();
            printf("请输入出车用途: ");
            purpose = getS();
            printf("请输入出车时长(格式N天): ");
            usetime = getS();
            printf("请输入出车日期(格式YYYY-MM-DD,如 %s): ",now_date);
            usedate = getS();
            printf("请输入计划归还时间(格式YYYY-MM-DD,如 %s): ",now_date);
            return_time = getS();
            useprice = "200";
            if (datecmp(now_date,return_time) > 0)
            {
                printf("\n归还时间输入错误,最少需要租一天,即时间应该大于等于 %s\n\n",now_date);
                system("pause");
                system("cls");
                goto main_menu;
            }
            i=dispatch(L1,lender_name,lender_id,return_time,section,purpose,usedate,useprice,usetime);        //调用车辆调度函数
            if (i==0)
            {
                system("cls");
                goto main_menu;
            }
            else
            {
                system("pause");
                system("cls");
                goto main_menu;
            }
        }
 
        case 2:
        {
            printf("请输入汽车编号: ");
            vehicle_key = getS();
            printf("请输入租车人姓名: ");
            lender_name = getS();
            printf("请输入租车人身份证号: ");
            lender_id = getS();
            back_vehicle(L1,vehicle_key,lender_name,lender_id);//调用车辆归还函数
            system("pause");
            system("cls");
            goto main_menu;
        }
 
        case 3:
        {
            list_all(L1);//调用车辆总览函数
            system("cls");
            goto main_menu;
        }
 
        case 4:
        {
            printf("请输入汽车编号或车牌号: ");
            vehicle_key=getS();
            tmpL=select_vehicle(L1,vehicle_key);//调用车辆查找函数
            if (tmpL != NULL)//返回不为空,说明找到了
            {
                printf("\n*****************************找到了符合条件的车辆信息****************************\n");
                printf("\n车辆编号  车 牌 号  载重量  车 牌  车 型  车辆状态  上次出车时间  租车人姓名  计划归还时间\n");
                printf("\n%6s %10s %6s %8s %4s %10s %10s %18s %14s\n",
                       tmpL->next->data.ver_id,tmpL->next->data.ver_no,tmpL->next->data.weight,tmpL->next->data.ver_trand,
                       tmpL->next->data.ver_type,tmpL->next->data.ver_status,
                       tmpL->next->data.ver_last_date,tmpL->next->data.lender_name,
                       tmpL->next->data.return_time);
                system("pause");
            }
            else
            {
                printf("\n\n没有找到符合条件的车辆信息!\n\n");
                system("pause");//按任意键继续
            }
            system("cls");
            goto main_menu;
        }
 
        case 5:
        {
            L1=register_vehicle(L1);//调用车辆登记函数
            system("pause");
            system("cls");
            goto main_menu;
        }
 
        case 6:
        {
            vehicle_key = "0008";
            printf("请输入需要注销的车辆编号: ");
            vehicle_key=getS();
            delete_vehicle(L1,vehicle_key);//调用车辆注销函数
            system("cls");
            goto main_menu;
        }
 
        case 7:
        {
            int temp;
            printf("您确定要退出系统?输入Y确定,输入N返回主菜单\n");
            temp = quit();
            if(1 == temp)
            {
                SaveData(L1,filename);//保存数据
                return 0;
            }
            else if(0 == temp){
                system("cls");
                goto main_menu;//如果返回真则退出,否则返回主菜单
            }
            else
            {
                printf("输入错误!");
                system("pause");
            }
        }
 
        default:
        {
            system("cls");
            getchar();
            goto main_menu;//如果输入不在1-7内,则返回主菜单
        }
 
    }
 
    return 0;
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/qq_41586843/article/details/103465026

延伸 · 阅读

精彩推荐
  • C/C++给C语言初学者的学习建议

    给C语言初学者的学习建议

    在本篇文章里小编给大家分享的是关于C语言学习建议的相关内容,有兴趣的朋友们可以学习参考下。...

    少儿编程9232021-09-13
  • C/C++c语言的cps实现求fibonacci数列示例

    c语言的cps实现求fibonacci数列示例

    这篇文章主要介绍了c语言的cps实现求fibonacci数列示例,需要的朋友可以参考下...

    C语言程序设计5672021-01-17
  • C/C++c/c++拷贝构造函数和关键字explicit详解

    c/c++拷贝构造函数和关键字explicit详解

    这篇文章主要介绍了c/c++拷贝构造函数和关键字explicit的相关知识,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下...

    小石王4232021-07-01
  • C/C++12个关于C语言的有趣问答

    12个关于C语言的有趣问答

    这篇文章主要介绍了12个关于C语言的有趣问答,有助于读者加深对C语言程序设计的理解,需要的朋友可以参考下...

    C语言程序设计9692021-01-24
  • C/C++C语言打印某一年中某月的日历

    C语言打印某一年中某月的日历

    本文详细讲解了C语言打印某一年中某月的日历,文中通过示例代码介绍的非常详细。对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随...

    雷猴11252022-03-09
  • C/C++解决C++中重定义的方法总结

    解决C++中重定义的方法总结

    本篇文章是对C++中重定义的解决方法进行了详细的分析介绍,需要的朋友参考下...

    C++教程网4342020-11-30
  • C/C++C++实现邮件群发的方法

    C++实现邮件群发的方法

    这篇文章主要介绍了C++实现邮件群发的方法,较为详细的分析了邮件发送的原理与C++相关实现技巧,非常具有实用价值,需要的朋友可以参考下...

    kevin02167292021-03-02
  • C/C++C++实现LeetCode(312.打气球游戏)

    C++实现LeetCode(312.打气球游戏)

    这篇文章主要介绍了C++实现LeetCode(312.打气球游戏),本篇文章通过简要的案例,讲解了该项技术的了解与使用,以下就是详细内容,需要的朋友可以参考下...

    Grandyang9502021-12-01