?? main.cpp
字號:
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <stdexcept>
#include <string>
#include <stack>
using namespace std;
#include "Car.h"
int main(int argc,char *argv[])
{
if (argc != 2) {
cerr << "Usage: " << argv[0] << " data-file\n";
return EXIT_FAILURE;
}
try {
string file = argv[1];
ifstream in;
//Open the file
in.open(file.c_str());
if(!in)
{
throw exception("Can not open the file");
}
//The file has been open,we declar a stack as the parking lot aisle
stack<Car*> aisle;
string action;//The action of the car from the text file
string license;//The license of the car from the text file
while(1)
{
in>>license;
in>>action;
if(action=="arrives")
{
if(aisle.size()==5)
{
cout<<"Sorry "<<license<<", the lot is full"<<endl;
}else
{
Car *car=new Car(license);
aisle.push(car);
}
}else
if(action=="departs")
{
stack<Car*> tempStore;
Car * tempCar;
int count=aisle.size();
while(!aisle.empty())
{
tempCar=aisle.top();
if(tempCar->getLicense()==license)
{
cout<<*tempCar;
aisle.pop();
delete tempCar;
break;
}else
{
aisle.pop();
tempCar->movedTimesIncrease();
tempStore.push(tempCar);
}
}
if(tempStore.size()==count)
{
cout<<"Can not find the car "<<license<<endl;
}
while(!tempStore.empty())
{
aisle.push(tempStore.top());
tempStore.pop();
}
}
if(in.eof())
{
break;
}
}
}
catch(exception& e) {
cerr << e.what() << endl;
}
catch(...) {
cerr << "Unknown exception caught!" << endl;
}
return EXIT_FAILURE;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -