停车场管理系统

#include “stdio.h”
#include “stdlib.h”
#include “string.h”
#include “conio.h”
int MAX; /定义一个全局变量用来存储车库最大容量/
float price;/每车每小时的费用/
typedef struct time
{
int hour;
int min;
}Time; /时间结点/
typedef struct node
{
char num[10];
Time reach;
Time leave;
}Car; /车辆信息结点/
typedef struct NODE
{
Car *stack[100];
int top;
}SqStack; /停车站/
typedef struct car
{
Car *data;
struct car *next;
}QNode;
typedef struct Node
{
QNode *head;
QNode *rear;
}LinkQueue; /通道/

void InitStack(SqStack *); /初始化栈/
int InitQueue(LinkQueue *); /初始化便道/
int arrive(SqStack *,LinkQueue *); /车辆到达/
void leave(SqStack *,SqStack *,LinkQueue *); /车辆离开/
void info(SqStack,LinkQueue); /显示停车场信息/
void PRINT(Car *p,int room);

void InitStack(SqStack *s) /初始化栈/
{
int i;
s->top=0;
for(i=0;i<=MAX;i++)
s->stack[s->top]=NULL;
}
int InitQueue(LinkQueue *Q) /初始化便道/
{
Q->head=(QNode *)malloc(sizeof(QNode));
if(Q->head!=NULL)
{
Q->head->next=NULL;
Q->rear=Q->head;
return(1);
}
else return(-1);
}

void main()
{
SqStack In,Out;
LinkQueue Wait;
int ch;
InitStack(&In); /初始化停车站/
InitStack(&Out); /初始化让路的临时栈/
InitQueue(&Wait); /初始化通道/
while(1)
{
printf(“--------------------欢迎使用停车场管理系统--------------------\n”);
printf(“请输入停车场的容量:”);
scanf(“%d”,&MAX);
printf(“请输入停车场的收费标准(元/小时):”);
scanf(“%f”,&price);
printf(“您输入的停车场容量为%d位,费用为%2.1f元/小时。\n”,MAX,price);
printf(“\n(1)车辆到达\n(2)车辆离开\n(3)停车场信息\n(4)退出系统\n请选择\n”);
while(1)
{
ch=getch();
switch(ch)
{
case 49:arrive(&In,&Wait);break; /车辆到达/
case 50:leave(&In,&Out,&Wait);break; /车辆离开/
case 51:info(In,Wait);break; /输出车站信息/
case 52:{printf(“谢谢使用!”);exit(0);} /退出主程序/
default:printf(“\n按键无效,请重新按键选择!”);
}/49-52分别表示“1”-“4”这四个按键的键值/
system(“CLS”);
printf(“--------------------欢迎使用停车场管理系统--------------------\n”);
printf(“\t,作者:周瑾,董名远 \n\n\n”);
printf(“您输入的停车场容量为%d位,费用为%2.1f元/小时。\n”,MAX,price);
printf(“\n(1)车辆到达\n(2)车辆离开\n(3)停车场信息\n(4)退出系统\n请选择\n”);
}
}
}

int arrive(SqStack *In,LinkQueue *W) /车辆到达/
{
Car *p;
QNode *t;
p=(Car *)malloc(sizeof(Car));
flushall();
printf(“\n停车场还有%d停车位(若停车位为0,车可先进入便道等待)”,MAX-In->top);
printf(“\n请输入车牌号码(例:湘D0734):”);
gets(p->num);
if(In->top<MAX) /停车场未满,车进车场/
{
In->top++;
printf(“\n停车的位置:%d号停车位。”,In->top);
printf(“\n请输入车到达的时间(格式“:”):”);
scanf(“%d:%d”,&(p->reach.hour),&(p->reach.min));
In->stack[In->top]=p;
printf(“请按任意键返回”);
getch();
return(1);
}
else /停车场已满,车进便道/
{
printf(“\n停车位已满,该车须在便道等待!”);
t=(QNode *)malloc(sizeof(QNode));
t->data=p;
t->next=NULL;
W->rear->next=t;
W->rear=t;
printf(“请按任意键返回”);
getch();
return(1);
}
}

void leave(SqStack *In,SqStack *Out,LinkQueue *W)
{ /车辆离开/
int room;
Car *p,*t;
QNode *q;
/判断车场内是否有车/
if(In->top>0) /有车/
{
while(1) /输入离开车辆的信息/
{
printf(“\n请输入车在停车场的位置(1-%d):”,In->top);
scanf(“%d”,&room);
if(room>=1&&room<=In->top) break;
}
while(In->top>room) /车辆离开/
{
Out->top++;
Out->stack[Out->top]=In->stack[In->top];
In->stack[In->top]=NULL;
In->top–;
}
p=In->stack[In->top];
In->stack[In->top]=NULL;
In->top–;
while(Out->top>=1)
{
In->top++;
In->stack[In->top]=Out->stack[Out->top];
Out->stack[Out->top]=NULL;
Out->top–;
}
PRINT(p,room);
/判断通道上是否有车及车站是否已满/
if((W->head!=W->rear)&&In->top<MAX) /便道的车辆进入停车场/
{
q=W->head->next;
t=q->data;
In->top++;
printf(“\n便道的%s号车进入车场第%d号停车位。”,t->num,In->top);
printf(“\n请输入现在的时间(格式“:”):”);
scanf(“%d:%d”,&(t->reach.hour),&(t->reach.min));
W->head->next=q->next;
if(q==W->rear) W->rear=W->head;
In->stack[In->top]=t;
free(q);
}
}
else printf(“\n停车场里没有车\n”); /没车/
printf(“请按任意键返回”);
getch();
}

void info1(SqStack *S) /列表输出车场信息/
{
int i;
if(S->top>0) /判断停车场内是否有车/
{
printf(“\n车场:”);
printf(“\n 位置 到达时间 车牌号\n”);
for(i=1;i<=S->top;i++)
{
printf(" %d\t",i);
printf(“%d:%d “,S->stack[i]->reach.hour,S->stack[i]->reach.min);
puts(S->stack[i]->num);
}
}
else printf(”\n停车场里没有车”);
}

void info2(LinkQueue *W) /显示便道信息/
{
QNode *p;
p=W->head->next;
if(W->head!=W->rear) /判断通道上是否有车/
{
printf(“\n便道中车辆的号码为:\n”);
while(p!=NULL)
{
puts(p->data->num);
p=p->next;
}
}
else printf(“\n便道里没有车\n”);
printf(“请按任意键返回”);
getch();
}

void info(SqStack S,LinkQueue W)
{
info1(&S); /显示停车场信息/
info2(&W); /显示停便道信息/
}

void PRINT(Car *p,int room) /输出停车站车的信息/
{
int A1,A2,B1,B2;
printf(“\n请输入车离开的时间(格式“:”):”);
scanf(“%d:%d”,&(p->leave.hour),&(p->leave.min));
printf(“\n车牌号码:”);
puts(p->num);
printf(“\n车到达的时间是: %d:%d”,p->reach.hour,p->reach.min);
printf(“车离开的时间是: %d:%d”,p->leave.hour,p->leave.min);
A1=p->reach.hour;
A2=p->reach.min;
B1=p->leave.hour;
B2=p->leave.min;
printf(“\n费用为: %2.1f元”,((B1-A1)+(B2-A2)/60.0)*price);
free§;
}

  • 24
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

@末之凉秋

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值