#include <stdio.h>
#include <stdlib.h>
#include"kernel_list.h"
#include <time.h>
#include<string.h>
void show(struct list_head *vhead) ;
//会员车辆
struct vip_car
{
int S_time; // 会员的注册日期
int F_time; //会员的到期日期
char car_id[100]; // 车牌号
struct list_head list; //内核链表 (用于链表的操作)
};
//普通车辆
struct car
{
char car_id[100]; //车牌号
int in; //车辆的进场日期
int out; //车辆的出场日期
struct list_head list; //内核链表 (用于链表的操作)
};
//vip的录入
void vip_inser(struct list_head *vhead)
{
struct vip_car *new = malloc(sizeof(struct vip_car));
int S_time,F_time,a; //定义会员时间
char car_id[100];
time_t T;
time(&T);
long int b=T; //获取时间(秒)
printf("\n\t\t\t请输入VIP信息\n");
printf("\n\t\t\t 请输入车牌号\n");
scanf("%s",car_id);
stpcpy(new->car_id,car_id);
printf("\n请输入充值的是至尊年卡还是会员月卡,年卡按1,月卡(30天)按2\n");
printf("\033[47;35m****************************************************************\033[0m \n\n");
scanf("%d",&a);
if(a==1)
{
new->S_time=b;
new->F_time=b+(31536000);
}
if(a==2)
{
new->S_time=b;
new->F_time=b+(2592000);
}
list_add_tail(&new->list,vhead);
show(vhead);
}
//时间转换
void A_time(long int a)
{
struct tm *p=localtime(&a);
printf("%d年%d月%d日%d时\n",p->tm_year+1900,p->tm_mon+1,p->tm_mday,p->tm_hour);
}
//时间差计算
int B_time(long int a,long int b)
{
int m=b-a;
return m;
}
//会员信息
void show(struct list_head *vhead)
{
struct list_head *pos = vhead->next;
int m=0;
time_t T;
time(&T);
long int b=T;
printf("------------------------------------------------------------------\n\n");
while(pos != vhead)
{
printf("\t会员车:\n");
printf("%s\n",list_entry(pos,struct vip_car,list)->car_id);
printf("\t注册时间为:\n");
A_time(list_entry(pos,struct vip_car,list)->S_time);
printf("\t到期时间为:\n");
A_time(list_entry(pos,struct vip_car,list)->F_time);
m=B_time(list_entry(pos,struct vip_car,list)->S_time,list_entry(pos,struct vip_car,list)->F_time);
printf("\t会员到期时间还剩%d天\n",m/86400);
pos = pos->next;
}
printf("-------------------------------------------------------------------\n");
}
//停车场的录入
void Park(struct list_head *head,struct list_head *vhead,char car_id[100])
{
struct list_head *p=vhead->next;
long int in; //车辆的进场日期
time_t T;
time(&T);
long int c=T; //获取时间(秒)
while(p!=vhead)
{
if(strcmp(car_id,list_entry(p,struct vip_car,list)->car_id)==0)//
{
printf(" \033[47;35m******************************尊贵的会员车**************************\033[0m \n");
struct vip_car *new = malloc(sizeof(struct car));
stpcpy(new->car_id,car_id);
printf("%s\n",list_entry(p,struct vip_car,list)->car_id);
printf("注册时间为:\n");
A_time(list_entry(p,struct vip_car,list)->S_time);
printf("到期时间为:\n");
A_time(list_entry(p,struct vip_car,list)->F_time);
list_add_tail(&new->list,head);
printf("\n\t会员停车成功!!\n");
return ;
}
p=p->next;
}
struct car *new = malloc(sizeof(struct car));
stpcpy(new->car_id,car_id);
new->in=c;
list_add_tail(&new->list,head);
printf("\t\t\t停车成功!!\n");
}
//普通车显示
void show_poorpark(struct list_head *head)
{
struct list_head *tmp =head->next;
printf("---------------------------------------------------------------------------\n\n");
while (tmp!=head)
{
printf("%s\n",list_entry(tmp,struct car,list)->car_id);
tmp =tmp->next;
}
printf("---------------------------------------------------------------------------\n\n");
}
//会员车显示
void show_vippark(struct list_head *head,struct list_head *vhead)
{
struct list_head *pos =head->next;
printf("----------------------------------------------------------\n\n");
while (pos!=head)
{
printf("%s\n",list_entry(pos,struct vip_car,list)->car_id);
pos =pos->next;
}
printf("-----------------------------------------------------------\n\n");
}
//普通车出场
void del(struct list_head *head,char a[100])
{
struct list_head *pos = head->next;
time_t T;
time(&T);
long int b=T;
int q=0;
if(pos==head)
{
printf("停车场为空\n");
return;
}
while(pos!=head)
{
if(strcmp(a,list_entry(pos,struct car,list)->car_id)==0) //找到需要删除的数据
{
printf(" \033[47;35m*************************************************************\033[0m \n");
struct list_head *p = pos;
pos = pos->prev;// pos 回去上一个位置
q=b-(list_entry(p,struct car,list)->in);
printf("本次停车费用为%f¥\n",q*0.03);
list_del(p);
free(list_entry(p,struct car,list));
printf("\033[47;35m\t\t\t\t***请慢走***\033[0m \n\n");
printf(" \033[47;35m*****************************************************************\033[0m \n");
}
pos = pos->next;
}
}
//会员车出场
void vip_del(struct list_head *head,struct list_head *vhead)
{
struct list_head *pos = head->next;
if(pos==head)
{
printf("停车场为空\n");
return;
}
char a[100]={0};
printf("输入车牌号\n\n");
scanf("%s",a);
while(pos!= head)
{
if(strcmp(a,list_entry(pos,struct vip_car,list)->car_id)==0) //找到需要删除的数据
{
printf(" \033[47;35m******************************尊贵的会员车*****************************\033[0m \n\n");
struct list_head *tmp = pos;
show(vhead);
pos = pos->prev;
list_del(tmp);
free(list_entry(tmp,struct vip_car,list));
printf("\t\033[47;35m**************************尊敬的VIP请慢走***********************\033[0m\n\n");
printf("\033[47;35m************************************************************************\033[0m \n\n");
}
pos = pos->next;
}
}
//停车场信息菜单
void park_menu(int m, int n)
{
printf("\n");
printf("********************************************************************************\n\n");
printf("停车场标准:\n\n");
printf(" --------停车场会员不收费:年卡破盘价只要6666,月卡破盘价只要998-------- \n\n");
printf(" 停车场收费标准:%d元/小时\n\n", m);
printf(" 停车场最多停 %d 辆车 \n\n",n);
printf("********************************************************************************\n");
}
int main()
{
struct list_head *vhead =malloc(sizeof(struct list_head));
vhead->next =vhead;
vhead->prev =vhead;
struct list_head* head =malloc(sizeof(struct list_head));
head->next =head;
head->prev =head;
while (1)
{
printf(" \033[47;35m********************欢迎进入停车场********************\033[0m \n");
printf(" \033[47;35m** 1、停车 **** 2、开车 **** 0、会员卡登记 **\033[0m \n");//设置标题
printf(" \033[47;35m******************************************************\033[0m \n");
int m = 0;
scanf("%d",&m);
if(m == 1) //循环体
{
int a = 0;
do
{ printf("\033[35m********************************欢迎进入停车系统********************************\033[0m\n");
printf("1、停车\t\t\t2、查看停车场最大停车位及收费标准\t\n3、查看已经停的普通车车\t\t4、查看已经停的会员车车\t\t5、退出\n"); //设置标题
pri
评论0