Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following code should compile and run, but the user interface is train wreck. A) Fix the interface so that it makes sense. B) Make

The following code should compile and run, but the user interface is train wreck. A) Fix the interface so that it makes sense. B) Make it possible to add and remove cars at the front and back of the train. C) Improve and add any classes or functions that you see fit. D) Be sure to write a summary of your work and document the code with sufficient comments (C++)

///////////// code

#include using namespace std; int current_year = 2017; const double PI = 3.14159; class container { public: int percent_loaded; container() { cout << " Calling container default constructor." << endl; } }; //Syntax: //class subclass_name : public superclass_name { }; class box : public container { public: double height, width, length; box() { cout << " Calling box default constructor." << endl; } double volume(){ return height * length * width; } }; class cylinder : public container { public: cylinder(){} cylinder(double rad, double len) {radius = rad; length = len;} double radius, length; double volume ( ) {return PI * radius * radius * length;} }; class rail_car { public: int year_built; rail_car() { cout << " Calling rail_car default constructor." << endl; } int age() {return current_year - year_built;} }; class box_car : public rail_car, public box { public: box_car(){ cout << " Calling box_car default constructor." << endl; height = 10.0; length = 40.0; width = 9.0; } }; class tank_car : public rail_car, public cylinder { public: tank_car ( ) : cylinder (3.5, 40.0) { } }; class engine : public rail_car { public: engine ( ) { } }; class caboose : public rail_car { public: caboose ( ) { } }; // ?? rail_car *train[100]; main ( ) { // ?? int car_count, type_code; // Read type number and create corresponding objects: for (car_count = 0; cin >> type_code; ++car_count) if (type_code == 0) train[car_count] = new engine; else if (type_code == 1) train[car_count] = new box_car; else if (type_code == 2) train[car_count] = new tank_car; else if (type_code == 3) train[car_count] = new caboose; // ?? cout << "There are " << car_count << " cars in the array." << endl; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Lab Manual For Database Development

Authors: Rachelle Reese

1st Custom Edition

1256741736, 978-1256741732

More Books

Students also viewed these Databases questions

Question

6. Be able to choose and prepare a training site.

Answered: 1 week ago