数据结构课程设计-停车场管理程序.docx_第1页
数据结构课程设计-停车场管理程序.docx_第2页
数据结构课程设计-停车场管理程序.docx_第3页
数据结构课程设计-停车场管理程序.docx_第4页
数据结构课程设计-停车场管理程序.docx_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

#include#include#include#include #define N 3/停车场最多停车数#define M 4/候车场内最多停车数#define Price 2/每单位停车费用typedef structint CarNoN;/车牌号double CarTimeN;/进场时间int top;/栈指针SqStack;/定义顺序栈指针类型typedef structint CarNoM;/车牌号int front, rear;/队首和队尾指针SqQueue;/定义循环队类型/以下为顺序栈的基本运算算法void InitStack(SqStack * &s)s = (SqStack *)malloc(sizeof(SqStack);s-top = -1;bool StackEmpty(SqStack *s)return(s-top = -1);bool StackFull(SqStack *s)return(s-top = N - 1);bool Push(SqStack * &s, int e1, double e2)if (s-top = N - 1)return false;s-top+;s-CarNos-top = e1;s-CarTimes-top = e2;printf(车牌号为%d正在进站n, e1);Sleep(500);printf(车牌号为%d进站成功n, e1);Sleep(500);return true;bool Push1(SqStack * &s, int e1, double e2)if (s-top = N - 1)return false;s-top+;s-CarNos-top = e1;s-CarTimes-top = e2;printf(车牌号为%d正在进入临时站n, e1);Sleep(500);printf(车牌号为%d进临时站成功n, e1);Sleep(500);return true;bool Pop1(SqStack * &s, int &e1, double &e2)if (s-top = -1)return false;e1 = s-CarNos-top;e2 = s-CarTimes-top;s-top-;printf(车牌号为%d正在出临时站n,e1);Sleep(500);printf(车牌号为%d出临时站成功n, e1);Sleep(500);return true;bool Pop(SqStack * &s, int &e1, double &e2)if (s-top = -1)return false;e1 = s-CarNos-top;e2 = s-CarTimes-top;s-top-;printf(车牌号为%d正在出站n, e1);Sleep(500);printf(车牌号为%d出站成功n, e1);Sleep(500);return true;void DispStack(SqStack *s)int i;for (i = s-top; i = 0; i-)printf(%d , s-CarNoi);printf(n);/以下为循环队列的基本运算算法void InitQueue(SqQueue * &q)q = (SqQueue *)malloc(sizeof(SqQueue);q-front = q-rear = 0;bool QueueEmpty(SqQueue *q)return(q-front = q-rear);bool QueueFull(SqQueue *q)return(q-rear + 1) % M = q-front);bool enQueue(SqQueue * &q, int e)if (q-rear + 1) % M = q-front)return false;q-rear = (q-rear + 1) % M;q-CarNoq-rear = e;return true;bool deQueue(SqQueue * &q, int &e)if (q-front = q-rear)return false;q-front = (q-front + 1) % M;e = q-CarNoq-front;return true;void DispQueue(SqQueue *q)int i;i = (q-front + 1) % M;printf(%d, q-CarNoi);while (q-rear - i + M) % M 0)i = (i + 1) % M;printf(%d, q-CarNoi);printf(n);void main()int comm;double e2, time;int no, e1;int i, j;int arrivehour10000, arrivemin10000,departhour10000,departmin10000;SqStack *St, *St1;SqQueue *Qu;InitStack(St);InitStack(St1);InitQueue(Qu);doprintf(*欢迎使用停车场管理程序系统*n);printf(* 温馨提示:停车每小时2元 *n);printf(* 不足1小时部分按1小时收费! *n);printf(* *n);printf(* 输入指令(1:到达 2:离开 3:停车场 4:候车场 0:退出)*n);printf(* *n);printf(* *n);printf(* *n);printf(* *n);printf(*n);scanf_s(%d, &comm);switch (comm)case 1:/汽车到达printf(请输入车号:);scanf_s(%d, &no);printf(请输入到达的时和分,用空格隔开:);scanf_s(%d%d, &arrivehourno, &arriveminno);time = (arrivehourno + (1.0*arriveminno / 60);if (!StackFull(St)/停车场不满Push(St, no, time);printf(停车场位置:%dn, St-top + 1);else/停车场满if (!QueueFull(Qu)enQueue(Qu, no);printf(候车场位置:%dn, Qu-rear);elseprintf(候车场位置已满,不能停车n);break;case 2:/汽车离开printf(请输入车号:);scanf_s(%d, &no);printf(请输入离开的时和分,用空格隔开:);scanf_s(%d%d, &departhourno, &departminno);time = (departhourno + (1.0*departminno / 60);for (i = 0; i top&St-CarNoi != no; i+);if (iSt-top)printf(未找到该编号的汽车n);elsefor (j = i; j top&St-top0 &i!=St-top; j+)Pop(St, e1, e2);Push1(St1, e1, e2);/倒车到临时栈Pop(St, e1, e2);/该汽车离开printf(正在为您计算费用,请稍候!n);Sleep(500);printf(%d汽车进站时间为:%d时%d分,离开时间为:%d时%d分,停车费用:%.2f,祝您一路顺风!n, no,arrivehourno,arriveminno,departhourno,departminno, ceil(time - e2)*Price);printf(n);while (!StackEmpty(St1)/将临时栈St1重新回到St中Pop1(St1, e1, e2);Push(St, e1, e2);if (!QueueEmpty(Qu)/队不空时,将队头进栈StdeQueue(Qu, e1);Push(St, e1, time);/以当前时间开始计费break;case 3:/显示停车场中的情况if (!StackEmpty(St)printf(停车中的车辆:n);/输出停车场中的车辆DispStack(St);elseprintf(停车场中无车辆n);break;case 4:/显示候车场中的情况if (!QueueEmpty(Qu)printf(候车场中的车辆:);/输出候车场中的车辆DispQueue(Qu);elseprintf(候车场中无车辆n);break;ca

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论