Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you help me complete #include #include #include mileage.h using namespace std; int main ( ) { / / Declare and initialize variables double

Can you help me complete
#include
#include
#include "mileage.h"
using namespace std;
int main()
{
//Declare and initialize variables
double miles =0.0;
double gallons =0.0;
//Limit decimal display to two decimal places.
cout fixed setprecision(2);
//Retrieve data from user and validate data entered.
cout "Enter the miles driven: " endl;
cin >> miles;
while (miles =0)
{
cout "Incorrect entry.
Enter a number"
" greater than zero." endl;
cin >> miles;
}
cout "Enter the gallons used: " endl;
cin >> gallons;
while (gallons =0)
{
cout "Incorrect entry.
Enter a number"
" greater than zero." endl;
cin >> gallons;
}
//Create copy of mileage class
mileage myMiles{ miles, gallons };
//Display results for user
cout "Your car gets " myMiles.getMPG()
" miles-per-gallon." endl;
}#include "mileage.h"
mileage::mileage(double miles, double gallons)
{
setMiles(miles);
setGallons(gallons);
}
void mileage::setMiles(double miles)
{
this->miles = miles;
}
void mileage::setGallons(double gallons)
{
this->gallons = gallons;
}
double mileage::getMiles()
{
return miles;
}
double mileage::getGallons()
{
return gallons;
}
double mileage::getMPG()
{
//Do not directly access the private variables of the class.
//Use the get methods.
return getMiles()/ getGallons();
}
#pragma once
class mileage
{
private:
double miles;
double gallons;
public:
mileage( double, double );
void setMiles(double);
void setGallons(double);
double getMiles();
double getGallons();
double getMPG();
};
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

Step: 3

blur-text-image

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

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions