#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 <= 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;
}
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 < 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;
else
m = 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);
}
}