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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
#include <iostream>
#include <iomanip>
#include <cstring>
using namespace std;
class Bakery
{
public:
Bakery() {}
Bakery(double x, double y, double z ) { price1 = x; price6 = y; price12 = z; }
void putPrice(double, double, double);
void putAmount(int w) { amount = w; }
void calcPrice();
void displayPrice();
// void newOrder();
private:
double price1;
double price6;
double price12;
double totalPrice;
double trialPrice;
double trialPrice2;
int amount;
};
void Bakery::putPrice(double a, double b, double c)
{
price1 = a;
price6 = b;
price12 = c;
}
void Bakery::calcPrice()
{
double calcPrice1, calcPrice6, calcPrice12 = 0;
calcPrice12 = (amount/12) * price12;
calcPrice6 = (amount/6) * price6;
calcPrice1 = amount * price1;
totalPrice = calcPrice12;
trialPrice = (amount%12) * calcPrice1;
(trialPrice >= calcPrice12 ? totalPrice += calcPrice12 : trialPrice += (amount%12)/6 * calcPrice6 );
(((amount%6) * calcPrice1) >= trialPrice ? totalPrice += calcPrice6 : totalPrice = (amount * calcPrice1));
/* if(trialPrice >= calcPrice12)
{
totalPrice += calcPrice12;
}
if (trialPrice < calcPrice12)
{
trialPrice += (amount%12)/6 * calcPrice6;
trialPrice2 += (amount%6) * calcPrice1;
if (trialPrice2 >= calcPrice6)
{
totalPrice += calcPrice6;
}
else
{
totalPrice += amount * calcPrice1;
}
} */
}
void Bakery::displayPrice()
{
cout << "Amount due for this customer is: " << totalPrice << endl << endl;
}
/* void Bakery::newOrder()
{
bool order = false;
while (order != true)
{
char input;
cout << "Would you like to take another order? ";
cin >> input;
if (input == 'Y' || input == 'y')
{
order = true;
cout << endl << endl << endl;
return;
}
else if (input == 'N' || input == 'n')
{
return;
}
}
} */
int main()
{
Bakery myMuffinShop;
double single, half, dozen;
int amount;
cout << "Enter the price of a single muffin, half-dozen, and dozen" <<
endl;
cin >> single >> half >> dozen;
if (!cin.eof() && cin.good())
{
myMuffinShop.putPrice(single,half,dozen);
// do
// {
cout << "\nHow many muffins does the customer want to order? ";
cin >> amount;
if (!cin.eof() && cin.good() && amount > 0)
{
myMuffinShop.putAmount(amount);
myMuffinShop.calcPrice();
myMuffinShop.displayPrice();
// myMuffinShop.newOrder();
}
// }
}
else
{
cout << "\nInvalid prices entered." << endl;
cout << "Program terminating..." << endl << endl;
return 0;
}
}
|