数据结构c语言版课程设计停车场管理系统样本.docx
《数据结构c语言版课程设计停车场管理系统样本.docx》由会员分享,可在线阅读,更多相关《数据结构c语言版课程设计停车场管理系统样本.docx(22页珍藏版)》请在冰豆网上搜索。
数据结构c语言版课程设计停车场管理系统样本
课程设计:
停车场
c语言版本的数据结构课程设计,要求用栈模拟停车场,用队列模拟便道,实现停车场的收费管理系统
停车场停满车后车会停在便道上面
下面附上源码,vc:
(下编译
#include
//#include//malloc
#include//获取系统时间所用函数
#include//getch()
#include//设置光标信息mallco
#defineMaxSize5/*定义停车场栈长度*/
#definePRICE0.05/*每车每分钟收费值*/
#defineBASEPRICE0.5//基础停车费
#defineEsc27//退出系统
#defineExit3//结束对话
#defineStop1//停车
#defineDrive2//取车
intjx=0,jy=32;//全局变量日志打印位置
typedefstruct
{inthour;
intminute;
}Time,*PTime;/*时间结点*/
typedefstruct/*定义栈元素的类型即车辆信息结点*/
{intnum;/*车牌号*/
Timearrtime;/*到达时刻或离区时刻*/
}CarNode;
typedefstruct/*定义栈,模拟停车场*/
{CarNodestack[MaxSize];
inttop;
}SqStackCar;
typedefstructnode/*定义队列结点的类型*/
{intnum;/*车牌号*/
structnode*next;
}QueueNode;
typedefstruct/*定义队列,模拟便道*/
{QueueNode*front,*rear;
}LinkQueueCar;
/*函数声明*/
PTimeget_time();
CarNodegetcarInfo();
voidqingping(inta);
voidgotoxy(intx,inty);
voidprintlog(Timet,intn,intio,charab,intpo,doublef);
voidprintstop(inta,intnum,intx0,inty0);
voidprintleave(inta,intpo,intnum);
/*初始化栈*/
voidInitSeqStack(SqStackCar*s)
{
s->top=-1;
}
/*push入站函数*/
intpush(SqStackCar*s,CarNodex)//数据元素x入指针s所指的栈
{
if(s->top==MaxSize-1)
return(0);//如果栈满,返回0
else
{
s->stack[++s->top]=x;//栈不满,到达车辆入栈
return
(1);
}
}
/*栈顶元素出栈*/
CarNodepop(SqStackCar*s)
{
CarNodex;
if(s->top<0)
{
x.num=0;
x.arrtime.hour=0;
x.arrtime.minute=0;
return(x);//如果栈空,返回空值
}
else
{
s->top--;
return(s->stack[s->top+1]);//栈不空,返回栈顶元素
}
}
/*初始化队列*/
voidInitLinkQueue(LinkQueueCar*q)
{
q->front=(QueueNode*)malloc(sizeof(QueueNode));//产生一个新结点,作头结点
if(q->front!
=NULL)
{
q->rear=q->front;
q->front->next=NULL;
q->front->num=0;//头结点的num保存队列中数据元素的个数
}
}
/*数据入队列*/
voidEnLinkQueue(LinkQueueCar*q,intx)
{
QueueNode*p;
p=(QueueNode*)malloc(sizeof(QueueNode));//产生一个新结点
p->num=x;
p->next=NULL;
q->rear->next=p;//新结点入队列
q->rear=p;
q->front->num++;//队列元素个数加1
}
/*数据出队列*/
intDeLinkQueue(LinkQueueCar*q)
{
QueueNode*p;
intn;
if(q->front==q->rear)//队空返回0
return(0);
else
{
p=q->front->next;
q->front->next=p->next;
if(p->next==NULL)
q->rear=q->front;
n=p->num;
free(p);
q->front->num--;
return(n);//返回出队的数据信息
}
}
/*********************车辆到达***************************/
//参数:
停车栈停车队列车辆信息
//返回值:
空
//功能:
对传入的车辆进行入栈栈满则入队列
voidArrive(SqStackCar*stop,LinkQueueCar*lq,CarNodex)
{
intf;
f=push(stop,x);//入栈
if(f==0)//栈满
{
EnLinkQueue(lq,x.num);//入队
printstop(1,lq->front->num,0,23);
printlog(x.arrtime,x.num,1,'B',lq->front->num,0);
qingping(0);printf("您的车停在便道%d号车位上\n",lq->front->num);//更新对话
}
else
{
printstop(0,stop->top+1,0,23);
printlog(x.arrtime,x.num,1,'P',stop->top+1,0);
qingping(0);printf("您的车停在停车场%d号车位上\n",stop->top+1);//更新对话
}
qingping
(1);printf("按任意键继续");
getch();
}
/**************************车辆离开*************************************/
//参数:
停车栈指针s1,暂存栈指针s2,停车队列指针p,车辆信息x
//返回值:
空
//功能:
查找栈中s1的x并出栈,栈中没有则查找队p中并出队,打印离开收费信息
voidLeave(SqStackCar*s1,SqStackCar*s2,LinkQueueCar*p,CarNodex)
{
doublefee=0;
intposition=s1->top+1;//车辆所在车位
intn,f=0;
CarNodey;
QueueNode*q;
while((s1->top>-1)&&(f!
=1))//当栈不空且未找到x
{
y=pop(s1);
if(y.num!
=x.num)
{
n=push(s2,y);
position--;
}
else
f=1;
}
if(y.num==x.num)//找到x
{
gotoxy(33,17);printf("%d:
%-2d",(x.arrtime.hour-y.arrtime.hour),(x.arrtime.minute-y.arrtime.minute));
fee=((x.arrtime.hour-y.arrtime.hour)*60+(x.arrtime.minute-y.arrtime.minute))*PRICE+BASEPRICE;
gotoxy(48,17);printf("%2.1f元\n",fee);
qingping(0);printf("确认您的车辆信息");
qingping
(1);printf("按任意键继续");
getch();
while(s2->top>-1)
{y=pop(s2);
f=push(s1,y);
}
n=DeLinkQueue(p);
if(n!
=0)
{
y.num=n;
y.arrtime=x.arrtime;
f=push(s1,y);
printleave(p->front->num+1,position,s1->top+1);//出栈动画ji队列成员入栈
printlog(x.arrtime,x.num,0,'P',position,fee);
printlog(y.arrtime,y.num,1,'P',s1->top+1,0);
}
else
{
printleave(0,position,s1->top+2);
printlog(x.arrtime,x.num,0,'P',position,fee);
}
}
else//若栈中无x
{
while(s2->top>-1)//还原栈
{
y=pop(s2);
f=push(s1,y);
}
q=p->front;
f=0;
position=1;
while(f==0&&q->next!
=NULL)//当队不空且未找到x
if(q->next->num!
=x.num)
{
q=q->next;
position++;
}
else//找到x
{
q->next=q->next->next;
p->front->num--;
if(q->next==NULL)
p->rear=p->front;
gotoxy(33,17);printf("0:
0");
gotoxy(48,17);printf("0元");
qingping(0);printf("您的车将离便道");
qingping
(1);printf("按任意键继续");
getch();
printleave(-1,position,p->front->num+1);//出队动画
printlog(x.arrtime,x.num,0,'B',position,0);
f=1;
}
if(f==0)//未找到x
{
qingping(0);printf("停车场和便道上均无您的车");