数据结构课程设计-C语言停车场管理器|数据结构课程设计
/*******************************停车场管理器*************************************/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <conio.h>
/********************************************************************************/
#define MAXSTACKSIZE 2 /*车库容量*/
#define price 0.1 /*每车每分钟费用*/
typedef struct time{
int hour;
int min;
}Time; /*时间结点*/
typedef struct {
char num[10];
Time reach;
Time leave;
}CarNode; /*车辆信息结点*/
typedef struct {
CarNode *base;
CarNode *top;
int stacksize;
}SqStackCar; /*模拟车站*/
typedef struct car{
CarNode *data;
struct car *next;
}QueueNode;
typedef struct {
QueueNode *front;
QueueNode *rear;
}LinkQueueCar; /*模拟通道*/
int QueueEmpty(LinkQueueCar Q) /*便道判空函数*/
{
if(Q.front==Q.rear) return 1;
else return 0;
}
/********************************************************************************/
void InitStack(SqStackCar *s) /*初始化栈*/
{
s->base=(CarNode *)malloc(MAXSTACKSIZE*sizeof(CarNode));
if(!s->base) exit(0);/*分配失败*/
s->top=s->base;
s->stacksize=MAXSTACKSIZE;
}
int Push(SqStackCar *s,CarNode *e) /*进站函数*/
{
if(s->top-s->base>=s->stacksize) return 0;
else *s->top++=*e;
return 1;
}
int Pop(SqStackCar *s,CarNode *e) /*出站函数*/
{
if(s->top==s->base) return 0;
*e=*--s->top;
return 1;
}
int StackEmpty(SqStackCar s) /*判空函数*/
{
if(s.base==s.top) return 1;
else return 0;
}
int InitQueue(LinkQueueCar *Q) /*初始化便道*/
{
Q->front=Q->rear=(QueueNode *)malloc(sizeof(QueueNode));
if(!Q->front) exit(0);
Q->front->next=NULL;
return 1;
}
/**************************************************************/
int EnQueue(LinkQueueCar *Q,CarNode *e) /*便道插入函数*/
{
QueueNode *p;
p=(QueueNode *)malloc(sizeof(QueueNode));
if(!p) exit(0);
p->data=e;
p->next=NULL;
Q->rear->next=p;
Q->rear=p;
return 1;
}
int DeQueue(LinkQueueCar *Q,CarNode *e) /*便道删除函数*/
{
QueueNode *p;
if(Q->front==Q->rear) return 0;
p=Q->front->next;
e=p->data;
Q->front->next=p->next;
if(Q->rear==p) Q->rear=Q->front;
free(p);
return 1;
}
/********************************************************************************/
int Arrive(SqStackCar *In,LinkQueueCar *Wait) /*车辆到达函数*/
{
CarNode *i;
QueueNode *w;
i=(CarNode *)malloc(sizeof(CarNode));
flushall();
printf("Input the car number:");
gets(i->num);
if(In->top-In->base<MAXSTACKSIZE) /*车场未满,车辆进栈*/
{
printf("\nThe time the car arrive(00:00): ");
scanf("%d:%d",&i->reach.hour,&i->reach.min);
Push(In,i);
printf("\nCar in success!!");
sleep(1);
return 1;
}
else /*停车场已满,车进便道*/
{
w=(QueueNode *)malloc(sizeof(QueueNode));
w->data=i;
w->next=NULL;
Wait->rear->next=w;
Wait->rear=w;
printf("The PART is full,car must wait in the road!");
sleep(1);
return 1;
}
return 0;
}
/********************************************************************************/
int Departure(SqStackCar *In,SqStackCar *temp,LinkQueueCar *Wait) /*车辆离开函数*/
{
int flag=0,a1,a2,b1,b2, money;
CarNode *p,*t;
QueueNode *q;
p=(CarNode *)malloc(sizeof(CarNode));
flushall();
printf("Input the out car number: ");
gets(p->num);
while(!StackEmpty(*In))
{
t=(CarNode *)malloc(sizeof(CarNode));
Pop(In,t);
if(strcmp(p->num,t->num)==0) /*比较车场中有无这辆车,有即出站*/
{
printf("Input the time the car out(00:00):");
scanf("%d:%d",&p->leave.hour,&p->leave.min);
printf("The ");
printf("%s",p->num);
printf(" Car out the part!");
a1= p->leave.hour;
a2= t->reach.hour;
b1= p->leave.min;
b2= t->reach.min;
money = ((a1-a2+24)%24*60+(b1-b2+60)%60)*price; /*计算车辆需要的费用*/
printf("\nThe time the car arrive: %d:%d",t->reach.hour,t->reach.min);
printf("\nThe time the car leave: %d:%d",p->leave.hour,p->leave.min);
printf("\nNeed: %d yuan",money);
flag=1;
getch();
free(t);
break;
}
else
Push(temp,t);
} /*while*/
[1] [2] 下一页
数据结构课程设计-C语言停车场管理器下载如图片无法显示或论文不完整,请联系qq752018766