![screamqueen](/avatars/2881.jpg)
screamqueen
05.05.2020 •
Computers and Technology
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');
}
Solved
Show answers
More tips
- F Food and Cooking Kick Your Taste Buds Into Gear with This Authentic and Delicious Recipe for Solyanka...
- O Other What happens if you get scared half to death twice?...
- F Family and Home What s That Noise When a Kettle Boils? The Science of Water and Steam...
- L Leisure and Entertainment History of International Women s Day: When Did the Celebration of March 8th Begin?...
- W Work and Career How much does an honest traffic police officer earn in a day?...
- F Food and Cooking Red Caviar: How to Choose the Best?...
- S Style and Beauty How to Get Rid of a Bruise: Tips and Tricks...
- H Health and Medicine Is Massage Necessary? Facts and Opinions...
- L Leisure and Entertainment Should You Buy a Ceramic Knife?...
- C Computers and Internet Best Antivirus: How to Choose Protection for Your Computer?...
Answers on questions: Computers and Technology
- C Computers and Technology Let Σ= {a, b}. a. Consider the language S*, where S= {aa ab ba bb}. Give another description of this language. b. Give an example of a set S such that S* only contains all possible...
- C Computers and Technology Total Purchase (SOWP Ch. 2 Problem 4): A customer in a store is purchasing five items. Write a program that asks for the price of each item, then displays the subtotal of the sale,...
- C Computers and Technology True or False? A volatile storage device loses the contents of its memory if its power supply is turned off....
- C Computers and Technology Arock is defined as a.any hard aggregate in the earth b.an aggregate of minerals without specific chemical composition c.a substance made of just one chemical element 3 points save...
- C Computers and Technology The specifies whether each entity supertype occurrence must also be a member of at least one subtype....
- C Computers and Technology Which is a software application used to analyze an organization’s data to improve decision making?...
- M Mathematics 18. leo reads 13 pages in 1/3 hour. how many pages he reads in one hour?...
- M Mathematics What is the answer for zero point zero eighty five times sevendee...
- C Chemistry What’s the difference between cation and an anion...
- M Mathematics How would you write 7/10 as a percent using the algorithm method?...
Ответ: