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

Make a class Vehicle with a member function to set the gas mileage, which is sto

ID: 3885703 • Letter: M

Question

Make a class Vehicle with a member function to set the gas mileage, which is stored in a data member Add member function display to write on the screen the vehicle's gas mileage Make a class Car which inherits from Vehicle Add a member function to Car to set the maximum number of passengers, which is stored in a data member Add member function display to Car which writes the number of passengers on the screen and the gas mileage by using the base class display function Make a class Truck which inherits from Vehicle Add a member function to Truck to set the maximum payload, which is stored in a data member Add member function display to Truck which writes the payload on the screen and the gas mileage by using the base class display function Use the following main function to obtain the given output # include # include "Vehicle.h" using namespace std: int main() { Car sedan: Truck bigRig: sedan.setMileage(25): sedan.setPassengers(5): sedan.display(): cout

Explanation / Answer

#include<iostream>
using namespace std;
//class Vehicle
class Vehicle {
public:
//mileage data member
int mileage;
//setter function to set mileage
void setMileage(int m){
mileage = m;
}
//display function to display mileage
void display(){
cout << "Gas mileage is " << mileage << " MPG" << endl;
}
};
class Car : public Vehicle {
public :
//maxPassengers data member
int maxPassengers;
//setter function to set maxPassengers
void setPassengers(int maxP){
maxPassengers = maxP;
}
//display function to display maxPassengers and mileage
void display(){
cout << "This car seats " << maxPassengers << " passengers" << endl;
cout << "Gas mileage is " << mileage << " MPG" << endl;
}
};
class Truck : public Vehicle {
public :
//payLoad data member
int payLoad;
//setter function to set payLoad
void setPayload(int payL){
payLoad = payL;
}
//display function to display
void display(){
cout << "This truck has a payload of " << payLoad << " tons" << endl;
Vehicle :: display();
}
};
int main(){
   Car sedan;
   Truck bigRig;
   sedan.setMileage(25);
   sedan.setPassengers(5);
   sedan.display();
   cout << endl;
   bigRig.setMileage(15);
   bigRig.setPayload(200);
   bigRig.display();
   cout << "Press any key to continue..." << endl;
   getchar();
   return 0;
}

/*
sample output

This car seats 5 passengers
Gas mileage is 25 MPG

This truck has a payload of 200 tons
Gas mileage is 15 MPG
Press any key to continue...
*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote