//Fall 2011 Answers //Exam 1, questions 4 and 5 //Train class //only need these 2 lines of code for question 5 #include using namespace std; //Qeustion 4 class Train { private: int id; bool seats; // true means separate seats, false means benches char route; public: //destructor (only prototype) ~Train(); //default constructor Train() { seats = false; } //overloaded constructor accepts 2 args Train(int i, char r) { id = i; route = r; seats = false; } //accessor functions int getId() { return id; } char getRoute() { return route; } bool getSeating() { return seats; } //mutator functions void setId(int i) { id = i; } void setRoute(char r) { route = r; } void setSeating(bool s) { seats = s; } //toggle seating to other mode void changeSeating() { if (seats) seats = false; else seats = true; } }; /* int main() { Train NYsubway(5685, 'M'); } */ //define destructor function so that can run a program that allocates Train objects Train::~Train(){}; //Question 5 //part b: utility function to calculate the number of trains assigned to a specific subway line //not part of Train class since one Train cannot use it int numTrainsOnLine(char route, Train trains[], int totalTrains) { int totalOnLine = 0; for (int i = 0; i