generated from Auburn-University-COMP-3000/Assignment_4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq1.cpp
55 lines (49 loc) · 1.24 KB
/
q1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <iomanip>
using namespace std;
class GasPump {
private:
double amountDispensed,
amountCharged,
costPerGallon,
totalGas,
totalCost;
public:
double cost,
time;
double getAmountDispensed() {
amountDispensed = 0.10 * time;
return amountDispensed;
}
double getAmountCharged() {
amountCharged = getAmountDispensed() * cost;
return amountCharged;
}
double getCostPerGallon() {
costPerGallon = cost;
return costPerGallon;
}
void reset() {
amountDispensed = 0.0;
amountCharged = 0.0;
}
};
int main() {
GasPump pump;
char fill = 'x';
do {
cout << "Enter cost of gas per gallon: $";
cin >> pump.cost;
cout << "Enter how long gas is pumped (in seconds): ";
cin >> pump.time;
pump.getAmountDispensed();
pump.getAmountCharged();
cout << "Amount of gas dispensed (in gallons): " << fixed << setprecision(2) << pump.getAmountDispensed() << endl;
cout << "Amount charged for gas: $" << fixed << setprecision(2) << pump.getAmountCharged() << endl;
cout << "The cost per gallon: $" << fixed << setprecision(2) << pump.getCostPerGallon() << endl;
cout << "Enter Y to dispense again: ";
cin >> fill;
}
while(fill == 'Y');
return 0;
}