Answered step by step
Verified Expert Solution
Link Copied!

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 setMiles(double mile)
{
miles = mile;
}
// setGallons() method, sets the Gallons
void setGallons(double 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.setMiles(mile);
// Input the No. of Gallons
cout " Enter Number of Gallons: ";
cin >> gallon;
// Set the Gallons using setGallons()
car.setGallons(gallon);
// Get the MPG using getMPG() method. To print only 2 decimals, use setprecision() and fixed.
cout " Miles per Gallon: " fixed setprecision(2) car.getMPG();
return 0;
}nstance for the MPGmain ??
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions