版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、精选问题描述: 设停车场内只有一个可停放 n 辆汽车的狭长通道, 且只有一个大门可以供汽车进 出。汽车在停车场内按照车辆到达的先后顺序,依次由北向南排列,大门在最南段。若停车 场内车位已经停满, 则后来的车位只能停在过道上等候。 一旦停车场内有车离开, 停靠在过 道上的车辆就能开进停车场停放。 根据每辆车在停车场的停靠时间计费。 请设计一个停车场 管理系统。实验代码如下: #include #include #include #include #include #include #include using namespacestd;#define MAXNUM 5 #define PRICE
2、 2.0 struct 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(
3、s- top= MAXNUM -1)return 1;elsereturn 0;void Stackpush(Seqstack*s,car car1)if(! Isfull (s)s- top+;s- carlists- top= car1;elsecout its full now carlists- 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/ st
4、ruct carnodecar data;struct carnode * next;struct carnodequeuecarnode * head;carnode * rear;void carnodequeueinit(carnodequeue* q)if(!(q-head= (carnode*)malloc(sizeof(carnode) cout failed to malloc! rear= q- head;q- head- next= NULL ;q- rear- next= NULL ;int carnodequeueisempty(carnodequeue*q)if(q-
5、rear= q- head)return 1;elsereturn 0;void carnodequeuein(carnodequeue*q,car cc)carnode *p;if(!(p=(carnode*)malloc(sizeof(carnode)cout failed 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
6、- 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+)cout ch;if(newline = 1)cout endl;/ print the time struct /void printdata(struct tm gm_data)cout gm_data.tm
7、_mon / gm_data.tm_mday gm_data.tm_hour +8 : gm_data.tm_min : gm_data.tm_sec endl; 精选/ show park /void showpark(Seqstack* s)struct tm gm;cout the park information is follow: endl; separator(40,-,1);if(Isempty(s)cout the park is empty ! endl;elsecout position number intime endl;for ( int i=0; i top;i+
8、)coutcarlisti.position ime);cout the total is top +1 cars. top = MAXNUM -1)cout and the park is full now! endl;elsecout and the park have top position is empty ! head- next;cout the ailse information is follow: endl; separator(30,-,1);cout number the intime endl; while(p != N
9、ULL ) cout data.num ime); p= p- next;精选elsecout the ailse is empty ! endl; separator(30,-,1); cout endl;/ 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(
10、& seconds);/get the timegm_data= gmtime(& seconds);cout the 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)cout the park if full,the car can only park int the ails
11、e . 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;Seqstackp;char nowtime 10;int i,pos;car cc;Stackinit(& p);if(Isempty(s)cout the park is empty,no car need to leave . endl;exit(0);elsecout
12、the park information is follow. endl;showpark(s);cout which one need to leave ? pos;if(pos 0 & pos top +1)for (i= s- top +1; i pos;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.o
13、utime)-mktime(&ime); cc.expense=( cc.length/3600 + 1)* PRICE ;cout the information which car is to leave is follow. endl; cout cc.num cc.length cc.expense endl;while(! Isempty (& p)cc= Stackpop(& p);Stackpush(s,cc); while(!Isempty(s) & ! carnodequeueisempty(q)cc= carnodequeueout(q); time(& sec
14、onds); gm_data= gmtime(& seconds); ime =* gm_data; Stackpush(s,cc);elsecout the car position is wrong! endl;主函数调用为:#include stdafx.h#include example34_car.hint main() SeqstackPark; carnodequeueAisle; Stackinit(& Park); carnodequeueinit(& Aisle); char choice;docout endl endl; separator(10,-,0);
15、cout the management of park endl; separator(30,-,1);cout 1. the car in endl;cout 2. the car out endl;cout 3. watch the park information endl;cout 0. exit endl; separator(56,-,1);cout the total is MAXNUM position and can park in the ailse if park is full .please choice choice; switch(choice)case1: In
16、 park (& Park,&Aisle);break; case2:0utpark (& Park,&Aisle);break; case3:showall( &Park, &Aisle);break; while (choice != 0);return 0;实验结果展示:S3*;1Qtotral ia 5 poa it ionand can park in tho ailao if papk iv full .plo菇choico2Dtv thepark iniFcmat ion io papk infornait ioni isFollow. Follou:Ipoo it i_onni
17、Ambel*int; ino1111115/1711:10:8222222S/1711:10:1135/1711:19:1444444445zi? 11:1S:1(5555555/1?11:10:1?ths芹0七乱19and the park i$ Full nov!kihich one nod to loavo ?C:Wi 1 d ows .syitemS 1 .Cmd .exeposition 11111* 22222p 33333*444444L SSbSSnumberint ine5/17 11:1O:B5/17 11:10:11517 11:10:14S/17 11:10:1GSZ1
18、7the total is carsknd the park is fullnauTFEB C:Wirdow5system32ctid.exethe nan ag erne nt of parkX- the car in Z_ the car out3 . LJd*tGh lio pai*k irff oinat: ion 0. exitbhlch one need to leaue ?9the informaticn which cav is to leave is follor kd333 55 2tbfinF xtarkL . * he c ar i.n*- the cat* out.a. uaC ch tlieinfiona. exithhn tota is % position anrt cap prk in the aiIse if park is fnIL .vlRase choiceC: W indcw5ys: eni M2errd.exeosit ion 11111:22222444444L 5555I GGG66number
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- GB/T 917-2026公路路线标识规则和国道编号
- T/SDJSXH 07-2024塔式起重机自动驾驶系统应用技术规程
- T/JX 001-2024喷水织机行业中水回用水质要求
- T/CCSAS 052-2025三氯氢硅还原法多晶硅生产安全技术规范
- T/CCPA 74-2025公路与市政工程预制混凝土构件智能工厂技术要求
- T/CSMT HJ005-2026产品碳足迹数据质量溯源性要求
- GB/T 48281-2026航空器操纵钢丝绳套管尺寸与载荷
- 2025~2026学年广西壮族自治区玉林市陆川县人教版六年级上册11月期中数学试卷【附答案】
- 甘肃省定西市2027届七上数学期末调研模拟试题含解析
- PHP常用复试面试题及详细答案(真实职场版)
- 阿拉善盟教师招聘真题2025
- 湖南省长沙市2026-2027学年高一上学期期中考试语文自编卷(范围:统编版必修一1-4单元)(原卷版)
- 2026年食品标签标识规范业务考试试卷试题及答案
- GJB 151C-2024 军用设备和分系统 电磁发射和敏感度要求与测量
- ISO9001-2026质量管理体系标准培训
- 2026版公路水运工程试验检测专业技术人员职业资格考试《桥隧工程一本通》
- IPC-JEDEC J-STD-020F-2024 中文版(非气密固态表面贴装器件的潮湿 - 再流焊敏感度分级)
- 2025浙江鹿城农商银行春季招聘笔试历年典型考题及考点剖析附带答案详解
- 高中英语U4-The-Words-That-Changed-A-Nation教学课件
- 新能源的风险与防范措施
- 《针灸治疗》课件-第十六节 网球肘
评论
0/150
提交评论