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 13:00
Which option should u select to ignore all tracked changes in a document
Answers: 1
question
Computers and Technology, 23.06.2019 13:30
Anetwork security application that prevents access between a private and trusted network and other untrusted networks
Answers: 1
question
Computers and Technology, 23.06.2019 21:20
In microsoft word, when you highlight existing text you want to replace, you're in              a.  advanced mode.    b.  automatic mode.    c.  basic mode.    d.  typeover mode
Answers: 1
question
Computers and Technology, 23.06.2019 22:00
Technician a says engine assemblies can be mounted longitudinally in a chassis. technician b says engine assemblies can be mounted transversely in a chassis. who is correct?
Answers: 2
You know the right answer?
Fill in the missing functions/classes to enable the program to compile and work correctly. This prog...
Questions
Questions on the website: 13722361