Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started