当前位置:文档之家› 停车场管理系统

停车场管理系统

停车场管理系统[实验目的]综合运用线性表、队列、排序、随机数等数据结构知识,掌握并提高分析、设计、实现及测试程序的综合能力。

[(1(2(3(4(5)对该停车场进行统计:统计每天到达、离开的车次,停车总时数、每天停车场的收入等。

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

一天以24小时计算。

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

#include <iostream>位private:bool biaozhi; //用来标识车位是否被占用int intime,outtime; //车位上的车辆的进站时间和出站时间int zongshijian,zongfeiyong; //该车位上总时间和产生的总费用int zongchel; //总共离开车辆数int chepai; //在该车位上停车的车辆的车牌号int alltime(); //总时间int allcost(); //总费用int allcar();};void chewei::incar(int cp,int sj){biaozhi=false;chepai=cp;intime=sj;cout<<"停车时间为: "<<time<<endl;cout<<"需缴纳停车费为: "<<feiyong<<endl<<endl; ofstream outfile("jilu.txt",ios::app);outfile<<"车牌号为: "<<chepai<<endl;outfile<<"进入车库时间为: "<<intime<<endl;outfile<<"离开车库时间为: "<<sj<<endl;outfile<<"停车时间为: "<<time<<endl;outfile<<"需缴纳停车费为: "<<feiyong<<endl<<endl;}int chewei::allcar (){return zongchel;}int chewei::tingliusj(int t){ //车辆停留的时间if(biaozhi==false)return t-intime;else位};class kycw{private:ky * head;int length;public:kycw(){length=0;head=new ky();}bool isempty(){return head->next==NULL;}if(p==NULL)head->next=new ky(item,NULL);else{ if(p->haoma>item)head->next=new ky(item,p);elsewhile((p->next!=NULL)&&(p->haoma<item)){p=p->next;}}int kycw::shanchu(){ //弹出最小的车位ky * p;length--;p=head->next;int a;a=p->haoma;head->next=p->next;next=nextnode;}node(int item,node *nextnode=NULL) {data=item;next=nextnode;}};length=0;}bool isempty() //判断便道是否为空{return head->next==NULL;}int changdu() //便道中剩余车辆{length++;while(p->next!=NULL)p=p->next;p->next=new node(cp,NULL);}int biandao::jinrucheku() //便道最前端的车进入停车位,记下车牌号{length--;int main(){int M=4;int N=2;chewei cw[4];biandao bd;kycw keyong;int chep[500];outfile<<" 每小时停车费用为: 30元"<<endl<<endl;for(i=0;i<M;i++)keyong.kongche(i);for(i=0;i<500;i++){chep[i]=i;}for(t=0;t<5;t++)时时{if(cw[m].tingliusj(t)==1){ //停车时间为一小时的车,25%离开车库i=rand()%4;if(i==0){cout<<"停车位为: "<<m<<endl;ofstream outfile("jilu.txt",ios::app);outfile<<"停车位为: "<<m<<endl;50%cout<<"停车位为: "<<m<<endl;ofstream outfile("jilu.txt",ios::app);outfile<<"停车位为: "<<m<<endl;cw[m].outcar(t);keyong.kongche(m);}}if(cw[m].tingliusj(t)==3){ //停车时间为三小时的车,75%离开车库}}if(cw[m].tingliusj(t)==4){ //停车时间为四小时的车,100%离开车库cout<<"停车位为: "<<m<<endl;ofstream outfile("jilu.txt",ios::app);outfile<<"停车位为: "<<m<<endl;cw[m].outcar(t);outfile<<"第"<<t<<"小时来停车场的车辆数量为: "<<j<<endl<<endl;if(number2<number1) //可用车位比便道中车辆数量多{for(i=0;i<number2;i++) //清空便道{c=bd.jinrucheku(); //取出从便道中进入车库的车牌number=keyong.shanchu(); //找到可用车位中号码最小的,并从可用车位中删除cw[number].incar(chep[cphao],t);cphao++;}}else{ //如果该小时来停车库的车辆比剩余可用车位多k=j-number1;for(i=0;i<number1;i++)if(i<N)bd.jinrubiandao(chep[cphao++]); //车辆进入便道if(i>=N){cout<<"本车库已满....请去其他停车场停车"<<endl;outfile<<"本车库已满....请去其他停车场停车"<<endl;}}牌number=keyong.shanchu(); //找到可用车位中号码最小的,并从可用车位中删除cw[number].incar(c,t); //将该车位状态更新}for(i=0;i<j;i++){if(i<N)bd.jinrubiandao(chep[cphao++]); //车辆进入便道if(i>=N){for(i=0;i<M;i++){Alltime=Alltime+cw[i].alltime();Allcost=Allcost+cw[i].allcost();Allcar=Allcar+cw[i].allcar();}cout<<"总共离开车辆数:"<<Allcar<<endl;cout<<"停车场总停车时间为: "<<Alltime<<endl; cout<<"停车场总营业额为: "<<Allcost<<endl;。

相关主题