📄 main.cpp
字号:
#pragma warning(disable:4786)
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <stack>
#include <stdexcept>
#include <vector>
#include <algorithm>
#include "car.h"
using namespace std;
const int PARKING_SPOTS_PER_AISLE = 3;
const int NUMBER_OF_AISLES = 5;
void handle_arrival(vector<Car>&, vector<stack<string> >&, const string&);
void handle_departure(vector<Car>&, vector<stack<string> >&, const string&);
Car& find_car(vector<Car>&, string);
int main(int argc, char* argv[]) {
try {
if (argc != 2) {
cerr << "Usage:\n" << argv[0] << " data-file";
return EXIT_FAILURE;
}
ifstream inf(argv[1]);
if (! inf) {
cerr << "Could not open " << argv[1];
return EXIT_FAILURE;
}
vector<Car> cars;
vector< stack<string> > parking_lot(NUMBER_OF_AISLES);
while (! inf.eof()) {
string action, plate;
inf >> plate >> action;
if (action == "arrives") {
handle_arrival(cars, parking_lot, plate);
}
else if (action == "departs") {
handle_departure(cars, parking_lot, plate);
} else {
cerr << "Unknown action: " << action << endl;
}
}
inf.close();
cout << "\nHere are all the cars that visited the lot today:\n";
// TODO: Output the license plates of all the
// cars that visited the lot, in alphabetical order
return EXIT_SUCCESS;
}
catch (exception& e) {
cerr << e.what() << endl;
}
catch (...) {
cerr << "Unknown exception caught!" << endl;
}
return EXIT_FAILURE;
}
void handle_arrival(vector<Car>& cars, vector< stack<string> >& parking_lot, const string& plate) {
// TODO: Handle car arrivals
}
void handle_departure(vector<Car>& cars, vector< stack<string> >& parking_lot, const string& plate) {
// TODO: Handle car departures
}
Car& find_car(vector<Car>& cars, string plate) {
// TODO: Return a reference to the
// the Car object whose license plate equals
// the parameter 'plate'
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -