停车场程序设计

来源:互联网 发布:网络借贷宝怎么还款啊 编辑:程序博客网 时间:2024/04/26 06:04

转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents


问题描述:

由于我国经济发展迅速,车辆的拥有量也跟着大幅上升,城市拥堵的情况越来越严重,停车场越来越成为一种稀缺资源,因此就有了要求高效利用停车场的需求。
控制稀缺资源的有效办法就是收费。停车场的收费规则是,1小时以内免费。超过1小时,每小时6元钱。人工计费费时费力,而且容易出错,希望你们开发一个软件来帮助辛勤的保安们来管理停车场。

1)对车位进行管理:
能查询一共有多少车位
能查询有多少空的车位
能查询占用车位对应的车牌号和停靠时间
2)收费管理:
能查询现在停靠了多少车
能够记录车辆的停靠时间
根据根据停靠时间计算出费用

代码如下:

#include<cstdio>#include<cstring>#include<malloc.h>#include<ctime>#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 <= 10 ; n++ ){p = (struct node*)malloc(LEN);p->num = n ; strcpy(p->numble,"0");strcpy(p->intime,"0");strcpy(p->outtime,"0");if(n == 1){head = p;}elsetail->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 < len1 ; i++){if(time1[i] == ':'){t1 = t1*10+time1[i-2]-'0';}}for( i = 0 ; i < len2 ; i++){if(time2[i] == ':'){t2 = t2*10+time2[i-2]-'0';}}int tt = t2 - t1;if(tt > 1)m = (tt-1)*6;elsem = 0;printf("此次停车共计费用为: %d\n",m);} void in(struct node *head)//车辆进入停车场{char s[47];time_t rawtime;struct tm*timeinfo;time(&rawtime);timeinfo=localtime(&rawtime);struct node *p;p = head;while((p!=NULL)&&(strcmp(p->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);}}



9 0