首页 > 编程 > C++ > 正文

C++实现停车场管理系统

2020-01-26 13:48:55
字体:
来源:转载
供稿:网友

本文实例为大家分享了停车场管理系统的具体代码,供大家参考,具体内容如下

#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<cstdlib>#include<algorithm>#include<queue>#include<vector>#include<stack>#include<map>using namespace std;struct node{ string no;//车牌号 int time;//车辆进入的时间(以小时为单位) int sub;//车辆在停车场的位置} nod;map<string,int>mp;//用来检测车辆在停车场或者在便道内deque<node>q1;//模拟停车场deque<node>q2;//模拟便道stack<node>sk;//交换媒介string str1="park",str2="pavement";void Push(int n)//车辆驶入操作{ cout<<"请输入要进入车辆的车牌号"<<endl; string x; int y,ans; cin>>x; cout<<"请输入该车辆进入停车场的时间(时间为整形时刻)"<<endl; cin>>y; if(!mp[x])//如果此车不在停车场或者便道内执行以下命令 { if(q1.size()<n)//如果停车场未满 {  nod.no=x;  nod.time=y;  nod.sub=q1.size()+1;  q1.push_back(nod);  mp[x]=q1.size(); } else//停车场满了之后进入便道 {  nod.no=x;  nod.time=y;  nod.sub=q2.size()+1;  q2.push_back(nod);  mp[x]=n+q2.size(); } } else cout<<"错误:该车辆已在停车场内!"<<endl;}void Pop(int n)//车辆驶出操作{ cout<<"请输入要驶出车辆的车牌号"<<endl; string x; int y,ans; cin>>x; cout<<"请输入该车辆驶出停车场的时间(时间为整形时刻)"<<endl; cin>>y; if(!mp[x]) cout<<"错误:该辆并不在停车场内!"<<endl; else if(mp[x]<=n)//如果该车在停车场内 { mp[x]=0; while(q1.back().no!=x)//车出 {  q1.back().sub--;  sk.push(q1.back());  q1.pop_back(); } ans=y-q1.back().time; q1.pop_back(); while(!sk.empty()) {  q1.push_back(sk.top());  sk.pop();  mp[q1.back().no]=q1.back().sub; } if(!q2.empty())//如果便道里也有车,那么进入停车场,并且便道后面的车向前移动 {  q2.front().time=y;  q2.front().sub=q1.size()+1;  q1.push_back(q2.front());  q2.pop_front();  while(!q2.empty())  {  q2.back().sub--;  sk.push(q2.back());  q2.pop_back();  }  while(!sk.empty())  {  q2.push_back(sk.top());  sk.pop();  mp[q2.back().no]=q1.back().sub;  }  mp[q1.back().no]=q1.size(); } cout<<"该车辆一共停了 "<<ans<<" 个小时"<<endl; cout<<"所以该车辆需要缴纳 "<<ans*5<<"元"<<endl; } else if(mp[x]>n)//如果车在便道里,那么直接离开,后面的车向前移动 { mp[x]=0; while(q2.back().no!=x) {  q2.back().sub--;  sk.push(q2.back());  q2.pop_back(); } q2.pop_back(); while(!sk.empty()) {  q2.push_back(sk.top());  sk.pop(); } cout<<"由于该车辆并未进入停车场,所以不进行收费"<<endl; }}void Query1(int n)//查询停车场的停车状态{ cout<<"请输入要查询状态的车牌号"<<endl; cout<<endl; string x; cin>>x; if(!mp[x]) cout<<"该车辆并未在停车场"<<endl; else if(mp[x]<=n) cout<<"该车辆位于停车场"<<mp[x]<<"号位"<<endl; else cout<<"该车辆位于"<<mp[x]-n<<"号便道"<<endl;}void Query2(int n)//查询停车场的空车位{ cout<<endl; if(q1.size()==n) cout<<"停车场已满"<<endl; else { cout<<"停车场的"<<q1.size()+1; for(int i=q1.size()+2; i<=n; i++)  cout<<"、"<<i; cout<<"号位车为空"<<endl; }}int main(){ int n; cout<<"  **************停车场管理系统**************"<<endl; cout<<endl; cout<<"停车场管理系统说明:"<<endl; cout<<"1.当停车场车位已满之后,车将会停在便道"<<endl; cout<<"2.停车场按照每小时五元的标准收费(不足一小时按照一小时计算)"<<endl; cout<<"3.停在便道的车辆不收费。"<<endl; cout<<endl; cout<<"首先请设置停车场的总共的车位数:"<<endl; cin>>n; cout<<endl; cout<<"*********车位设置完毕!下面开始停车场管理系统模拟*********"<<endl; cout<<endl; cout<<"  *********操作说明*********"<<endl; cout<<endl; cout<<"车辆驶入登记->请按1 ^_^  车辆驶出登记->请按2 ^_^"<<endl; cout<<endl; cout<<"查询停车场的停车状态->请按3 ^_^ 查询停车场空闲车位->请按4 ^_^ "<<endl; cout<<endl; cout<<"退出停车场管理系统->请按0 ^_^"<<endl; cout<<endl; cout<<"说明完毕!下面开始操作"<<endl; cout<<endl; while(1) { cout<<"********请选择操作1~4或者退出按0********"<<endl; cout<<endl; int t; cin>>t; if(t==1)  Push(n); else if(t==2)  Pop(n); else if(t==3)  Query1(n); else if(t==4)  Query2(n); else  break; cout<<endl; cout<<"***********************biubiu***********************"<<endl; cout<<"***********************biubiu***********************"<<endl; cout<<endl; } cout<<"欢迎使用停车场管理系统,期待您的下次使用^_^"<<endl;}

结果:

这里写图片描述

这里写图片描述

更多学习资料请关注专题《管理系统开发》。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持武林网。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表