Given the Vehicle class from the book. Use it to create two car variables of you
ID: 3643129 • Letter: G
Question
Given the Vehicle class from the book. Use it to create two car variables of your choice.Then write one if statement to see which car has the largest fuel capacity.
// Declare the Vehicle Class
class Vehicle {
// These are now private
int passengers; // number of passengers
int fuelcaps; // fuel capacity in gallons
int mpg; // fuel consumption in miles per gallon
public:
// this is a constructor for Vehicle.
Vehicle (int p, int f, int m) {
passengers = p;
fuelcap =f;
mpg = m;
}
// Compute and return the range.
int range() { return mpg * fuelcap; )
// Accesor function.
int get_passengers () { return passengers; }
int get_fuelcap;
int get_mpg() { return mpg; }
};
void main(void)
{
}
Explanation / Answer
#include using namespace std; // Declare the Vehicle Class class Vehicle { // These are now private int passengers; // number of passengers int fuelcaps; // fuel capacity in gallons int mpg; // fuel consumption in miles per gallon public: // this is a constructor for Vehicle. Vehicle (int p, int f, int m) { passengers = p; fuelcaps =f; mpg = m; } // Compute and return the range. int range() { return mpg * fuelcaps; } // Accesor function. int get_passengers () { return passengers; } int get_fuelcap() { return fuelcaps; } int get_mpg() { return mpg; } }; void main(void) { Vehicle car1(2, 10, 40); Vehicle car2(8, 30, 10); if(car1.get_fuelcap() > car2.get_fuelcap()) coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.