模拟停车场管理系统

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
cout<<"该停车场还有空位,请到"<<pos<<"号车位进行泊车"<<endl;
cout<<endl;
}
}
else
{
pos=pushqueue(cq,cnum,ctime);
cout<<"该停车场已满,请将车停在通道"<<pos<<"号车位上"<<endl;
cout<<endl;
}
}
void parkingmanagement::leave(carstack &cs,carqueue &cq,int cnum,double ctime)
friend calss parkingmanagement;
public;
carqueue();
int full();
car *front,*rear;
};
calss parkingmanagement{
public;
int pushstack(carstack &cs,int cnum,double ctime);
综合实验
——模拟停车场管理系统
1.实验目的
1.掌握Dev-C++环境下的编译、调试和执行的方法及步骤。
2.熟悉线性表、栈、队列、串、数组等线性结构的存储方式。
3.掌握利用数据结构综合处理非数值问题的方法。
2.实验内容
模拟停车场如下图所示
停车场是可停放n辆汽车的狭长通道,停车场内只有一条单行线通道可走车,有一个大门可供汽车进出。
(cq.rear)->next=p;
cq.rear=(cq.rear)->next;
}
countp=(cq.front)->next;
while(countp!=NULL)
{
count++;
countp=countp->next;
}
return count;
}
void parkingmanagement::popqueue(carqueue &cq){
{
int i;
car p;
carstack stemp;
for(i=0;i<=cs.top;i++)
if((cs.s[i]).number==cnum)break;
p=cs.s[i];
while(cs.top>i)
stemp.s[++(stemp.top)]=cs.s[(stemp.top)--];
public;
double time;//
int number;
car *next;
};
class carstack{
public calss parkingmanagement;
public;
carstack;
int empty();
int full();
car *s;
int top;
};
class carqueue{
hour=ctime-popstacktime;
outcarnum=popqueue(cq);
pstack=pushstack(cs,outcarnum,ctime);
cout<<"该车在本停车场内停留时间为"<<hour<<"分钟,应付金额"<<hour*(price/60)<<"元!"<<endl;
}
else
{
p=cq.front;
while(p!=NULL)
{
count++;
p=p->next;
if(p->number==cnum)
{
deletequeue(cq,count);
if(count>Max)
{
cout<<"haaaaa"<<count<<"haaaa"<<endl;
break;
}
popstacknumber=p.number;
popstacktime=p.time;
cs.top--;
whlie(stemp.top>=0)
cs.s[++(cs.top)]=stemp.s[(stemp.top)--];
}
void parkingmanagement::pushqueue(carqueue &cq,int cnum,double ctime)
{
car *pbData,*countp;
int count(1);
p=new car;
p->number=cnum;
p->time=ctime;
p->next=NULL;
if(cq.front==NULL)
{
cq.front=cq.rear=p;
}
else{
p->next=(cq.rear)->next;
car p;
p.number=((cq.front)->next)->time;
p.time=((cq.front)->next)->time;
p.next=((cq.front)->next)->time;
return p.number;
cq.front=(cq.front)->next;
}
void parkingmanagement::arrival(carstack &cs,carqueue &cq,int cnum,double ctime)
基本要求:
1.进站:若车场内已停满n辆汽车,则后来的汽车只能在门外通道上等候,一旦有车开走,则排在通道上的第一辆车即可开入。
2.出站:当停车场内某辆汽车要离开时,必须按它在停车场停留的时间长短缴纳费用;如果通道前面有汽车在缴纳费用,则要在Baidu Nhomakorabea后面排队等候。
3.假设出、入便道上一次只能排m辆汽车,本题按n=7,m=3进行模拟,时间计算到分钟,每小时停车费3元。
if(acc=='A')
park.arrival(cars,carq,carnum,cartime);
else if(acc=='D')
park.leave(cars,carq,carnum,cartime);
else if(acc=='E')
break;
else
cout<<"您输入有误,请重新输入!"<<endl;
void popstack(carstack &cs,int cnum);
int pushstack(carstack &cq,int cnum,double ctime);
int pushstack(carstack &cq,int cnum);
void arrival(carstack &cs,carqueue &cq,int cnum,double ctime);
{
if(cs.top==Max-1)
{
cout<<"停车场已满!"<<endl;
return Max;
}
else{
cs.top++;
(cs.s[cs.top]).number=cnum;
(cs.s[cs.top]).time=ctime;
return(cs.top+1);
}
}
}
void parkingmanagement::popstack(carstack &cs,int cnum)
{
int pos;
if(!(cs.full()))
{
int fl(0),i;
for(i=0;i<=cs.top;i++)
{
if(cs.s[i].number==cnum)
{
fl=1;
break;
}
}
if(fl==1)
{
cout<<"输入错误!请重新输入!"<<endl;
}
else
{
pos=pushstack(cs,cnum,ctime);
cout<<"= 3/hour;size:6="<<endl;
cout<<"= ="<<endl;
cout<<"= "<<endl;
cout<<"=A:到达;D:离去;E:退出;"<<endl;
cout<<"======================================"<<endl;
exit(1);
}
}
int carstack::full()
{
return top==Max-1;
}
carqueue::carqueue()
{
rear=front=NULL;
}
int parkingmanagement::pushstack(carstack &cs,int cnum,double ctime)
void deletequeue(carqueue &cq,int i);
int popstacknumber;
double popstacktime;
};
carstack::carstack(){
top=-1;
s=new car[Max];
if(s==NULL)
{
cout<<"栈空间分配不成功!"<<endl;
4.假设初始时停车场内停了6辆汽车,没有排队等候进站或出站的汽车。
3.概要设计
1.数据类型定义(含所用到的结构的表示及其基本操作)
#include <iostream>
using namespace std;
const int Max=6;
const double price=3;
class car{
}
}
if(p==NULL)
{
cout<<""<<endl;}
}
}
void parkingmanagement::deletequeue(carqueue &cq,int i)
{
car *p,*q;
int j(0);
p=cq.front;
while(p&&j<i-1)
{
p=p->next;
j++;
}
if(!p||!p->next)
}
2.主函数main设计
void main()
{
char acc;
int carnum;
double cartime;
parkingmangement park;
carstack cars;
carqueue carq;
while(1)
{
print();
cin>>acc>>carnum>>cartime;
}
}
4.测试结果
运行测试结果截图
5.实验过程遇到的问题和心得
附:完整源程序
{
cout<<"i不合法";}
else
{
q=p->next;
p->next=q->next;
delete q;
}
}
void print()
{
cout<<"======================================"<<endl;
cout<<"=welcome!="<<endl;
cont<<"= ="<<endl;
{
int i,flag(0),pstack,count(1),outcarnum;
double hour;
car *p;
for(i=0;i<=cs.top;i++)
if((cs.s[i].number)==cnum)
{
flag=1;
break;
}
if(flag)
{
popstack(cs,cnum);
相关文档
最新文档