已阅读5页,还剩6页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
问题描述:设停车场内只有一个可停放n辆汽车的狭长通道,且只有一个大门可以供汽车进出。汽车在停车场内按照车辆到达的先后顺序,依次由北向南排列,大门在最南段。若停车场内车位已经停满,则后来的车位只能停在过道上等候。一旦停车场内有车离开,停靠在过道上的车辆就能开进停车场停放。根据每辆车在停车场的停靠时间计费。请设计一个停车场管理系统。实验代码如下:#include #include #include #include #include #include #include using namespace std;#define MAXNUM 5#define PRICE 2.0struct carchar num10;struct tm intime;struct tm outime;double expense;int length;int position;/the stack of car/typedef structcar carlistMAXNUM;int top;Seqstack;void Stackinit(Seqstack * s)s-top=-1;int Isempty(Seqstack * s)if(s-top=-1)return 1;elsereturn 0;int Isfull(Seqstack *s)if(s-top=MAXNUM-1)return 1;elsereturn 0;void Stackpush(Seqstack *s,car car1)if(! Isfull(s)s-top+;s-carlists-top=car1;elsecoutits full nowcarlists-top;s-top-;return car1;car Stackgettop(Seqstack *s)car car1;if(! Isempty(s)car1=s-carlists-top;return car1;/the queue of car int tunnel/struct carnodecar data;struct carnode *next;struct carnodequeuecarnode *head;carnode *rear;void carnodequeueinit(carnodequeue *q)if(!(q-head = (carnode *)malloc(sizeof(carnode)coutfailed to malloc!rear=q-head;q-head-next=NULL;q-rear-next=NULL;int carnodequeueisempty(carnodequeue *q)if(q-rear=q-head)return 1;elsereturn 0;void carnodequeuein(carnodequeue *q,car cc)carnode *p;if(!(p=(carnode *)malloc(sizeof(carnode)coutfailed to malloc!data=cc;p-next=NULL;q-rear-next=p;q-rear=p;car carnodequeueout(carnodequeue *q)carnode *p;car cc;if(q-head != q-rear)p=q-head-next;if(p-next=NULL)cc=p-data;q-rear=q-head;free(p);elseq-rear-next=p-next;cc=p-data;free(p);return cc;/ the separator of cout /void separator(int n,char ch,char newline)for(int i=0;in;i+)coutch;if(newline = 1)coutendl;/ print the time struct /void printdata(struct tm gm_data)coutgm_data.tm_mon/gm_data.tm_mday gm_data.tm_hour+8:gm_data.tm_min:gm_data.tm_secendl;/ show park /void showpark(Seqstack *s)struct tm gm;coutthe park information is follow:endl;separator(40,-,1);if(Isempty(s)coutthe park is empty !endl;elsecoutposition number intime endl;for(int i=0;itop;i+)coutcarlisti.position ime);cout the total is top+1 cars.top = MAXNUM-1)coutand the park is full now!endl;elsecoutand the park have top position is empty !head-next;cout the ailse information is follow: endl;separator(30,-,1);coutnumber the intime endl;while(p != NULL)ime);p=p-next;elsecoutthe ailse is empty !endl;separator(30,-,1);coutendl;/ show park and ailse /void showall(Seqstack *s,carnodequeue *q)showpark(s);showaisle(q);/ in park /void Inpark(Seqstack *s,carnodequeue *q)car cc;struct tm *gm_data;time_t seconds;time(&seconds); /get the timegm_data=gmtime(&seconds);coutthe number of car cc.num;ime=*gm_data;if(!Isfull(s) & carnodequeueisempty(q)cc.position=(s-top)+2;Stackpush(s,cc);showpark(s);else if(Isfull(s) | !carnodequeueisempty(q)coutthe park if full,the car can only park int the ailse .endl;cc.position=MAXNUM;carnodequeuein(q,cc);showall(s,q);/ the out park /void Outpark(Seqstack *s,carnodequeue *q)struct tm *gm_data;time_t seconds;Seqstack p;char nowtime10;int i,pos;car cc;Stackinit(&p);if(Isempty(s)coutthe park is empty,no car need to leave .endl;exit(0);elsecoutthe park information is follow.endl;showpark(s);coutwhich one need to leave ?pos;if(pos 0 & postop+1)for(i=s-top+1;ipos;i-)cc=Stackpop(s);cc.position=cc.position-1;Stackpush(&p,cc);cc=Stackpop(s);time(&seconds);gm_data = gmtime(&seconds);cc.outime=*gm_data;cc.length=mktime(&cc.outime)-mktime(&ime);cc.expense=(cc.length/3600 + 1)*PRICE;coutthe information which car is to leave is follow.endl;coutcc.num cc.length cc.expenseendl;while(! Isempty(&p)cc=Stackpop(&p);Stackpush(s,cc);while(!Isempty(s) & !carnodequeueisempty(q)cc=carnodequeueout(q);time(&seconds);gm_data=gmtime(&seconds);ime=*gm_data;Stackpush(s,cc);elsecoutthe car position is wrong!endl;主函数调用为:#include stdafx.h#include example34_car.hint main()Seqstack Park;carnodequeue Aisle;Stackinit(&Park);carnodequeueinit(&Aisle);char choice;do coutendlendl;separator(10,-,0);coutthe management of parkendl;separator(30,-,1);cout1. the car in endl;cout2. the car out endl;cout3. watch the park information endl;cout0. exitendl;separator(56,-,1);coutthe total is MAXNUM position
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年重庆市辅警笔试试题含答案
- 2025年中国铁塔招聘考试题库及答案
- 2025年5月铁路机车车辆驾驶人员考试题及参考答案
- 2025年企业级系统架构设计师高级认证考试试卷及答案
- 2025电线电缆购销合同范本
- 2025临时工作合同临时的劳动合同
- 2025短期个人信用贷款借款合同
- 2025协商解除劳动合同协议书样本
- 2025年下半年周口项城广播电视台招考易考易错模拟试题(共500题)试卷后附参考答案
- 2025年下半年吉林通化梅河口市人社局面向社会公开招聘76人易考易错模拟试题(共500题)试卷后附参考答案
- 中国建设银行建信消费金融有限责任公司招聘笔试真题2023
- 幼儿园课件运动项目知多少
- 18《我的白鸽》课件
- 2024年新人教版部编本一年级上册美术教学工作计划及教学进度2
- 危险作业清单
- 工业园标准化厂房建设工程监理投标大纲(框架结构 技术标)
- 产后束腹带的使用宣教课件
- 中国纺织文化智慧树知到期末考试答案章节答案2024年武汉纺织大学
- 金蝶云星空财务云整体解决方案
- 小程序用户协议和隐私条款
- 车辆GPS动态监控台账
评论
0/150
提交评论