Question: How did car become the instance in the sets and gets ? #include #include using namespace std; / / Define Class MPG class MPG {
How did car become the instance in the sets and gets
#include
#include
using namespace std;
Define Class MPG
class MPG
Declare the Private Members
private:
double miles, gallons;
Declare the Public Members
public:
setMiles method, sets the Miles
void setMilesdouble mile
miles mile;
setGallons method, sets the Gallons
void setGallonsdouble gallon
gallons gallon;
getMiles method, returns the value of Miles
double getMiles
return miles;
getGallons method, returns the value of Gallons
double getGallons
return gallons;
getMPG method, returns the MPG
double getMPG
return miles gallons;
;
Main Function
int main
Declare the variables
double mile, gallon;
Create an Instance of MPG
MPG car;
Input the No of Miles
cout Enter Number of Miles: ;
cin mile;
Set the Miles using setMiles
car.setMilesmile;
Input the No of Gallons
cout Enter Number of Gallons: ;
cin gallon;
Set the Gallons using setGallons
car.setGallonsgallon;
Get the MPG using getMPG method. To print only decimals, use setprecision and fixed.
cout Miles per Gallon: fixed setprecision car.getMPG;
return ;
nstance for the MPGmain
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
