?? parking.cpp
字號:
#include<iostream>
using namespace std;
#include "Hparking.h"
//構(gòu)造函數(shù)
Parking::Parking()
{
int i = 0;
Temptop = -1;
cout<<"請輸入單位時間的停車費用:";
cin>>fee;
cout<<"請輸入停車場車位數(shù): ";
cin >> n;
Stop = -1;
Ntop = n;
park = new Car [n];
parkrec = new Car [n];
Northroad = new BCar;
Northroad->next = NULL;
Northtail = Northroad;
Southroad = new BCar;
Southroad->next = NULL;
Southtail = Southroad;
}
//車剛到的選擇處理
void Parking::cararrive()
{
int i = 0;
int j = 0;
BCar *p;
p = new BCar;
char NS;
cout<<"車的信息,包括:"<<endl;
cout<<"該車是到達(A)還是離去(D),車牌號碼,車到達或離去的時間"<<endl;
cout<<"例如:A 123456 12其中以空格間隔"<<endl;
cout<<"輸入:E 0 0表示輸入完畢!"<<endl;
while(1)
{
cout<<"請輸入車的信息:"<<endl;
cin>>aCar.ADinfor;
cin>>aCar.Carnumber;
cin>>aCar.ADtime;
if (aCar.ADinfor == 'E'|| aCar.ADinfor =='e')
{
break;
}
else if (aCar.ADinfor == 'A'||aCar.ADinfor=='a')
{
//排除時間,車牌號碼的邏輯錯誤
if (Stop > -1)
{
if(park[Stop].ADtime > aCar.ADtime)
{
cout<<"車到達時間輸入有誤!(時間要小于之前車輛到達的時間)"<<endl;
cout<<"重新輸入車的信息!"<<endl;
continue;
}
for(i = 0;i <= Stop;i++)
{
if(park[i].Carnumber == aCar.Carnumber)
{
cout<<"車牌號碼已經(jīng)存在!重新輸入車的信息!"<<endl;
j = 1;
break;
}
}
if (1 == j)
{
continue;
}
}
j = 0;
if (Ntop < n)
{
if (park[Ntop].ADtime > aCar.ADtime)
{
cout<<"車到達時間輸入有誤!(時間要小于之前車輛到達的時間)"<<endl;
cout<<"重新輸入車的信息!"<<endl;
continue;
}
for(i = Ntop;i < n;i++)
{
if(park[i].Carnumber == aCar.Carnumber)
{
cout<<"車牌號碼已經(jīng)存在!重新輸入車的信息!"<<endl;
j = 1;
break;
}
}
if (1 == j)
{
continue;
}
}
j = 0;
if (Southroad->next != NULL)
{
if(Southtail->bcar.ADtime > aCar.ADtime)
{
cout<<"車到達時間輸入有誤!(時間要小于之前車輛到達的時間)"<<endl;
cout<<"重新輸入車的信息!"<<endl;
continue;
}
p = Southroad->next;
while(p != NULL)
{
if (p->bcar.Carnumber == aCar.Carnumber)
{
cout<<"車牌號碼已經(jīng)存在!重新輸入車的信息!"<<endl;
j = 1;
break;
}
p = p->next;
}
if (1 == j)
{
continue;
}
}
j = 0;
if (Northroad->next != NULL)
{
if (Northtail->bcar.ADtime > aCar.ADtime)
{
cout<<"車到達時間輸入有誤!(時間要小于之前車輛到達的時間)"<<endl;
cout<<"重新輸入車的信息!"<<endl;
cout<<endl;
continue;
}
p = Northroad->next;
while(p != NULL)
{
if (p->bcar.Carnumber == aCar.Carnumber)
{
cout<<"車牌號碼已經(jīng)存在!重新輸入車的信息!"<<endl;
j = 1;
break;
}
p = p->next;
}
if (1 == j)
{
continue;
}
}
//進出車場的操作(包括進,出車場,進便道)
do
{
i = 0;
cout<<"請選擇車到來的方向:"<<endl;
cout<<"北門(North)或南門(South)"<<endl;
cout<<"****************"<<endl;
cout<<"1 北門(North)"<<endl;
cout<<"2 南門(South)"<<endl;
cout<<"****************"<<endl;
cout<<"請輸入你選擇的編號:"<<endl;
cin>>NS;
if (NS != '1' && NS != '2')
{
i = 1;
cout<<"沒有此選項"<<endl;
}
}while(i == 1);
if (Stop + 1 == Ntop)
{
cout<<"車場已滿,車將進入便道"<<endl;
switch(NS)
{
case '1':
Nroad(aCar);
break;
case '2':
Sroad(aCar);
break;
}
}
else
{
switch(NS)
{
case '1':
Nparkingin(aCar);
break;
case '2':
Sparkingin(aCar);
break;
default:
break;
}
}
}
else if (aCar.ADinfor == 'D'||aCar.ADinfor=='d')
{
int judge = 0;
int judge1 = 0;
for(i = 0;i <= Stop;i++)
{
if (park[i].Carnumber == aCar.Carnumber)
{
if (park[i].ADtime > aCar.ADtime)
{
cout<<"輸入時間有誤(可能是離開時間小于到來時間)"<<endl;
cout<<"檢查輸入信息,重新輸入車的信息"<<endl;
cout<<endl;
judge1 = 1;
break;
}
else
{
Sparkingout(aCar);
judge = 1;
break;
}
}
}
for(i = n - 1;i >= Ntop;i--)
{
if(park[i].Carnumber == aCar.Carnumber)
{
if (park[i].ADtime > aCar.ADtime)
{
cout<<"輸入時間有誤(可能是離開時間小于到來時間)"<<endl;
cout<<"檢查輸入信息,重新輸入車的信息"<<endl;
cout<<endl;
judge1 = 1;
break;
}
else
{
Nparkingout(aCar);
judge = 1;
break;
}
}
}
if(judge1 == 1)
{
continue;
}
if (judge == 0)
{
cout<<"此車場中沒有牌號為"<<aCar.Carnumber<<"的車!重新輸入車的信息!"<<endl;
}
}
else
{
cout<<"車的到達或離去信息錯誤!重新輸入車的信息!"<<endl;
}
}
}
//整個車場狀況
void Parking::Allshow()
{
int i = 0;
BCar *p;
p = new BCar;
if(Stop == -1)
{
cout<<"南門入口未有車進入"<<endl;
}
else
{
for(i = 0;i <= Stop;i++)
{
cout<<"車位: 南門第"<<i + 1<<"個位置"<<endl;
cout<<"車牌號是"<<park[i].Carnumber<<endl;
cout<<"該車到達時間是"<<park[i].ADtime<<endl;
}
}
cout<<endl;
if (Ntop == n)
{
cout<<"北門入口未有車進入"<<endl;
}
else
{
for(i = n - 1;i >= Ntop;i--)
{
cout<<"車位: 北門第"<<n - i<<"個位置"<<endl;
cout<<"車牌號是"<<park[i].Carnumber<<endl;
cout<<"該車到達時間是"<<park[i].ADtime<<endl;
}
}
cout<<endl;
i = 0;
p = Southroad->next;
if (p == NULL)
{
cout<<"南門便道沒有車在等候"<<endl;
}
else
{
while(p!=NULL)
{
cout<<"南便道第"<<i + 1<<"位置";
cout<<"車牌號:"<<p->bcar.Carnumber<<endl;
cout<<"該車到達時間是:"<<p->bcar.ADtime<<endl;
i++;
p = p->next;
}
}
cout<<endl;
i = 0;
p = Northroad->next;
if (p == NULL)
{
cout<<"北門便道沒有車在等候"<<endl;
}
else
{
while(p!=NULL)
{
cout<<"北便道第"<<i + 1<<"位置";
cout<<"車牌號:"<<p->bcar.Carnumber<<endl;
cout<<"進入北門便道時間是:"<<p->bcar.ADtime<<endl;
i++;
p = p->next;
}
}
cout<<endl;
}
//析構(gòu)函數(shù)
Parking::~Parking()
{
BCar *p;
p = new BCar;
while(Northroad->next != NULL)
{
p = Northroad->next;
Northroad->next = p->next;
delete p;
}
while(Southroad->next != NULL)
{
p = Southroad->next;
Southroad->next = p->next;
delete p;
}
delete Northroad;
delete Southroad;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -