Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The code below the pics... thank you... I have two questions about my code which

ID: 3736596 • Letter: T

Question

The code below the pics... thank you... I have two questions about my code which sub-case 5 under case 2 has a problem, I cannot return the last menu...

the second is the problem shows in pics.

#include <iostream>

#include <stdlib.h>

#include <conio.h>

#include <iomanip>

using namespace std;

class Vehicle

{

friend class Truck;

private:

string name;

int passengers;

int wheels;

float maxspeed;

public:

void setname(string types) {name = types;}

void setpassengers(int riders) {passengers = riders;}

void setwheels(int tire) {wheels = tire;}

void setspeed(float rate) {maxspeed = rate;}

string getname() {return name;}

int getpassengers() {return passengers;}

int getwheels() {return wheels;}

float getspeed() {return maxspeed;}

void setall(string types, int riders, int tire, float rate) {name = types; passengers = riders; wheels = tire; maxspeed = rate;}

Vehicle(string types = "Motorcycle", int riders = 2, int tire = 2, float rate = 100)

{

name = types;

passengers = riders;

wheels = tire;

maxspeed = rate;

}

};

class Truck: public Vehicle

{

private:

float load;

float weight;

public:

void setload(float capacity) {load = capacity;}

void setweight(float pounds) {weight = pounds;}

float getload() {return load;}

float getweight() {return weight;}

Truck(float capacity = 0, float pounds = 2000)

{

load = capacity;

weight = pounds;

}

};

int main()

{

int option_1, option_2, option_2_1, option_3, option_5;

string types; int riders; int tire; float rate;

int const number = 5;

Truck Pickup_truck, Van;

Vehicle record[number] = {

{"Sedan", 5, 4, 80},

{"Bicycle", 1, 2, 30},

{"Unicycle", 1, 1, 15},

{"Row Boat", 3, 0, 10},

};

Pickup_truck.setall("Pickup Truck", 2, 4, 65);

Van.setall("Van", 2, 6, 70);

char ans = 'y';

while (ans == 'y')

{

system("cls");

cout << " Menu";

cout << " 1 - Display All Vehicles";

cout << " 2 - Change Values of a Class Member";

cout << " 3 - Find a Vehicle Class Member";

cout << " 4 - Display Truck Values";

cout << " 5 - Change Truck Members";

cout << " 6 - Quit";

cout << " Enter an Option 1 - 6: ";

cin >> option_1;

switch(option_1)

{

case 1:

{

int n;

system("cls");

for(int n = 0; n < number; n++)

{

cout << "Index #" << n << " ";

cout << record[n].getname() << " Carries " << record[n].getpassengers() << " Passengers (Including the driver) ";

cout << record[n].getname() << " Has " << record[n].getwheels() << " Wheels and can travel a Maximum of " << record[n].getspeed() << " mph ";

cout << " ";

}

cout << " Hit Any Key to continue...";

getch();

break;

}

case 2:

{

while (option_2 >= 1 || option_2 <= 5)

{

system("cls");

cout << " Menu";

cout << " 1 - Change Values of Sedan";

cout << " 2 - Change Values of Bicycle";

cout << " 3 - Change Values of Unicycle";

cout << " 4 - Change Values of Row Boat";

cout << " 5 - Change Values of Motorcycle";

cout << " 6 - Quit";

cout << " Enter an option 1 - 6: ";

cin >> option_2;

if(option_2 == 6)

{

break;

}

while (option_2_1 >= 1 || option_2_1 <= 5)

{

system("cls");

cout << "Index #" << option_2 - 1 << " ";

cout << record[option_2 - 1].getname() << " Carries " << record[option_2 - 1].getpassengers() << " Passengers (Including the driver) ";

cout << record[option_2 - 1].getname() << " Has " << record[option_2 - 1].getwheels() << " Wheels and can travel a Maximum of " << record[option_2 - 1].getspeed() << " mph ";

cout << " Menu";

cout << " 1 - Change vehicle name";

cout << " 2 - Change number of passengers";

cout << " 3 - Change number of wheels";

cout << " 4 - Change vehicle speed";

cout << " 5 - Quit";

cout << " Enter an option 1 - 5: ";

cin >> option_2_1;

switch(option_2_1)

{

case 1:

{

cout << "Enter vehicle name: ";

cin >> types;

record[option_2 - 1].setname(types);

break;

}

case 2:

{

cout << "Enter number of passengers: ";

cin >> riders;

record[option_2 - 1].setpassengers(riders);

break;

}

case 3:

{

cout << "Enter number of wheels: ";

cin >> tire;

record[option_2 - 1].setwheels(tire);

break;

}

case 4:

{

cout << "Enter vehicle speed: ";

cin >> rate;

record[option_2 - 1].setspeed(rate);

break;

}

case 5:

{

break;

}

default:

{

cout << " input invaild...Hit Any Key to return...";

getch();

break;

}

}

}

}

break;

}

case 3:

{

system("cls");

cout << "Enter an Index 0 to 4: ";

cin >> option_3;

cout << " Index #" << option_3 << " ";

cout << record[option_3].getname() << " Carries " << record[option_3].getpassengers() << " Passengers (Including the driver) ";

cout << record[option_3].getname() << " Has " << record[option_3].getwheels() << " Wheels and can travel a Maximum of " << record[option_3].getspeed() << " mph ";

cout << " Hit Any Key to continue...";

getch();

system("cls");

break;

}

case 4:

{

system("cls");

cout << "Pickup weighs " << Pickup_truck.getweight() << " pounds and carries a Load of " << Pickup_truck.getload() << " pounds";

cout << " Pickup has " << Pickup_truck.getwheels() << " Wheels and carries " << Pickup_truck.getpassengers() << " passengers";

cout << " Pickup has a maximum speed of " << Pickup_truck.getspeed() << " mph";

cout << " Van weighs " << Van.getweight() << " pounds and carries a Load of " << Van.getload() << " pounds";

cout << " Van has " << Van.getwheels() << " and carries " << Van.getpassengers() << " passengers";

cout << " Van has a maximum speed of " << Van.getspeed() << " mph";

cout << " Hit Any Key to continue...";

getch();

system("cls");

break;

}

case 5:

{

float weight, load, speed;

int wheels;

while (option_5 >= 0 || option_5 <= 2)

{

system("cls");

cout << " Menu";

cout << " 1 - Change Truck's Values";

cout << " 2 - Cancel";

cout << " Find Vehicle Index (0 - 1), Cancel input 2: ";

cin >> option_5;

system("cls");

switch(option_5)

{

case 0:

{

cin.ignore();

cout << " 1 of 4 - Set the Weight of the Pickup: ";

cin >> weight;

Pickup_truck.setweight(weight);

cout << " 2 of 4 - Set the Maximum Load of the Pickup";

cin >> load;

Pickup_truck.setload(load);

cout << " 3 of 4 - Set the Number of Wheels on the Pickup: ";

cin >> wheels;

Pickup_truck.setwheels(wheels);

cout << " 4 of 4 - Set the Maximum Speed of the Pickup: ";

cin >> speed;

Pickup_truck.setspeed(speed);

break;

}

case 1:

{

cin.ignore();

cout << " 1 of 4 - Set the Weight of the Van: ";

cin >> weight;

Van.setweight(weight);

cout << " 2 of 4 - Set the Maximum Load of the Van: ";

cin >> load;

Van.setload(load);

cout << " 3 of 4 - Set the Number of Wheels on the Van: ";

cin >> wheels;

Van.setwheels(wheels);

cout << " 4 of 4 - Set the Maximum Speed of the Van: ";

cin >> speed;

Van.setspeed(speed);

break;

}

case 2:

{

system("cls");

break;

}

}

break;

}

break;

}

case 6:

{

system("cls");

cout << "Hit Any Key to Quit...";

getch();

exit(0);

break;

}

default:

{

cout << " Input invaild...input vaild number (1 to 6)...";

cout << " Hit Any Key to continue...";

getch();

break;

}

}

}

}

