c/c++
面向对象
控制台
求项目源代码
// An highlighted block
var foo = 'bar';
#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;
int i=0; //计数,记录目前已经占用的车位数
class Car{ //新建一个Car类来记录入场车辆的车牌号,颜色,车型,入场时间及分别指向在此车前后入场的车对象指针
public:
string chepai;
string color;
string chexing;
int time;
Car* tail;
Car* front;
};
class Maneger{ //管理员类,来进行对入场,出场,查询,统计及管理员登录的方法
public:
Car c[200];
void cun();
void qu(int);
void chaxun();
void statistic();
string login(string ,int );
};
void Maneger::cun(){ //入场存车
string chepai1;
string color1;
string chexing1;
int time1;
cout<<"欢迎入场停车!"<<endl;
if(i==200)
{
cout<<"车位已满!"<<endl;
}
else
{ cout<<"请输入车牌:"<<endl;
cin>>chepai1;
c[i].chepai=chepai1;
cout<<"请输入车辆颜色:"<<endl;
cin>>color1;
c[i].color=color1;
cout<<"请输入车型:"<<endl;
cin>>chexing1;
c[i].chexing=chexing1;
cout<<"请输入入场时间:"<<endl;
cin>>time1;
c[i].time=time1;
c[i].tail=&c[i+1]; //记录当前车的下一辆车的地址
c[i+1].front=&c[i]; //把当前车的地址赋给下一辆将要入场的车
i=i+1; //占用车位数增一
cout<<"请顺序入场!"<<endl;
}
}
void Maneger::qu(int time1){
int a;
string chepai2;
cout<<"请输入本车车牌号码:"<<endl;
cin>>chepai2;
for(a=0;a<=i;a++){
if(chepai2.compare(c[a].chepai)==0)
{
int t=time1-c[a].time;
cout<<"您的停车时长为:"<<t<<"小时"<<endl;
cout<<"您需交费为:"<<t*3<<"元"<<endl; //每小时停车3元钱
cout<<"交费成功!祝您一路平安"<<endl;
for(int p=a;p<=i;p++) //出场后,每一个车的信息前移,覆盖出场车辆
{
c[p]=c[p+1];
}
i=i-1; //占用车位数减一
break;
}
}
}
void Maneger::chaxun(){
string chepai3;
string panduan; //判断查看前还是后
string pd; //判断是否需要查询前后车辆的信息
cout<<"请输入您需要查询的车辆车牌号:"<<endl;
cin>>chepai3;
for(int j=0;j<=i;j++)
{
if(chepai3.compare(c[j].chepai)==0)
{
cout<<"车牌号为:"<<c[j].chepai<<endl;
cout<<"车型为:"<<c[j].chexing<<endl;
cout<<"车辆颜色为:"<<c[j].color<<endl;
cout<<"车辆入场时间为:"<<c[j].time<<"点"<<endl;
cout<<"是否需要查询此车前后入场车辆信息?"<<endl;
cin>>pd;
if(pd.compare("yes")==0)
{
cout<<"查询此车前一辆或者后一辆?"<<endl;
cin>>panduan;
if(panduan.compare("qian")==0)
{ cout<<"车牌号为:"<<c[j].front->chepai<<endl;
cout<<"车型为:"<<c[j].front->chexing<<endl;
cout<<"车辆颜色为:"<<c[j].front->color<<endl;
cout<<"车辆入场时间为:"<<c[j].front->time<<endl;
}
if(panduan.compare("hou")==0)
{ cout<<"车牌号为:"<<c[j].tail->chepai<<endl;
cout<<"车型为:"<<c[j].tail->chexing<<endl;
cout<<"车辆颜色为:"<<c[j].tail->color<<endl;
cout<<"车辆入场时间为:"<<c[j].tail->time<<endl;
}
}
if(pd.compare("no")==0)
break;
}
if(j>i)
cout<<"此车没有入场"<<endl;
}
}
void Maneger::statistic(){
cout<<"本停车场车位总数为:200"<<endl;
cout<<"剩余停车位数为:"<<200-i<<endl;
}
string Maneger::login(string name,int num){ //管理员输入正确名字及密码登录
if(name.compare("limingrui")==0&&num==123456)
return "登录成功!";
else{
return "登录失败!";
}
}
int main()
{
Maneger m;
string name1;
string login1="登录失败!"; //初始赋为“登录失败!”
int num1,time3;
while(login1.compare("登录失败!")==0)
{ cout<<"欢迎管理员,请先登录!"<<endl;
cout<<"姓名为:"<<endl;
cin>>name1;
cout<<"密码为:"<<endl;
cin>>num1;
login1=m.login(name1,num1); //若login方法返回“登录成功!”则跳出循环
cout<<login1<<endl;
}
string caozuo;
while(1)
{
cout<<"请输入您需要的操作"<<endl; //选择管理员需要进行的操作
cin>>caozuo;
if(caozuo.compare("ruchang")==0)
{
m.statistic();
m.cun();
}else if(caozuo.compare("chuchang")==0)
{
cout<<"请输入当前出场时间:"<<endl;
cin>>time3;
m.qu(time3);
}else if(caozuo.compare("chaxun")==0)
{
m.chaxun();
}else if(caozuo.compare("tongji")==0)
{
m.statistic();
}
else
cout<<"请输入正确的操作!"<<endl;
}
}
代码如上,万望采纳。