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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
#include <iostream>
#include <string>
using namespace std;
class Transaction {
public:
Transaction(unsigned doughnuts, unsigned carburetors = 0, unsigned racquets = 0);
unsigned getDoughnuts() const; // return the number of doughnuts purchased in this transaction
unsigned getCarburetors() const; // return the number of carburetors purchased in this transaction
unsigned getRacquets() const; // return the number of racquets purchased in this transcation
double getSubtotal() const; // return the total cost of this purchase, excluding sales tax
double getTotal() const; // return the total cost of this purchase, including sales tax
Transaction & setDoughnuts(unsigned doughnuts);
Transaction & setCarburetors(unsigned carburetors);
Transaction & setRacquets(unsigned racquets);
private:
unsigned dough, carb, rac;
double subtotal = 0, total = 0;
}; // class Transaction
void report(const Transaction transaction[], unsigned elements);
int main() {
Transaction One(0), Two(0), Three(0), Four(0), Five(0);
unsigned doughs, carbs, racs;
cout << "How many Doughnuts, Carburetors, and Racquets? " << endl;
cin >> doughs >> carbs >> racs;
One.setDoughnuts(doughs);
One.setCarburetors(carbs);
One.setRacquets(racs);
cout << endl;
cout << "Get functions: " << endl;
cout << "Number of Doughnuts: " << One.getDoughnuts() << endl;
cout << "Number of Carburetors: " << One.getCarburetors() << endl;
cout << "Number of Racquets: " << One.getRacquets() << endl << endl;
cout << "Total functions: " << endl;
cout << "Subtotal is: " << One.getSubtotal() << endl;
cout << "Total is: " << One.getTotal() << endl << endl;
Transaction January[5] = { One, Two, Three, Four, Five };
cout << "Report function: " << endl;
cout << "Business done this month: " << endl;
report(January, 5);
cout << endl << endl;
}
void report(const Transaction transaction[], unsigned elements) {
double dTotal = 0, cTotal = 0, rTotal = 0;
double Total = 0, Subtotal = 0;
for (unsigned count = 0; count < elements; count++) {
dTotal = transaction[count].getDoughnuts + dTotal;
cTotal += transaction[count].getCarburetors;
rTotal += transaction[count].getRacquets;
}
dTotal *= 0.4;
cTotal *= 200;
rTotal *= 75;
Total = dTotal*(1.09) + cTotal*(1.09) + rTotal;
Subtotal = dTotal + cTotal + rTotal;
}
Transaction & Transaction::setDoughnuts(unsigned doughnuts) {
dough = doughnuts;
return *this;
}
Transaction & Transaction::setCarburetors(unsigned carburetors) {
carb = carburetors;
return *this;
}
Transaction & Transaction::setRacquets(unsigned racquets) {
rac = racquets;
return *this;
}
Transaction::Transaction(unsigned doughnuts, unsigned carburetors, unsigned racquets) {
setDoughnuts(doughnuts);
setCarburetors(carburetors);
setRacquets(racquets);
}
unsigned Transaction::getDoughnuts() const {
return dough;
}
unsigned Transaction::getCarburetors() const {
return carb;
}
unsigned Transaction::getRacquets() const {
return rac;
}
double Transaction::getSubtotal() const {
double subtotal = (0.4*dough) + (200 * carb) + (75 * rac);
return subtotal;
}
double Transaction::getTotal() const {
double dTotal = (0.4*dough);
double cTotal = (200 * carb);
double rTotal = (75 * rac);
double total = dTotal*(1.09) + cTotal*(1.09) + rTotal;
return total;
}
|