停车场管理系统程序设计.docx

上传人:b****4 文档编号:7018566 上传时间:2023-05-11 格式:DOCX 页数:17 大小:20.83KB
下载 相关 举报
停车场管理系统程序设计.docx_第1页
第1页 / 共17页
停车场管理系统程序设计.docx_第2页
第2页 / 共17页
停车场管理系统程序设计.docx_第3页
第3页 / 共17页
停车场管理系统程序设计.docx_第4页
第4页 / 共17页
停车场管理系统程序设计.docx_第5页
第5页 / 共17页
停车场管理系统程序设计.docx_第6页
第6页 / 共17页
停车场管理系统程序设计.docx_第7页
第7页 / 共17页
停车场管理系统程序设计.docx_第8页
第8页 / 共17页
停车场管理系统程序设计.docx_第9页
第9页 / 共17页
停车场管理系统程序设计.docx_第10页
第10页 / 共17页
停车场管理系统程序设计.docx_第11页
第11页 / 共17页
停车场管理系统程序设计.docx_第12页
第12页 / 共17页
停车场管理系统程序设计.docx_第13页
第13页 / 共17页
停车场管理系统程序设计.docx_第14页
第14页 / 共17页
停车场管理系统程序设计.docx_第15页
第15页 / 共17页
停车场管理系统程序设计.docx_第16页
第16页 / 共17页
停车场管理系统程序设计.docx_第17页
第17页 / 共17页
亲,该文档总共17页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

停车场管理系统程序设计.docx

《停车场管理系统程序设计.docx》由会员分享,可在线阅读,更多相关《停车场管理系统程序设计.docx(17页珍藏版)》请在冰点文库上搜索。

停车场管理系统程序设计.docx

停车场管理系统程序设计

一、停车场管理系统

1.1设计要求

1。

1.1问题描述

设计一个停车场管理系统,模拟停车场的运作,此程序具有以下功能:

1汽车到达,则显示汽车在停车场内或便道上的停车位置。

2若车离去,则显示汽车在停车场内停留的时间和应缴纳的费用(在便道上停留的时间不收费)。

1.1。

2基本要求

①要求以栈模拟停车场,以队列模拟车场外地便道,按照从终端读入的输入数据序列进行模拟管理。

2求处理的数据元素包括三个数据项:

汽车“到达”或“离去"信息.汽车牌照号码以及离去的时刻。

3要求栈以顺序结构实现,队列以链表实现。

1。

1.3测试数据

自行设计一组在停车场上停车的数据和便道上停车的数据.

1。

1.4实现提示

该停车场能容纳车辆的数量,便道上的停车数量。

车辆到达对应栈的入栈操作,车辆离开对应栈的出栈操作。

1。

2设计代码及注释

#include

#include

#include

#include〈dos。

h〉

#include

usingnamespacestd;

#definePASS20

#definePOT20

structpassLot//便道队列数据结构

{

intnum;//车位号

time_ttimep;//停车时间

intcarNum;//停车的车牌号码

};

structpotLot//停车场栈数据结构

intnum;

time_ttimep;

intcarNum;

};

voidprintLine()//打印下划线(作为主界面图表的框架)

cout〈<"\t\t\t___________________________________”<〈endl;

return;

voidprintStar()//打印星号

{

cout〈〈endl〈〈"\t\t******************************************************”<

}

classerroFull//停车位满时异常类

{public:

erroFull()

system("color3c");

voidex()

{

cout〈

!

停车场位已满!

”〈〈endl;

_sleep(2000);

}

~erroFull(){}

};

classerroEmp//停车位空时异常类

