问题描述:
由于我国经济发展迅速,车辆的拥有量也跟着大幅上升,城市拥堵的情况越来越严重,停车场越来越成为一种稀缺资源,因此就有了要求高效利用停车场的需求。
控制稀缺资源的有效办法就是收费。停车场的收费规则是,1小时以内免费。超过1小时,每小时6元钱。人工计费费时费力,而且容易出错,希望你们开发一个软件来帮助辛勤的保安们来管理停车场。
1)对车位进行管理:
能查询一共有多少车位
能查询有多少空的车位
能查询占用车位对应的车牌号和停靠时间
2)收费管理:
能查询现在停靠了多少车
能够记录车辆的停靠时间
根据根据停靠时间计算出费用
代码如下:
#include#include#include#include#define null 0# define len sizeof(struct node)struct node{ int num; //序号 char numble[47]; //车牌 char intime[47]; //进入时间 char outtime[47]; //出去时间 struct node *next;};struct node *creat()//创建一个有十个车位的停车场链表{ int n; struct node *head,*p,*tail; head = null; for(n = 1 ; n num = n ; strcpy(p->numble,0); strcpy(p->intime,0); strcpy(p->outtime,0); if(n == 1) { head = p; } else tail->next = p; tail = p; } tail->next = null; return(head);}void print(struct node *head){ struct node *p; printf(当前停车场信息如下:\n\n); p=head; if(head!=null) { do { printf(车场序号: %-6d车牌号码: %5s\n,p->num,p->numble); printf(进入时间:%32s\n,p->intime); printf(驶出时间:%32s\n,p->outtime); printf(*******************************************\n); p=p->next; }while(p!=null); } }void money(struct node *head)//计费{ int n,m; struct node *p; time_t rawtime; struct tm*timeinfo; time(&rawtime); timeinfo = localtime(&rawtime); printf(亲、请输入你要计费的车辆序号\n); scanf(%d,&n); p = head; while(p->num != n) { p = p->next; //寻找对应序号 }// int tt = asctime(timeinfo) - p->intime; char time1[47],time2[47]; strcpy(time1,asctime(timeinfo)); strcpy(time2,p->intime); int len1 = strlen(time1); int len2 = strlen(time2); int t1= 0,t2 = 0; for(int i = 0 ; i numble,0)!=0))//查找空车位 { p=p->next; } if(p!=null) { printf(请输入当前的车牌号!\n); scanf(%s,s); printf(您的停车位是:[%d]号!\n,p->num); strcpy(p->numble,s); strcpy(p->intime,asctime(timeinfo)); } else { printf(停车场已满,亲、请退出操作!\n); } }void out(struct node* head){ struct node *p; int n; time_t rawtime; struct tm*timeinfo; time(&rawtime); timeinfo = localtime(&rawtime); printf(请输入车辆的序号!\n); scanf(%d,&n); p = head; while(p->num != n) { p = p->next; //寻找对应序号 } strcpy(p->outtime,asctime(timeinfo)); printf(车牌 号码为:[%s]\n,p->numble); printf(车辆进入时间为:%s\n,p->intime); printf(车辆驶出时间为:%s\n,p->outtime); strcpy(p->numble,0); strcpy(p->intime,0);}void main(){ int n; struct node *head; head=null; printf(请输入对应的数字,进行操作\n); printf(0:退出程序\n); printf(1:创建停车场信息\n); printf(2:输出停车场信息\n); printf(3:车辆进入停车场\n); printf(4:车辆驶出停车场\n); printf(5: 车辆停车所需费用\n); printf(请输入对应的数字,进行操作\n); scanf(%d,&n); while(n!=0) { switch(n) { case 1: head=creat(); break; case 2: print(head); break; case 3: in(head); break; case 4: out(head); break; case 5: money(head); break; default: 0; } printf(请输入相应的数字,进行操作\n); scanf(%d,&n); }}
