📄 main.cpp
字号:
#include<iostream>
#include<string>
#include"astack.h"
#include"llist.h"
using namespace std;
void printindex(){
cout<<endl;
cout<<"******************************************************************"<<endl;
cout<<"* Welcome to use the parking system. *"<<endl;
cout<<"******************************************************************"<<endl;
cout<<"* *"<<endl;
cout<<"* Please type '1' to park a car. *"<<endl;
cout<<"* Please type '2' to let a parking car out. *"<<endl;
cout<<"* Please type '3' to show the condition of the parking lot. *"<<endl;
cout<<"* Please type '4' to show the condition of the waiting list. *"<<endl;
cout<<"* Please type '5' to quit the system. *"<<endl;
cout<<"* *"<<endl;
cout<<"******************************************************************"<<endl<<endl;
}
int main(void){
int num;
AStack<string> parking_lot(5); //suppose the parking lot can only contain 5 car.
LList<string> waiting_list;
string car_license;
while(1)
{
printindex();
cin>>num;
if(num==1){
cout<<"please input the license of the car which you want to park."<<endl;
cin>>car_license;
if(parking_lot.push(car_license))
cout<<"The car "<<car_license<<" has parked."<<endl;
else{
cout<<"The parking lot is full.The car "<<car_license <<" has to wait in the passage until other cars left."<<endl;
waiting_list.append(car_license);
}
}
else if(num==2){
cout<<"please input the license of the car which want to leave."<<endl;
cin>>car_license;
string tempt;
while(parking_lot.pop(tempt)){
if(tempt==car_license){//find the car
cout<<"The car " <<tempt<<" left successfully."<<endl;
break;
}
else{
waiting_list.setPos(0);
waiting_list.insert(tempt);
}
}
while(1){ // let the car in the waiting list go into the parking lot until it is full.
waiting_list.setPos(0);
if( !waiting_list.remove(tempt))
break;
if( ! parking_lot.push(tempt))
{
waiting_list.setPos(0);
waiting_list.insert(tempt);
break;
}
}
}
else if(num==3){
parking_lot.print();
}
else if(num==4){
waiting_list.print();
}
else if( num==5){
cout<<"I hope you can enjoy this system. Welcome to use next time. "<<endl;
cout<<"Bye-bye..."<<endl;
break;
}
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -