温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么用C++编写停车场管理系统

发布时间:2021-03-10 15:56:05 来源:亿速云 阅读:414 作者:TREX 栏目:编程语言

这篇文章主要介绍“怎么用C++编写停车场管理系统”,在日常操作中,相信很多人在怎么用C++编写停车场管理系统问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”怎么用C++编写停车场管理系统”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

#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;
}

结果:

怎么用C++编写停车场管理系统

怎么用C++编写停车场管理系统

到此,关于“怎么用C++编写停车场管理系统”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI