subject

Fill in the missing functions/classes to enable the program to compile and work correctly. This program simulates a train, where you start with just an engine. You have three options: go to the next train (forward towards the engine), go to the previous train (back towards the end of the train) or add a train behind the current train car. You may not change main(), we will check to ensure it is exactly the same. You should be able to train cars anywhere, and this will insert it into that part of the train. For this part, you do not need to worry about deleting dynamic memory.

Hint: when making the add() function, it would probably help to draw it out and figure out how many arrows/pointers you need to change.

B. Build off your answer for problem A (and include it in the submission). Add functionality to detach the previous train (the one behind the current train), if it exists. This time you need to ensure there are no memory leaks and all "new"s are deleted. Any cars on the train that are left once the user quits the loop should be deleted at the end of main().

Current Program.

#include

using namespace std;

int main()
{
train engine = train("Engine");
train* current = &engine;
string choice;
do
{
if(current -> hasNext())
{
cout << "Next train: " << current -> nextTrain() -> getName() << endl;
}

cout << "Current train: " << current -> getName() << endl;

if(current -> hasPrevious())
{
cout << "Previous train: " << current -> previousTrain() -> getName() << endl;
}

cout << "Do you wish to go to the (n)ext train, (p)revious train, (a)dd a train, or (q)uit?\n";
getline(cin, choice);

if(tolower(choice[0]) == 'n' && current -> hasNext())
{
current = current -> nextTrain();
}
else if(tolower(choice[0]) == 'p' && current -> hasPrevious())
{
current = current -> previousTrain();
}
else if(tolower(choice[0]) == 'a')
{
cout << "Which train is this?\n";
string name;
getline(cin, name);
current->add(name);
}

}while(tolower(choice[0]) != 'q');

}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 16:30
Primary tech skills are skills that are necessary for success in online education
Answers: 3
question
Computers and Technology, 22.06.2019 20:00
What side length would you specify if you were required to create a regular hexagonal plate that was composed of 33 cm(squared) of sheet metal? dimension the side length to 0.1 cm
Answers: 2
question
Computers and Technology, 24.06.2019 09:00
Why might you chose to crest a function resume
Answers: 1
question
Computers and Technology, 24.06.2019 16:00
How are roger williams, james oglethorpe, and william penn similar?
Answers: 3
You know the right answer?
Fill in the missing functions/classes to enable the program to compile and work correctly. This prog...
Questions
question
Mathematics, 11.11.2019 12:31
Questions on the website: 13722367