![subject](/tpl/images/cats/informatica.png)
Computers and Technology, 05.05.2020 18:06 tristan70
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](/tpl/images/cats/User.png)
Answers: 1
![](/tpl/images/ask_question.png)
![](/tpl/images/ask_question_mob.png)
Another question on Computers and Technology
![question](/tpl/images/cats/informatica.png)
Computers and Technology, 22.06.2019 16:30
Primary tech skills are skills that are necessary for success in online education
Answers: 3
![question](/tpl/images/cats/informatica.png)
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](/tpl/images/cats/informatica.png)
Computers and Technology, 24.06.2019 09:00
Why might you chose to crest a function resume
Answers: 1
![question](/tpl/images/cats/informatica.png)
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](/tpl/images/cats/fizika.png)
Physics, 11.11.2019 12:31
![question](/tpl/images/cats/mkx.png)
Arts, 11.11.2019 12:31
![question](/tpl/images/cats/mat.png)
![question](/tpl/images/cats/biologiya.png)
![question](/tpl/images/cats/mat.png)
![question](/tpl/images/cats/obshestvoznanie.png)
Social Studies, 11.11.2019 12:31
![question](/tpl/images/cats/istoriya.png)
![question](/tpl/images/cats/mat.png)
Mathematics, 11.11.2019 12:31
![question](/tpl/images/cats/mat.png)
Mathematics, 11.11.2019 12:31
![question](/tpl/images/cats/istoriya.png)
![question](/tpl/images/cats/mat.png)
Mathematics, 11.11.2019 12:31
![question](/tpl/images/cats/geografiya.png)
![question](/tpl/images/cats/health.png)
Health, 11.11.2019 12:31
![question](/tpl/images/cats/en.png)
English, 11.11.2019 12:31
![question](/tpl/images/cats/mat.png)
Mathematics, 11.11.2019 12:31
![question](/tpl/images/cats/mat.png)
![question](/tpl/images/cats/biologiya.png)
![question](/tpl/images/cats/en.png)
![question](/tpl/images/cats/mat.png)
![question](/tpl/images/cats/mat.png)
Mathematics, 11.11.2019 12:31