Question: C++, Will upvote. The following code should compile and run, but the user interface is train wreck. !!!!Please make sure answer each question below!!!!!! A)
C++, Will upvote.
The following code should compile and run, but the user interface is train wreck.
!!!!Please make sure answer each question below!!!!!!
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
----------------------------------------------
#include
usingnamespacestd; intcurrent_year = 2017; constdoublePI = 3.14159; classcontainer { public: intpercent_loaded; container() { cout << " Calling container default constructor."<< endl; } }; //Syntax: //class subclass_name : public superclass_name { }; classbox : publiccontainer { public: doubleheight, width, length; box() { cout << " Calling box default constructor."<< endl; } doublevolume(){ returnheight * length * width; } }; classcylinder : publiccontainer { public: cylinder(){} cylinder(doublerad, doublelen) {radius = rad; length = len;} doubleradius, length; doublevolume ( ) {returnPI * radius * radius * length;} }; classrail_car { public: intyear_built; rail_car() { cout << " Calling rail_car default constructor."<< endl; } intage() {returncurrent_year - year_built;} }; classbox_car : publicrail_car, publicbox { public: box_car(){ cout << " Calling box_car default constructor."<< endl; height = 10.0; length = 40.0; width = 9.0; } }; classtank_car : publicrail_car, publiccylinder { public: tank_car ( ) : cylinder (3.5, 40.0) { } }; classengine : publicrail_car { public: engine ( ) { } }; classcaboose : publicrail_car { public: caboose ( ) { } }; // ?? rail_car *train[100]; main ( ) { // ?? intcar_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] = newengine; elseif(type_code == 1) train[car_count] = newbox_car; elseif(type_code == 2) train[car_count] = newtank_car; elseif(type_code == 3) train[car_count] = newcaboose; // ?? cout << "There are "<< car_count << " cars in the array."<< endl; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
