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 #
SophiaDawayProgramcpp : 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 setMilesdouble mile
miles mile;
void setGallonsdouble 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.setMilesmile;
cout "Enter Number of Gallons: ;
cin gallon;
car.setGallonsgallon;
cout "Miles per Gallon: fixed setprecision car.getMPG endl;
return ;
We will make some changes to our second program. If you recall Program # began with, A car's gas
mileage or milespergallon MPG can be calculated with the following Formula:
MPG Miles Driven Gallons of gas used
Then Program # 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 milespergallon
to decimal places
Program #
Begin with Program # 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
Add a menu like the following to MPGMain:
Enter to Determine MilesperGallon
Enter to Determine Distance
Enter to Determine MilesperHour
Enter to Exit
The program should switch on the user's choice. The program should continue until the user enters
If the user enters a number greater than or less than the program should display an error
message and prompt the user to reenter a number between and 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 : Mileage, case : Distance, case : 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.
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