28 29 30 31 32 nametYPES passengers riders: wheelstire maxspeedrate: 34 35 36 37 38 39 40 41 42 43 4 45 46 47 48 elass Truck: publie Vehicle privatC: loat load: float weight; public: void setload (float capacity) {load = capacity; } void setweight (float pounds) (weightpounds: float getload return load: float getweight freturn weight: Truck (float capacity=0, float pounds= 2000) load capacity: weight pounds 50 51 52 int main ) 54 int option, option_2, option 2_, option 3, option 5: string types int riders: int tire; float rate; int const number-5 Truck Pickup truck, Van; vehicle record [number] = { 56 57 58 59 60 61 62 63 64 65 "Sedan", 5, 4, 80 "Bicycle", 1, 2, 30, "Unicycle", 1, 1, 15), "Row Boat", 3, 0, 10, Pickup_truck.setall ("Pickup Truck", 2, 4, 65) Van.setall ("Van", 2, 6, 70) char ans = 'y'; 67 68 69 while (ansy Logs & others Code::Blocks X Search results XI Cocc X Build log X fBuild messages X)CppCheck a++ X ACppCheck Vera ++ messages XCscopeX Debugger X DoxyBlocks File Line Messago Build file: "no target" in "no project" (copiler: unknon In function int main C:Users39411 C:User139411 C:Users139411.. 63arning: extended initializer lists only available vith -std-ot111 or-std-gnut+11 C: Usor 39411 63 63 rarning : extended 2n1 tial:or lists only available Vith -std=e++11 -std-gnu++11 or

Explanation / Answer

a) The problem with subcase 5 under case 2

I am getting this output which proper in my C++14. Its probably because of your C++ compiler only. Try to run online in any IDE.

b) The problem shown in the pic
This is not your problem but the problem of your C++ version.
Pre C++11 allows initialzation only at time of creation and not at arbitrarily at runtime, which you are trying to attempt here.
You are assigning record[] with initializer list here which is not allowed in your C++ vrsion.

I compiled your code in C++14 and its not showing this error.