Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ PLEASE I want to modify the code at the bottom to do those stuff: Modify your pump class by adding a static data member

C++ PLEASE

I want to modify the code at the bottom to do those stuff:

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.

The Code:

The CPP code:

#include "Header.h"

int main()

{

Pump p1;

Pump p2(2);

int ch;

float amount, total;

while (1)

{

cout << " Do you want full service or self-service? Press 1 for Full or 2 for Half or 3 to Quit" << endl;

cin >> ch;

if (ch == 1)

{

cout << "Enter amount of gas to get : ";

cin >> amount;

p1.full_service(amount);

total = p1.gas_sold();

p1.reset();

p2.reset();

}

else if (ch == 2)

{

p2.self_service();

total = p2.gas_sold();

}

else if (ch == 3)

{

cout << "Total Gas bought $" << total << endl;

exit(1);

}

else

{

cout << "Enter amount of gas to get : ";

cin >> amount;

p1.full_service(amount);

}

}

return 0;

}

The Header Code:

#include

#include

using namespace std;

class Pump

{

private:

float cost, gas, charge, total;

public:

Pump()

{

cost = 0.95;

gas = 0;

}

Pump(float x)

{

cost = x;

gas = 0;

}

void amount_dispensed()

{

cout << " Amount dispensed : " << gas;

}

void charged()

{

cout << " Amount charged for gas dispensed : $" << charge;

}

void cost_per_gallon()

{

cout << " Cost per gallon is $ " << cost;

}

void change_cost()

{

cout << " Enter New Cost per Gallon : ";

cin >> cost;

}

void reset()

{

gas = 0;

charge = 0;

}

void self_service()

{

char ch;

while (true)

{

cost_per_gallon();

cout << "Press Q to Stop.Or Press Any other key to continue filling. ";

cin.get(ch);

if (ch == 'Q' || ch == 'q')

break;

system("cls");

gas += 0.95;

charge = cost * gas;

total += charge;

cout << "Cost : $" << charge;

cout<<"Amount:"<

}

cout << "Cost:$ " << charge << " Gas Amount: " << gas << endl;

}

void full_service(float x)

{

charge = x; \

cost_per_gallon();

cout << endl;

gas = charge / cost;

total += charge;

amount_dispensed();

cout << endl;

cout << "Your total is: " <<"$"<< charge;

cout << endl;

}

float gas_sold()

{

return total;

}

};

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

Pro Oracle Fusion Applications Installation And Administration

Authors: Tushar Thakker

1st Edition

1484209834, 9781484209837

More Books

Students also viewed these Databases questions

Question

Do you prefer cooking dinner or going out?

Answered: 1 week ago