Question: I need help solving this code. Here is what I started with for program # 2 . / / SophiaDawayProgram 0 2 . cpp :

I need help solving this code. Here is what I started with for program #2.
// SophiaDawayProgram02.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include
#include
using namespace std;
class Mileage {
private:
double miles;
double gallons;
public:
void setMiles(double mile){
miles = mile;
}
void setGallons(double gallon){
gallons = gallon;
}
double getMiles(){
return miles;
}
double getGallons(){
return gallons;
}
double getMPG(){
return miles / gallons;
}
};
int main(){
double mile, gallon;
Mileage car;
cout "Enter Number of Miles: ";
cin >> mile;
car.setMiles(mile);
cout "Enter Number of Gallons: ";
cin >> gallon;
car.setGallons(gallon);
cout "Miles per Gallon: " fixed setprecision(2) car.getMPG() endl;
return 0;
}We will make some changes to our second program. If you recall Program #1 began with, A car's gas
mileage or miles-per-gallon (MPG) can be calculated with the following Formula:
MPG = Miles Driven / Gallons of gas used
Then Program #2 added a class called Mileage with two private member variables called miles and
gallons of type double. The class had four public methods: setMiles and setGallons used void return
types; getMiles and getGallons used double return types. It had one more method called getMPG
that performed the math calculation and returned the double mpg
The MPGMain asked the user for the number of miles driven and the gallons of gas used. It called the
Mileage class to calculate the car's MPG. Then the class returned the MPG to the MPGMain where it
was called and displayed the value on the screen. (Formatted display and limited the miles-per-gallon
to 2 decimal places)
Program #3
Begin with Program #2 Solution file. You will need to add two more classes to the Java Project. One
called Distance and one called Speed. Similar to Mileage, Distance will have two private member
variables, speed and time (both doubles); Speed will have two private member variables distance
and time (again both are doubles). They will need sets and gets (also called accessors and mutators).
Distance should have one more method called getDistance that performs the math calculation and
returns the double totalDistance. Speed should have one more method called getMPH that performs
the math calculation and returns the double mph
Add a menu like the following to MPGMain:
Enter 1 to Determine Miles-per-Gallon
Enter 2 to Determine Distance
Enter 3 to Determine Miles-per-Hour
Enter 4 to Exit
The program should switch on the user's choice. The program should continue until the user enters 4.
If the user enters a number greater than 4 or less than 1 the program should display an error
message and prompt the user to reenter a number between 1 and 4. The program will continue to
display the error message allowing the user to reenter their choice until they enter a number within
the correct range.
Each case in the switch statement should create an instance of the appropriate class (for example,
case 1: Mileage, case 2: Distance, case 3: Speed), and set the variable values using the set methods
of the class. Each case statement should also display the results of the appropriate mathematical
calculations by calling the getMPG, getDistance, or getMPH methods.
I need help solving this code. Here is what I

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!