Question
c++ How do I build engine to (while loop ) to dispense gas? Also cout to get user input of full service or self. my
c++ How do I build engine to (while loop ) to dispense gas?
Also cout to get user input of full service or self. my code bellow one class header file and main
#include "GasPump.h"
#include using namespace std;
double GasPump::mainGasTank = 100; GasPump::GasPump() {
CostPerGallon = 3.95; AmountGas = 0; ChargeGas = 0; TotalGas = 0; }
GasPump::GasPump(double price) {
CostPerGallon = price; AmountGas = 0; ChargeGas = 0; TotalGas = 0; }
void GasPump::AmountGasPrint() {
cout << "Amount of Gas Dispensed" << AmountGas << endl;
}
void GasPump::ChargeGasPrint() {
cout << "Amount Charge for Gas Dispensed" << ChargeGas << endl; }
void GasPump::CostPerGallonPrint() { cout << "Service Gasoline Price is " << CostPerGallon << " per gallon" << endl;
}
void GasPump::ChangeGallonPrint(double price) { CostPerGallon = price; }
void GasPump::ResetPump() { AmountGas = 0; ChargeGas = 0;
}
void GasPump::TotalGasPrint() { cout << "Your total $" << TotalGas << endl;
}
void GasPump::AmountGasPrint(int x) { // Overload calling
cout << "Press" << x << " to quit....." << endl;
int y = 0;
while (y != x) {
AmountGas = AmountGas + 0.1; ChargeGas = AmountGas * CostPerGallon; TotalGas += AmountGas; //mainGasTank -= TotalGas;
AmountGasPrint(); ChargeGasPrint(); TotalGasPrint();
cout << "Press" << x << " to quit....." << endl;
cin >> y;
/*if (mainGasTank == 0) y = x ;*/
} }
void GasPump:: FillMain(double y) { // Static Fn to fill main tank
mainGasTank = y; //passing the argument.
} double GasPump:: RemainingMainTank() { //Static Fn to
return mainGasTank; } // // void GasPump::everthingPrint() { // TotalGasPrint(); // cout << "Main Gas" << RemainingMainTank() << endl; // }
How do I build engine to (while loop ) to dispense gas? Also cout to get user input of full service or self. my code bellow one class header file and main
#include "GasPump2.h" #include using namespace std;
int main(){
GasPump pump1; //Default Construtor no parameters cout << " Gas Pump Modeling Program" << endl;
//GasPump pump2(2.00); // Contructor taking one argument as parmeter cout << "Full "; pump1.CostPerGallonPrint(); GasPump pump2(2.50); cout << "Self "; pump2.CostPerGallonPrint();
// pump1.AmountGasPrint(11);
system("pause"); return 0;
}
#include "GasPump2.h" #include using namespace std;
int main(){
GasPump pump1; //Default Construtor no parameters cout << " Gas Pump Modeling Program" << endl;
//GasPump pump2(2.00); // Contructor taking one argument as parmeter cout << "Full "; pump1.CostPerGallonPrint(); GasPump pump2(2.50); cout << "Self "; pump2.CostPerGallonPrint();
// pump1.AmountGasPrint(11);
system("pause"); return 0;
}
Write a class to model the behavior of a pump in a gas station and an associated driver program to test your class. Include the following data members in the pump class: ? Cost per gallon (assume each pump sells only one grade of gas and price varies based upon full vs. self service) ? Amount of gas dispensed for one fueling session ? Charge for gas dispensed in one fueling session ? Total amount of gas sold in gallons(an accumulator)
Note: Do not worry about running out of gas in Part A. In Part B, you will be adding a static data member to the pump class that is shared by all pump class objects, to keep track of the amount of gas in the main tank.
The pump model should include the following member functions: ? 2 constructors: ? A default constructor will set price per gallon to $3.95 and all other data members to 0. ? A one argument constructor will set price per gallon to the amount passed as an argument and set all other data members to 0. ? A function to display the amount dispensed. ? A function to display the amount charged for gas dispensed. ? A function to display the cost per gallon. ? A function to change a pumps price per gallon. ? A function to reset amount dispensed and amount charged to 0. ? 2 overloaded functions: ? A function to dispense gas in .1 gallon increments until the user wants to quit (This function will loop and continually clear the screen to simulate numbers scrolling on the gas pump charge and amount sold displays.) ? A function to dispense the $ amount of gas passed as an argument. ? A function that returns the total amount of gas sold by a single pump object.
Your driver program should create 2 instances of pump objects, one full service (@$3.95 per gallon) and one self serve (@ a lesser $ amount) and loop the pump dispensing model until the user wants to quit. Prompt each user to find out if they want full or self serve. Invalid data entries will automatically get full serve. Print the total amount of gas sold in gallons by each pump after the user quits.
part b
Modify your pump class by adding a static data member that is shared by all pump objects, to keep track of the amount of gas in the main tank. This static variable should be initialized to 0.
Additionally add 2 static member functions to the pump class: ? A static function to fill the main tank with the # of gallons passed as an argument (add this amount to the static data member). ? A static function to return the # of gallons in the main tank.
Modify your 2 dispensing functions to monitor the amount of gas left in the main tank. Dispensing should stop if the main tank is empty, a message should be displayed to the user, and the main tank should be filled.
Add one final method that prints the totals for the program run to a log file, i.e. the number of gallons sold by the full serve pump, the number of gallons sold by the self serve pump and the amount of gas remaining in the main tank. Prompt the user for the desired name of this log file.
Once you have completed Part B and tested it thoroughly with an appropriate driver program. Your program should be broken into 3 files for separate compilation. Create a header file (.h) for the class interface, a .cpp file for the implementation and a .cpp file for the driver.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started