#include #include #include #include using namespace std; #include "Car.h" int main(int arg, char **args){ stacklot; /* show different ways to use stack. lot.push(new Car("x")); Car *cp = new Car("y"); lot.push(cp); // clean up while(!lot.empty()){ cout << lot.top() << endl; cout << lot.top()->getLicence() << endl; delete lot.top(); lot.pop(); } */ ifstream inf; inf.open("data.txt"); if (! inf){ cout << "woops no file" << endl; return EXIT_FAILURE; } cout << "file opened" << endl; string tag, status; while(inf >> tag){ inf >> status; Car *c = new Car(tag); if(status == "arrives"){ if(lot.size() < 5) // park it lot.push(c); else{ // reject it cout << " Lot too full for " << c->getLicence() << endl; delete c; } } // departing case else { stackaux; while(!lot.empty()){ if(lot.top()->getLicence()==tag){ cout << tag << " departing moved " << lot.top()->getMoves() << endl; delete lot.top(); lot.pop(); while(!aux.empty()){ // cout << " getting back from aux " << aux.top()->getLicence() << endl; lot.push(aux.top()); aux.pop(); } break; } else{ aux.push(lot.top()); lot.pop(); aux.top()->incMoves(); //cout << " adding to aux " << aux.top()->getLicence() // << " moves " << aux.top()->getMoves() << endl; } } } //cout << tag << " " << status << endl; } inf.close(); while(!lot.empty()){ delete lot.top(); lot.pop(); } return EXIT_SUCCESS; }