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;
#include "defs.h" // Specifies field widths for grocery receipt
#include "Item.h"
#include "CannedGood.h"
#include "Produce.h"
#include "Coupon.h"
int main()
{
Item* items[100]; // Array of pointers to Items to checkout
int numItems = 0; // Number of Items added to the items array
int totalCost = 0; // Total cost of all the Items to checkout
// Add Items to be checked out
items[numItems++] = new Produce("Bananas", 5.3, 49);
items[numItems++] = new CannedGood("Vegetable Soup",89);
items[numItems++] = new Produce("Apples", 3.299, 109);
items[numItems++] = new CannedGood("Green Beans",59);
items[numItems++] = new CannedGood("Corn",49);
items[numItems++] = new CannedGood("Baked Beans",79);
items[numItems++] = new Produce("Watermelon", 11.303, 89);
items[numItems++] = new CannedGood("Fruit Cocktail",45);
items[numItems++] = new CannedGood("Tomato Soup",49);
items[numItems++] = new Coupon("Vegetable Soup",10);
items[numItems++] = new Coupon("Corn",15);
// Output the grocery receipt header
cout << "CSC234 Grocery Store" << endl
<< setfill('-') << setw(NAME_WIDTH + COST_WIDTH) << ""
<< setfill(' ')
<< endl << endl;
// Print the Items on the grocery receipt
for (int i = 0; i < numItems; ++i)
{
items[i]->print(cout);
cout << endl << endl;
// Add cost of current Item to total cost
totalCost += items[i]->cost();
}
// Print out the total cost
cout << left << setw(NAME_WIDTH) << "Total Cost"
<< right << fixed << setprecision(2)
<< setw(COST_WIDTH) << totalCost/100.0
<< endl;
system("pause");
return 0;
}
|