#include "stdafx.h"
#include
#include
#include
#define max 5
#define pri 5
typedef struct time{
int year;
int day;
int month;
int hour;
int min;
}Time;
typedef struct node{
char num[10];
Time reach;
Time leave;
}Carinfo;
typedef struct car{
Carinfo *data;
struct car *next;
}queue;
typedef struct Node{
queue *lead;
queue *end;
}link;
typedef struct NODE{
Carinfo *b[max+1];
int top;
}Zhan;
void Zhaninit(Zhan *s){
int i;
s->top=0;
for(i=0;i<=max;i++)
s->b[s->top]=NULL;
}
int queueinit(link *U){
U->lead=(queue *)malloc(sizeof(queue));
if(U->lead!=NULL)
{
U->lead->next=NULL;
U->end=U->end;
return(1);
}
else return(-1);
}
int Arrival(Zhan *into,link *R){
Carinfo *p;
queue *t;
p=(Carinfo *)malloc(sizeof(Carinfo));
flushall();
printf("\n车牌号:");
gets(p->num);
if(into->top<max)
{
into->top++;
printf("\n\n车辆在第%d位置.",into->top);
printf("\n到达时间:<例:2015 08 08 14:00>\n");
scanf("%d %d %d %d:%d",&(p->reach.year),&(p->reach.month),&(p->reach.day),&(p->reach.hour),&(p->reach.min));
into->b[into->top]=p;
return(1);
}
else
{
printf("无法进场,请稍候!");
t=(queue *)malloc(sizeof(queue));
t->data=p;
t->next=NULL;
R->end->next=t;
R->end=t;
return(1);
}
}
void pay(Carinfo *p,int blank)
{
int n1,n2,m1,m2,consume;
printf("\n离开的时间:");
scanf("%d %d %d %d:%d",&(p->leave.year),&(p->leave.month),&(p->leave.day),&(p->leave.hour),&(p->leave.min));
printf("\n离开的车牌号为:");
puts(p->num);
printf("\n其到达时间为: %d %d %d %d:%d",p->reach.year,p->reach.month,p->reach.day,p->reach.hour,p->reach.min);
printf("\n离开时间为: %d %d %d %d:%d",p->leave.year,p->leave.month,p->leave.day,p->leave.hour,p->leave.min);
n1=p->reach.day;
n2=p->reach.hour;
m1=p->leave.day;
m2=p->leave.hour;
if(m2==n2&&m1>=n1)
{
consume=((m1-n1)*24+1)*pri;
}
else
{
if(m2>n2&&m1>n1)
{
consume=((m1-n1)*24+(m2-n2))*pri;
}
else
{
if(m2<n2&&m1>n1)
{
consume=((m1-n1)*24+(m2-n2))*pri;
}
}
}
printf("\n应交费用为: %d元",consume);
free(p);
}
void Leave(Zhan *into,Zhan *off,link *R)
{
int blank;
Carinfo *p,*t;
queue *q;
if(into->top>0)
{
while(1)
{
printf("\n选择在场车辆的位置/1--%d/:",into->top);
scanf("%d",&blank);
if(blank>=1&&blank<=into->top) break;
else printf("\n 错误: ");
}
while(into->top>blank)
{
off->top++;
off->b[off->top]=into->b[into->top];
into->b[into->top]=NULL;
into->top--;
}
p=into->b[into->top];
into->b[into->top]=NULL;
into->top--;
while(off->top>=1)
{
into->top++;
into->b[into->top]=off->b[off->top];
off->b[off->top]=NULL;
off->top--;
}
pay(p,blank);
if((R->lead!=R->end)&&into->top
{
q=R->lead->next;
t=q->data;
into->top++;
printf("\n\n便道的%d号车进入车场第%d位置.",t->num,into->top);
printf("\n\n请输入%d号车进入车场的时间:",t->num);
scanf("%d %d %d %d:%d",&(t->reach.year),&(t->reach.month),&(t->reach.day),&(t->reach.hour),&(t->reach.min));
R->lead->next=q->next;
if(q==R->end) R->end=R->lead;
into->b[into->top]=t;
free(q);
}
else printf("\n便道里没有车.\n");
}
else printf("\n停车场里没有车.");
}
void park1(link *R)
{
queue *p;
int i;
p=R->lead->next;
if(R->lead!=R->end)
{
printf("没有车!:\n");
for(i=1; (p!=NULL); i++)
{
printf("第 %d 车辆.",i);
puts(p->data->num);
p=p->next ;
}
}
}
void park2(Zhan *S)
{
int i;
if(S->top>0)
{
printf("车场:");
printf("\n \n位置 到达时间 车牌号\n");
for(i=1;i<=S->top;i++)
{
printf(" %d ",i);
printf("%d %d %d %d:%d ",S->b[i]->reach.year,S->b[i]->reach.month,S->b[i]->reach.day,S->b[i]->reach.hour,S->b[i]->reach.min);
puts(S->b[i]->num);
}
}
else
printf("这里没有车!\n");
}
void park(Zhan U,link R)
{
int flag,tag;
flag=1;
while(flag)
{
printf("\n\n\n 1 道路上 2 车场里 3 返回主菜单\n");
printf("\n请选择 1~3:");
while(1)
{
scanf("%d",&tag);
if(tag>=1 && tag<=3)
break;
else
printf("\n 输入有误,请重新选择 1~3:");
}
switch(tag)
{
case 1:park1(&R);
break;
case 2:park2(&U);
break;
case 3:flag=0; system("cls");
break;
default:
break;
}
}
}
void main(int argc, char* argv[])
{
Zhan into,off;
link Wait;
int ch;
Zhaninit(&into);
Zhaninit(&off);
queueinit(&Wait);
system("color 0F");
while(1)
{
printf("\n\n\n\n\n\t ☆☆☆☆☆ 欢 迎 使 用 停 车 场 系 统. ☆☆☆☆☆\t\n");
printf("\n\n\n\t ▲◇◇◇◇◇◇ 1. 车辆进场信息录入.◇◇◇◇◇◇◇▲\t\n");
printf("\n\n\n\t ▲◇◇◇◇◇◇ 2. 车辆出场信息录入.◇◇◇◇◇◇◇▲\t\n");
printf("\n\n\n\t ▲◇◇◇◇◇◇ 3. 车辆列表信息显示.◇◇◇◇◇◇◇▲\t\n");
printf("\n\n\n\t ▲◇◇◇◇◇◇ 4. 退 出 系 统 .◇◇◇◇◇◇◇▲\t\n\n");
printf("\n\t收费标准:按小时收费,未满一小时按一小时算,总停车时长不得超过一个月!\t\n\n");
while(1)
{
printf(" 您想做些什么?: ");
scanf("%d",&ch);
if(ch>=1&&ch<=5)break;
else printf("\n 输入有误,请重新选择: 1~4: ");
}
switch(ch)
{
case 1:Arrival(&into,&Wait);
break;
case 2:Leave(&into,&off,&Wait);
break;
case 3:park(into,Wait);
break;
case 4:exit(0);
default:
break;
}
}
}