数据结构c语言版课程设计报告停车场管理系统.doc
《数据结构c语言版课程设计报告停车场管理系统.doc》由会员分享,可在线阅读,更多相关《数据结构c语言版课程设计报告停车场管理系统.doc(17页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、- .课程设计:停车场c语言版本的数据构造课程设计,要求用栈模拟停车场,用队列模拟便道,实现停车场的收费管理系统停车场停满车后车会停在便道上面下面附上源码,vc:(下编译#include /#include /malloc#include /获取系统时间所用函数 #include /getch()#include /设置光标信息 mallco#define MaxSize 5 /*定义停车场栈长度*/#define PRICE 0.05 /*每车每分钟收费值*/#define BASEPRICE 0.5 /根底停车费#define Esc 27 /退出系统#define Exit 3/完毕对话
2、#define Stop 1/停车#define Drive 2/取车int jx=0,jy=32; /全局变量日志打印位置typedef structint hour; int minute;Time,*PTime; /*时间结点*/typedef struct /*定义栈元素的类型即车辆信息结点*/int num ; /*车牌号*/ Time arrtime; /*到达时刻或离区时刻*/CarNode;typedef struct /*定义栈,模拟停车场*/CarNode stackMaxSize; int top;SqStackCar;typedef struct node /*定义队列
3、结点的类型*/int num; /*车牌号*/ struct node *next;QueueNode;typedef struct /*定义队列,模拟便道*/QueueNode *front,*rear;LinkQueueCar;/*函数声明*/PTime get_time();CarNode getcarInfo();void qingping(int a);void gotoxy(int x,int y);void printlog(Time t,int n,int io,char ab,int po,double f);void printstop(int a,int num,int
4、x0,int y0);void printleave(int a,int po,int num); /*初始化栈*/void InitSeqStack(SqStackCar *s) s-top=-1;/* push入站函数 */int push(SqStackCar *s,CarNode x) /数据元素x入指针s所指的栈if(s-top=MaxSize-1)return(0);/如果栈满,返回0elses-stack+s-top=x;/栈不满,到达车辆入栈return(1); /*栈顶元素出栈*/CarNode pop(SqStackCar *s) CarNode x;if(s-toptop
5、-;return(s-stacks-top+1); /栈不空,返回栈顶元素 /*初始化队列*/void InitLinkQueue(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保存队列中数据元素的个数 /*数据入队列*/void EnLinkQueue(LinkQueueCar *q,int x) QueueNode *p;p=(QueueNo
6、de*)malloc(sizeof(QueueNode); /产生一个新结点 p-num=x; p-next=NULL;q-rear-next=p; /新结点入队列 q-rear=p;q-front-num+; /队列元素个数加1 /*数据出队列*/ int DeLinkQueue(LinkQueueCar *q) QueueNode *p;int n;if(q-front=q-rear) /队空返回0return(0);elsep=q-front-next;q-front-next=p-next;if(p-next=NULL)q-rear=q-front;n=p-num;free(p);q-
7、front-num-;return(n); /返回出队的数据信息/* 车辆到达 */参数:停车栈 停车队列 车辆信息/返回值:空/功能:对传入的车辆进展入栈 栈满那么入队列void Arrive(SqStackCar *stop,LinkQueueCar *lq,CarNode x)int f;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);print
8、f(您的车停在便道%d号车位上n,lq-front-num);/更新对话elseprintstop(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中并出队,打印离开收费信息void Leave(Sq
9、StackCar *s1,SqStackCar *s2,LinkQueueCar *p,CarNode x)double fee=0;int position=s1-top+1; /车辆所在车位int n,f=0;CarNode y;QueueNode *q;while(s1-top -1)&(f!=1) /当栈不空且未找到xy=pop(s1);if(y.num!=x.num) n=push(s2,y);position-;elsef=1;if(y.num=x.num) /找到xgotoxy(33,17);printf(%d:%-2d,(x.arrtime.hour-y.arrtime.hou
10、r),(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
11、=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);elseprintleave(0,position,s1-top+2);printlog(x.arrtime,x.num,0,P,position,fee);else /假设栈中无x while(s2-top -1) /复原栈 y=pop(s2
12、); f=push(s1,y);q=p-front;f=0;position=1;while(f=0&q-next!=NULL) /当队不空且未找到xif(q-next-num!=x.num)q=q-next;position+;else /找到xq-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();
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据结构 语言版 课程设计 报告 停车场 管理 系统
限制150内