数据结构c语言版课程设计停车场管理系统.doc
《数据结构c语言版课程设计停车场管理系统.doc》由会员分享,可在线阅读,更多相关《数据结构c语言版课程设计停车场管理系统.doc(14页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、数据结构c语言版课程设计停车场管理系统 课程设计:停车场c语言版本的数据结构课程设计,要求用栈模拟停车场,用队列模拟便道,实现停车场的收费管理系统停车场停满车后车会停在便道上面下面附上源码,vc:(下编译include stdio.h /#include /获取系统时间所用函数 #include /getch()include windows.h /设置光标信息 mallcodefine MaxSize 5 /*定义停车场栈长度/define PRICE 0.05 /*每车每分钟收费值/#define BASEPRICE 0。5 /基础停车费#define Esc 27 /退出系统#defin
2、e Exit 3/结束对话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 x0,
4、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=MaxSize1)return(0);/如果栈满,返回0elses-stack+stop=x;/栈不满,到达车辆入栈return(1); /*栈顶元素出栈/CarNode pop(SqStackCar *s) CarNode x;if(stoptop+1); /栈不
5、空,返回栈顶元素 /初始化队列/void InitLinkQueue(LinkQueueCar *q) qfront=(QueueNode)malloc(sizeof(QueueNode)); /产生一个新结点,作头结点if(q-front!=NULL)q-rear=qfront;qfrontnext=NULL;qfront-num=0; /头结点的num保存队列中数据元素的个数 /数据入队列/void EnLinkQueue(LinkQueueCar q,int x) QueueNode p;p=(QueueNode*)malloc(sizeof(QueueNode)); /产生一个新结点
6、pnum=x; pnext=NULL;qrearnext=p; /新结点入队列 q-rear=p;q-frontnum+; /队列元素个数加1 /*数据出队列/ int DeLinkQueue(LinkQueueCar q) QueueNode *p;int n;if(qfront=q-rear) /队空返回0return(0);elsep=q-frontnext;qfrontnext=p-next;if(p-next=NULL)qrear=qfront;n=pnum;free(p);q-frontnum-;return(n); /返回出队的数据信息/* 车辆到达 */参数:停车栈 停车队列
7、车辆信息/返回值:空/功能:对传入的车辆进行入栈 栈满则入队列void Arrive(SqStackCar *stop,LinkQueueCar *lq,CarNode x)int f;f=push(stop,x); /入栈if (f=0) /栈满EnLinkQueue(lq,x.num); /入队 printstop(1,lqfront-num,0,23);printlog(x。arrtime,x。num,1,B,lqfront-num,0); qingping(0);printf(您的车停在便道d号车位上n”,lqfront-num);/更新对话elseprintstop(0,stop-t
8、op+1,0,23);printlog(x.arrtime,x.num,1,P,stoptop+1,0);qingping(0); printf(您的车停在停车场d号车位上n”,stoptop+1);/更新对话qingping(1);printf(按任意键继续”);getch();/* 车辆离开 */参数:停车栈指针s1,暂存栈指针s2,停车队列指针p,车辆信息x/返回值:空/功能:查找栈中s1的x并出栈,栈中没有则查找队p中并出队,打印离开收费信息void Leave(SqStackCar s1,SqStackCar *s2,LinkQueueCar *p,CarNode x)double
9、fee=0;int position=s1top+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。hour),(x。arrtime。minutey。arrtime。minute) );fee=(x.arrtime。hour-
10、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(s2top1) 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-frontnum+1,po
11、sition,s1-top+1); /出栈动画ji队列成员入栈printlog(x。arrtime,x.num,0,P,position,fee);printlog(y.arrtime,y.num,1,P,s1top+1,0);elseprintleave(0,position,s1top+2);printlog(x.arrtime,x。num,0,P,position,fee);else /若栈中无x while(s2top -1) /还原栈 y=pop(s2); f=push(s1,y);q=pfront;f=0;position=1;while(f=0&q-next!=NULL) /当队
12、不空且未找到xif(qnextnum!=x.num)q=q-next;position+;else /找到xqnext=q-next-next;p-front-num-;if(q-next=NULL)p-rear=pfront;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。nu
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据结构 语言版 课程设计 停车场 管理 系统
限制150内