Program:
#include <iostream>
using namespace std;
// Creating Odometer class
class Odometer
{
private:
// Declaring variables
int milesDriven;
double fuelEfficiency;
int noOfGallonsUsed;
public:
int totalMilesDriven;
Odometer();
// Function declarations
void reset();
void setFuelEfficiency(double FuelEff);
void addMiles(int milesDrivenInTrip);
double getGasolineConsumed();
};
// Default constructor
Odometer::Odometer()
{
totalMilesDriven = 0;
fuelEfficiency = 0.0;
}
// Function implementations
void Odometer::reset()
{
this->milesDriven = 0;
}
void Odometer::setFuelEfficiency(double FuelEff)
{
this->fuelEfficiency = FuelEff;
}
void Odometer::addMiles(int milesDrivenInTrip)
{
milesDriven = milesDrivenInTrip;
totalMilesDriven += milesDrivenInTrip;
}
double Odometer::getGasolineConsumed()
{
return milesDriven / fuelEfficiency;
}
int main()
{
// Declaring variables
int noOfMilesDriven;
double fuelEfficiency;
// Create a instance of Odometer class
Odometer trip1;
// getting the data entered by the user
cout << "Enter the no of Miles Driven in trip#1:";
cin >> noOfMilesDriven;
// Calling the setter method
trip1.addMiles(noOfMilesDriven);
// getting the fuel efficiency entered by the user
cout << "Enter Fuel Efficiency :";
cin >> fuelEfficiency;
// Calling the setter method
trip1.setFuelEfficiency(fuelEfficiency);
// Displaying the no of gallons used in that trip#1
cout << "No of Gallons of Gasoline used for " <<
noOfMilesDriven
<< " in trip#1 :" << trip1.getGasolineConsumed()
<< endl;
trip1.reset();
Odometer trip2;
cout << "Enter the no of Miles Driven in trip#2:";
cin >> noOfMilesDriven;
trip2.addMiles(noOfMilesDriven);
cout << "Enter Fuel Efficiency :";
cin >> fuelEfficiency;
trip2.setFuelEfficiency(fuelEfficiency);
// Displaying the no of gallons used in that trip#2
cout << "No of Gallons of Gasoline used for " <<
noOfMilesDriven
<< " in trip#1 :" << trip2.getGasolineConsumed()
<< endl;
// Displaying the total no of gallons used
cout << "Total No of Miles driven :" <<
trip2.totalMilesDriven << endl;
}
Output:
C++, Visual Studio 3. Define a class called Odometer that will be used to track fuel...
Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tankfuls of gasoline by recording miles driven and gallons used for each tankful. Develop a C++ program that will input the miles driven and gallons used for each tankful. The program should calculate and display the miles per gallon obtained for each tankful. After processing all input information, the program should calculate and print the combined miles per gallon obtained for all tankfuls....
In JAVA In this assignment you will use a class Car to represent a car that travels to various destinations. Your car has a fuel economy rating of 32.3 miles per gallon. The gas tank holds 19.5 gallons. Your program will need to simulate two trips: 1) BC to Yosemite Valley, and 2) BC to Washington, D.C.. For each trip you will start with a full tank of gas. The output should look as follows. Trip one: Bakersfield College to...
Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tankful of gasoline by recording miles driven and gallons used for each tankful. Develop a C++ program that inputs the miles driven and gallons used for each tankful. The program should calculate and display the miles per gallon obtained for each tankful and print the combined miles per gallon obtained for all tankfuls up to this point.
Drivers are concerned with the mileage their automobiles get. One driver has kept track of several tankfuls of gasoline by recording the miles driven and gallons used for each tankful. Develop a C# app that will input the miles driven and gallons used (both as integers) for each tankful. The app should calculate and display the miles per gallon obtained for each tankful and display the combined miles per gallon obtained for all tankfuls up to this point. All averaging...
Computers in some vehicles calculate various quantities related to performance. One of these is the fuel efficiency, or gas mileage, usually expressed as miles per gallon (mpg). For one vehicle equipped in this way, the miles per gallon were recorded each time the gas tank was filled, and the computer was then reset. In addition to the computer's calculations of miles per gallon, the driver also recorded the miles per gallon by dividing the miles driven by the number of...
used for job-site visits and for other general business purposes. The other is a heavy truck used to haul equipment. The car gets 25 miles per gallon (mpg). The truck gets 10 mpg. You want to improve gas mileage to save money, and you have enough money to upgrade one vehicle. The upgrade cost will be the same for both vehicles. An upgraded car will get 40 mpg: an upgraded truck will get 12.5 mpg. The cost of gasoline is...
Your small remodeling business has two work vehicles. One is a small passenger car used for job-site visits and for other general business purposes. The other is a heavy truck used to haul equipment. The car gets 25 miles per gallon (mpg). The truck gets 10 mpg. You want to improve gas mileage to save money, and you have enough money to upgrade one vehicle. The upgrade cost will be the same for both vehicles. An upgraded car will get...
Your small remodeling business has two work vehicles. One is a small passenger car used for job-site visits and for other general business purposes. The other is a heavy truck used to haul equipment. The car gets 25 miles per gallon (mpg). The truck gets 10 mpg. You want to improve gas mileage to save money, and you have enough money to upgrade one vehicle. The upgrade cost will be the same for both vehicles. An upgraded car will get...
10 Your small remodeling business has two work vehicles. One is a small passenger car used for job site visits and for other general business purposes. The other is a heavy truck used to haul equipment. The car gets 25 miles per gallon (mpg). The truck gets 10 mpg. You want to improve gas mileage to save money, and you have enough money to upgrade one vehicle. The upgrade cost will be the same for both vehicles. An upgraded car...
C# for beginners (Methods and Properties, Data types) WorkStation:- Visual Studio 2019 Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as instance variables – a part number (type int), a part description (type string), a quantity of the item being purchased (type int) and a price per item (type decimal). Your class should have a constructor that initializes...