停车场管理系统.docx

上传人:b****6 文档编号:7088115 上传时间:2023-01-17 格式:DOCX 页数:8 大小:16.61KB
下载 相关 举报
停车场管理系统.docx_第1页
第1页 / 共8页
停车场管理系统.docx_第2页
第2页 / 共8页
停车场管理系统.docx_第3页
第3页 / 共8页
停车场管理系统.docx_第4页
第4页 / 共8页
停车场管理系统.docx_第5页
第5页 / 共8页
点击查看更多>>
下载资源
资源描述

停车场管理系统.docx

《停车场管理系统.docx》由会员分享,可在线阅读,更多相关《停车场管理系统.docx(8页珍藏版)》请在冰豆网上搜索。

停车场管理系统.docx

停车场管理系统

停车场管理系统

[实验目的]

综合运用线性表、队列、排序、随机数等数据结构知识,掌握并提高分析、设计、实现及测试程序的综合能力。

[实验内容及要求]

停车场拥有M个车位和一条进入停车场的便道,便道上最多停放N辆汽车。

汽车要想进入车位,首先进入便道等候。

若有空闲车位,则停车入位,否则在便道继续等候,直至有车位空出。

若便道已经停满等候的汽车,后到达的汽车只能离开,选择其他停车场。

设计一个停车场管理系统,模拟停车场的运作,并统计停车场的收入。

(1)使用随机数产生某一时间段内进入和离开停车场的车辆数目;

(2)存储并记录如下数据项:

汽车到达和离去的时间及汽车的车号;

(3)车辆到达时,提示汽车的停车位置编号(为车辆分配编号最小的可用车位),若车位已满给出相应提示;

(4)汽车离去时,输出汽车在停车场内停留的时间和应交纳的费用。

(5)对该停车场进行统计:

统计每天到达、离开的车次,停车总时数、每天停车场的收入等。

[测试数据]

M=30,N=5,以1小时为时间的最小单位,每小时停车费30元,每小时到达的车辆数目在0-20辆之间均匀分布,车辆停留1小时后离开的概率是25%,每多停留1小时后离开概率增加25%,4小时后一定要离开。

一天以24小时计算。

[实现提示]

用队列模拟便道,可用车位需按照编号排序,申请车位时分配编号最小的车位,可用车位动态变化,选择排序方法时应考虑算法效率。

 

#include

#include

#include

#include

usingnamespacestd;

/****************************************车位*****************************************/

classchewei

{

private:

boolbiaozhi;//用来标识车位是否被占用

intintime,outtime;//车位上的车辆的进站时间和出站时间

intzongshijian,zongfeiyong;//该车位上总时间和产生的总费用

intzongchel;//总共离开车辆数

intchepai;//在该车位上停车的车辆的车牌号

inttime;//车辆停留时间

public:

chewei(){biaozhi=true;intime=0;zongshijian=0;zongfeiyong=0;zongchel=0;}

voidshezhibz(){biaozhi=false;}//判断该车位上是否有车

voidshezhicp(intcp){chepai=cp;}//车到来的时候将车牌号改为该车的车牌号

voidincar(intcp,intsj);//车辆进入

voidoutcar(intsj);//车辆出来

inttingliusj(intt);//查看该车的停留时间

intalltime();//总时间

intallcost();//总费用

intallcar();

};

voidchewei:

:

incar(intcp,intsj){

biaozhi=false;

chepai=cp;

intime=sj;

}

voidchewei:

:

outcar(intsj){

inttime,feiyong;

time=sj-intime;

feiyong=time*30;

biaozhi=true;

cout<<"车牌号为:

"<

cout<<"进入车库时间为:

"<

cout<<"离开车库时间为:

"<

cout<<"停车时间为:

"<

cout<<"需缴纳停车费为:

"<

ofstreamoutfile("jilu.txt",ios:

:

app);

outfile<<"车牌号为:

"<

outfile<<"进入车库时间为:

"<

outfile<<"离开车库时间为:

"<

outfile<<"停车时间为:

"<

outfile<<"需缴纳停车费为:

"<

zongshijian=zongshijian+time;

zongfeiyong=zongfeiyong+feiyong;

zongchel=zongchel+1;

}

intchewei:

:

allcost(){

returnzongfeiyong;

}

intchewei:

:

alltime(){

returnzongshijian;

}

intchewei:

:

allcar(){

returnzongchel;

}

intchewei:

:

tingliusj(intt){//车辆停留的时间

if(biaozhi==false)

returnt-intime;

else

return0;

}

/****************************************可用车位*****************************************/

structky{

inthaoma;

ky*next;

ky(ky*nextky=NULL){next=nextky;}

ky(intitem,ky*nextky){haoma=item;next=nextky;}

};

classkycw{

private:

ky*head;

intlength;

public:

kycw(){length=0;head=newky();}

boolisempty(){returnhead->next==NULL;}

voidkongche(intitem);//将空车位插入其中

intshanchu();//车位被占就从中删除它

intchangdu(){returnlength;}//空闲车位的总量

};

voidkycw:

:

kongche(intitem){//按照从小到大的顺序将空车位插入其中

ky*p,*q;

p=head->next;

length++;

if(p==NULL)

head->next=newky(item,NULL);

else{if(p->haoma>item)

head->next=newky(item,p);

else

while((p->next!

=NULL)&&(p->haoma

p=p->next;

}

if((p->next==NULL)&&(p->haoma>item)){

q=head->next;

while((q->next)->next!

=NULL)

q=q->next;

q->next=newky(item,p);

}

else

p->next=newky(item,p->next);

}

}

intkycw:

:

shanchu(){//弹出最小的车位

ky*p;

length--;

p=head->next;

inta;

a=p->haoma;

head->next=p->next;

returna;

}

/**********************************便道**********************************/

structnode

{

intdata;

node*next;

node(node*nextnode=NULL)

{

next=nextnode;

}

node(intitem,node*nextnode=NULL)

{

data=item;

next=nextnode;

}

};

classbiandao

{

private:

node*head;

intlength;

public:

biandao()

{

head=newnode();

length=0;

}

boolisempty()//判断便道是否为空

{

returnhead->next==NULL;

}

intchangdu()//便道中剩余车辆

{

returnlength;

}

voidjinrubiandao(intcp);//车辆进入便道

intjinrucheku();

};

voidbiandao:

:

jinrubiandao(intcp)//车辆进入便道

{

node*p;

p=head;

length++;

while(p->next!

=NULL)

p=p->next;

p->next=newnode(cp,NULL);

}

intbiandao:

:

jinrucheku()//便道最前端的车进入停车位,记下车牌号

{

length--;

node*p;

intc;

p=head;

c=p->next->data;

head->next=(p->next)->next;

returnc;

}

/******************************主程序*************************/

intmain()

{

intM=4;

intN=2;

cheweicw[4];

biandaobd;

kycwkeyong;

intchep[500];

intt,number,number1,number2,i,j,k,l,m,c,cphao;

cphao=1;

cout<

cout<<"车位数为:

4"<

cout<<"便道数为:

2"<

cout<<"每小时停车费用为:

30元"<

ofstreamoutfile("jilu.txt",ios:

:

app);

outfile<<"车位数为:

4"<

outfile<<"便道数为:

2"<

outfile<<"每小时停车费用为:

30元"<

for(i=0;i

keyong.kongche(i);

for(i=0;i<500;i++)

{

chep[i]=i;

}

for(t=0;t<5;t++)

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

当前位置:首页 > 工作范文 > 行政公文

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1