{public:

erroEmp()

{

system("color3c”);

}

voidex()

{

cout<〈”!

停车场位为空!

”〈〈endl;

_sleep(2000);

~erroEmp(){}

};

classparkingLot//停车场类

{

public:

parkingLot()

{

passLot*pa;//便道停车位指针

potLot*po;//停车场停车位指针

flag=0;//用来记忆队列(便道)中停车的数量

rear=front=0;//初始化队列头尾

base=0;

top=base;//初始化栈头尾

inti=0;//初始化停车场和便道空间以及车位号

for(;i〈POT;i++)

pa=(passLot*)malloc(sizeof(passLot));

a[i]=pa;

a[i]-〉num=i+1;

a[i]->carNum=0;

po=(potLot*)malloc(sizeof(potLot));

b[i]=po;

b[i]->num=i+1;

b[i]->carNum=0;

}

}

~parkingLot()

{

cout〈〈”\t\t停车场数据已清空.”〈〈endl;

}

voidpassLG()//便道管理函数

{

try

{

if(flag==20)throwerroFull();//如果停车位已满,则抛出车位慢得异常情况

system(”cls”);

printStar();

cout<<"\t\t\t\t您进入了便道停车界面”〈

cout〈〈endl〈〈”\t\t\t便道停车场共有20个车位,现共停"<

cout<〈"\t\t\t请输入将要停车的号码:

";

cin>>a[rear]-〉carNum;

a[rear]—>timep=time(NULL);

cout<

汽车停放在"〈

!

"<

rear=(rear+1)%PASS;

flag++;

_sleep(1000);

}

catch(erroFull&err)

err。

ex();

voidpotLG()//停车场管理函数

try

{

if(top==20)throwerroFull();

system("cls”);

printStar();

cout〈<”\t\t\t\t您进入了停车场停车界面"<〈endl;

cout〈〈endl〈<”\t\t\t停车场共有20个车位,现共停"〈〈top〈〈”个车位。

”〈〈endl<

cout<〈"\t\t\t请输入将要停车的号码:

";

cin〉>b[top]->carNum;

b[top]—〉timep=time(NULL);

cout<〈endl<〈”\t\t\t!

!

汽车停放在”<〈b[top]-〉num〈<"车位成功,系统将在一秒后返回上层界面!

”〈

top++;

_sleep(1000);

}

catch(erroFull&err)

err.ex();

voidarrive()//汽车到达

{

intchoice=—1;

if(top==20&&flag==20)throwerroFull();

for(;;)

{

system(”cls");

printStar();

cout<〈”\t\t\t\t欢迎进入停车场"〈〈endl〈〈endl;

printLine();

cout〈<”\t\t\t|1.停车场停车\t\t\t|”〈〈endl;/*打印两个空格*/

printLine();

cout<<"\t\t\t|2。

便道停车\t\t\t|"〈〈endl;

printLine();

cout<<"\t\t\t|3.返回\t\t\t|”<

printLine();

printStar();

cout<<”\t\t请输入你的选项:

”;

cin>〉choice;

switch(choice)

{

case1:

potLG();break;

case2:

passLG();break;

case3:

break;

default:

system(”color3c");cout〈〈endl<<"\t\t\t\t输入格式不正确!

”〈〈endl;

_sleep(1000);break;

if(choice==3)break;

return;

}

intfeep(time_t*tmp)//费用计算

{

intgap=0,m=0,hour=0,min=0,sec=0;//设置数据用来计算时间间隔,停车时、分、秒.

local=localtime(tmp);//将存储的时间转化为当地时间日历

cout〈

”<tm_min<〈":

<〈local—>tm_sec〈

hour=local->tm_hour;//保存停车时刻

min=local->tm_min;

sec=local->tm_sec;

now=time(NULL);

nowp=localtime(&now);

cout<〈”\t当前时间为:

"〈〈nowp—>tm_hour<<”:

"〈〈nowp—>tm_min<〈”:

"

〈〈nowp—>tm_sec〈

hour=nowp->tm_hour—hour;//求出停车的时间间隔

min=nowp—〉tm_min-min;

sec=nowp->tm_sec-sec;

if(sec<0){min——;sec=60+sec;}//进行秒、分钟、秒时间转换

if(min〈0){hour——;min=60+min;}

cout〈〈"\t汽车共停了"〈〈hour〈<"小时"〈〈min<〈"分"<

if((0!

=min)||(0!

=sec))m=1;

gap=hour+m;//停车应收费的时间(单位:

小时)

returngap;

}

voidpassOut()//便道离开

try

{

if(flag==0)throwerroEmp();

intfee=0;

system("cls");

printStar();

cout〈〈"\t\t\t\t您进入了便道离开界面”<

cout〈

"

〈〈endl<〈endl;

cout〈<”\t\t\t将要离开车的信息为:

”<〈endl;

cout<<”\t车牌号码:

"〈〈a[front]->carNum〈<"\t车位:

便道"<

〈<”号\t\t停车时间:

";

fee=feep(&a[front]-〉timep)*0;

cout〈〈”\t该车应缴纳停车费为:

”<

<〈”元(便车道停车免费)"〈

a[front]->carNum=0;

front=(front+1)%PASS;

flag—-;

cout〈〈endl〈〈"\t\t\t!

汽车离开成功,按任意键返回!

!

"<

system(”pause");

}

catch(erroEmp&err)

{

err。

ex();

}

voidpotOut()//停车场离开

{

try

if(top==0)throwerroEmp();

intfee=0;

top-—;

system(”cls");

printStar();

cout<〈"\t\t\t\t您进入了停车场离开界面"〈〈endl;

cout〈

cout<〈"\t\t\t将要离开车的信息为:

"<〈endl;

cout<〈"\t车牌号码:

"<carNum<<”\t车位:

停车场"<num

〈〈"号\t\t停车时间:

";

fee=feep(&b[top]-〉timep)*8;//计费公式,每小时8元

cout<<”\t该车应缴纳停车费为:

”〈

<〈”元(每小时8元,不足一小时按一小时计算)”〈

b[top]—>carNum=0;

cout〈〈endl〈<”\t\t\t!

!

汽车离开成功,按任意键返回!

"〈

system(”pause");

}

catch(erroEmp&err)

{

err。

ex();

}

voiddepart()//汽车离开

intchoice=—1;

if(top==0&&flag==0)throwerroEmp();

for(;;)

system(”cls");

system("color3a");

printStar();

cout<<"\t\t\t\t欢迎下次光临停车场"<〈endl〈〈endl;

printLine();

cout〈〈”\t\t\t|1.停车场离开\t\t\t|"〈〈endl;/*打印两个空格*/

printLine();

cout<〈”\t\t\t|2。

便道离开\t\t\t|"〈〈endl;

printLine();

cout〈〈"\t\t\t|3。

返回\t\t\t|"<〈endl;

printLine();

printStar();

cout<<”\t\t请输入你的选项:

”;

cin〉〉choice;

switch(choice)

case1:

potOut();break;

case2:

passOut();break;

case3:

break;

default:

system("color3c”);cout〈

”〈〈endl;

_sleep(1000);break;

if(choice==3)break;

return;

}

voidsearchNum()//查询车牌号码

{

intnumCar,i=0,flag=1;

cout〈<”\t\t\t请输入车牌号码:

”;

cin>>numCar;

for(;i〈PASS;i++)

if(a[i]-〉carNum==numCar){

cout<num<〈"位”<〈endl;

flag=0;

if(flag)for(i=0;i〈POT;i++)

{

if(b[i]—〉carNum==numCar){

cout〈〈endl<<"\t\t\t车牌号为”〈〈numCar<〈”的车子停在停车道”〈〈b[i]—>num〈〈”位”〈〈endl;

flag=0;

}

if(flag)cout〈

"〈〈endl;

system("pause");

voidsearchPot()

intpotCar,nn;

cout〈〈”\t\t操作说明:

按照停车类型加位置来输入所要查找的车位信息\n\t\t如:

停车场10号位,即输入110。

停车场三号位,103。

便道场5号位,205"〈〈endl;

cout<<"\t\t请输入需要操作的序数:

";

cin〉>potCar;

if((potCar<121&&potCar〉100)||(potCar<221&&potCar>200)){

if(potCar/100==1){

nn=potCar%100—1;

if(b[nn]—>carNum==0)cout<〈”\t\t你说查询的车位没有停车"<〈endl;

elsecout<〈"停车场"〈〈nn<〈"车位停车的车牌号是:

"〈carNum〈

if(potCar/100==2){

nn=potCar%100-1;

if(a[nn]—〉carNum==0)cout〈〈"\t\t你说查询的车位没有停车"<

elsecout<<”便车道”<

"<〈a[nn]—〉carNum<

}

elsecout<〈"\t\t您所输入的数字不正确!

”〈

system("pause");

voidsearch()//号码查询

{

intchoice=-1;

if(top==0&&flag==0)throwerroEmp();

for(;;)

{

system(”cls”);

system("color3a");

printStar();

cout<<"\t\t\t\t您进入了号码查询界面”<〈endl<

printLine();

cout〈〈”\t\t\t|1。

根据车牌号码查询\t\t|”〈〈endl;/*打印两个空格*/

printLine();

cout〈<”\t\t\t|2.直接查询指定车位\t\t|"〈

printLine();

cout<〈"\t\t\t|3.返回\t\t\t|"<〈endl;

printLine();

printStar();

cout<〈"\t\t请输入你的选项:

”;

cin〉>choice;

switch(choice)

{

case1:

searchNum();break;

case2:

searchPot();break;

case3:

break;

default:

system(”color3c");cout<〈endl〈〈"\t\t\t\t输入格式不正确!

"〈

_sleep(1000);break;

}

if(choice==3)break;

}

return;

}

private:

intflag,front,rear,top,base;//设置访问栈和队列

passLot*a[PASS];//以顺序方式存储栈和队列,并且都设为20个车位

potLot*b[POT];

tm*local,*nowp;

time_tnow;//设置时间型变量

};//停车场类结束

voidmain()//程序运行主函数

parkingLota;

intchoice=—1;

for(;;)//使主界面能够自动初始化和重复使用

{system("cls");

system(”color3a");//设为主背景为湖蓝色

printStar();

cout<〈”\t\t\t\t欢迎进入停车场管理系统"〈〈endl<〈endl;

time_tt;//时间结构或者对象

t=time(NULL);//获取当前系统的日历时间

cout<<"\t\t\t\t\t\t”<

printLine();

cout<〈”\t\t\t|1。

汽车到达\t\t\t|”<

printLine();

cout〈<"\t\t\t|2.汽车离去\t\t\t|”〈〈endl;

printLine();

cout〈<”\t\t\t|3.汽车牌号查询\t\t\t|”〈

printLine();

cout<<”\t\t\t|4.退出管理系统\t\t\t|"〈〈endl;

printLine();

printStar();

cout〈<”\t\t请输入你的选项:

";

cin〉〉choice;

switch(choice)

{

case1:

try{

a。

arrive();

catch(erroFull&erro)

erro。

ex();

}

break;

case2:

a.depart();break;

case3:

a.search();break;

case4:

break;

default:

system("color3c");cout<〈endl<〈”\t\t\t\t输入格式不正确!

"〈〈endl;

_sleep(2000);;break;

if(choice==4)break;

}

return;

1。

3测试结果以及运行情况

1.3。

1运行主界面

1.3.2汽车到达界面

1.3.2。

1停车场停车测试界面

测试数据(按输入的先后排序)

表1

序号

1

2

3

4

5

6

7

8

9

10

牌照号

2001

2002

2003

2004

2005

2006

2007

2008

2009

2010

序号

11

12

13

14

15

16

17

18

19

20

牌照号

2011

2012

2013

2014

2015

2016

2017

2018

2019

2020

输入情况界面(部分)

异常情况处理,当停车场已经满20位时,便抛出异常(界面显示为红色,并停止工作)

1。

3。

2.2便车道停车测试

测试数据

表2

序号

1

2

3

4

5

6

7

8

9

10

牌照号

3001

3002

3003

3004

3005

3006

3007

3008

3009

3010

序号

11

12

13

14

15

16

17

18

19

20

牌照号

3011

3012

3013

3014

3015

3016

3017

3018

3019

3020

输入界面(部分)

异常情况处理,当停车场已经满20位时,便抛出异常(界面显示为红色,并停止工作)

1.3.3汽车离开界面

1.3.3.1停车场离开界面

当停车场为空时,抛出异常为空(颜色变红)

1.3。

3。

2便车道离开界面

当便车道为空时,抛出异常为空(颜色变红)

1.3。

4号码查询界面

1。

3。

4.1根据车牌号码查询

1。

3。

4。

2直接查询指定车位界面

1。

4评估与改进

1.4。

1评估

该系统能够完成题目要求的几项基本操作以及显示结果,并且显示的信息完全正确.在此基础上还加上了异常处理机制以及由异常处理导致的终端显示变异功能,同时在查询方面不仅完成了输入车牌号码查询功能,还能实现查找特定车位上停车情况的功能.

实验基本达到要求。

1。

4.2改进

真正的停车场不可能只按栈或者队列的顺序来停车,故此系统具有一定的局限性。

应根据停车场的具体情况对停车储存方式进行灵活地改善.

代码也比较冗余,希望能够不断简化。

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > IT计算机 > 电脑基础知识

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2