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, 23.06.2019 14:30
Choose the answers that best complete each sentence. on average,are more expensive than other kinds of postsecondary schools. the cost of room and board includes. to save money, some students attend auniversity in their home state.
Answers: 2
question
Computers and Technology, 23.06.2019 18:30
Where can page numbers appear? check all that apply. in the header inside tables in the footer at the bottom of columns at the top of columns
Answers: 1
question
Computers and Technology, 23.06.2019 19:00
Write a program that displays the following menu: geometry calculator 1. calculate the area of a circle 2. calculate the area of a rectangle 3. calculate the area of a triangle 4. quit enter your choice (1-4): if the user enters 1, the program should ask for the radius of the circle and then display its area. use the following formula: area = ďā‚¬(the square of r) use 3.14159 for ďā‚¬ and the radius of the circle for r. if the user enters 2, the program should ask for the length and width of the rectangle and then display the rectangleĆ¢ā‚¬ā„¢s area. use the following formula: area = length * width if the user enters 3, the program should ask for the length of the triangleĆ¢ā‚¬ā„¢s base and its height, and then display its area. use the following formula: area = base * height * .5 if the user enters 4, the program should end. input validation: display an error message if the user enters a number outside the range of 1 through 4 when selecting an item from the menu. do not accept negative values for the circleĆ¢ā‚¬ā„¢s radius, the rectangleĆ¢ā‚¬ā„¢s length or width, or the triangleĆ¢ā‚¬ā„¢s base or height. note: if the user enters an improper menu choice (1-4), the program prints "the valid choices are 1 through 4. run the program again and select one of those." if the user enters a negative radius, the program prints "the radius can not be less than zero." if the user enters a negative value for height or base, the program prints "only enter positive values for base and height."
Answers: 1
question
Computers and Technology, 24.06.2019 18:30
After making a powerpoint presentation about a new line of clothing designs, henri notices that he used the word ā€œgorgeousā€ on nearly every slide. what would be the  best  way to add more variety to his wording by using tools within powerpoint? using the thesaurus under the view tab, and then using the find dialog box to find and replace every instance of ā€œgorgeousā€using the spelling checker under the view tab, and then using the find dialog box to find every instance of ā€œgorgeousā€ and change some of themusing the thesaurus under the review tab, and then using the find dialog box to find every instance of ā€œgorgeousā€ and change some of themusing the spelling checker under the review tab, and then using the find dialog box to find and replace every instance of ā€œgorgeousā€
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
question
Mathematics, 21.10.2020 17:01
question
Mathematics, 21.10.2020 17:01
question
English, 21.10.2020 17:01
question
Chemistry, 21.10.2020 17:01
question
Mathematics, 21.10.2020 17:01
Questions on the website: 13722367