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
|
#include <iostream>
#include "Store.hpp"
using std::cout;
using std::cin;
using std::endl;
void printVector(std::vector<std::string> vect);
int main()
{
// create store called shoprite
Store shoprite;
//Product(std::string id, std::string t, std::string d, double p, int qa);
Product apple("1000", "Granny Smith", "green apple great for baking", 1.99, 12);
Product banana("1010", "Chiquita fruit", "great source of K, yellow", 0.49, 14);
Product watermelon("1111", "Summer Fruit", "Green and juicy", 5.95, 2); // 2 left
//Customer(std::string n, std::string a, bool pm);
Customer hugh("Hugh Jass", "CMN32", false);
Customer amanda("Amanda Huggankis", "CMN33", false);
Customer ben("Ben Dover", "CMN34", true);
shoprite.addMember(&hugh);
shoprite.addMember(&amanda);
shoprite.addMember(&ben);
shoprite.addProduct(&apple);
shoprite.addProduct(&banana);
shoprite.addProduct(&watermelon);
Customer* pMemb = shoprite.getMemberFromID("CMN32");
Product* pProd = shoprite.getProductFromID("1000");
pMemb = shoprite.getMemberFromID("CMN32");
pProd = shoprite.getProductFromID("1000");
// print Member pointer
if (pMemb != nullptr)
cout << "Member pointer is " << pMemb << endl;
else
cout << "Member pointer is NULL " << pMemb << endl;
// Print Product pointer
if (pProd != nullptr)
cout << "Product pointer is " << pProd << endl;
else
cout << "Product pointer is NULL " << pProd << endl;
// Product Search
shoprite.productSearch("asdfasdf");
shoprite.productSearch("green");
shoprite.productSearch("Green");
shoprite.productSearch("fruit");
shoprite.productSearch("Fruit");
// Add Products to member carts
shoprite.addProductToMemberCart("fdsve", "CMN32"); // add invalid product to hugh's cart
shoprite.addProductToMemberCart("1000", "fdaxfe"); // add apple to invalid's cart
shoprite.addProductToMemberCart("1000", "CMN32"); // add apple to hugh's cart
printVector(hugh.getCart());
shoprite.addProductToMemberCart("1010", "CMN32"); // add banana to hugh's cart
printVector(hugh.getCart());
shoprite.addProductToMemberCart("1111", "CMN32"); // add watermelon to hugh's cart
shoprite.addProductToMemberCart("1111", "CMN32"); // add watermelon to hugh's cart
shoprite.addProductToMemberCart("1111", "CMN32"); // add watermelon to hugh's cart
printVector(hugh.getCart());
shoprite.addProductToMemberCart("1111", "CMN33"); // add watermelon to amanda's cart (should fault because quantity available is 0)
printVector(amanda.getCart());
// Checkout hugh
shoprite.checkOutMember("CMN32");
// Checkout amanda
shoprite.checkOutMember("CMN33");
// Checkout ben (no items yet)
shoprite.checkOutMember("CMN34");
// Checkout invalid ID
shoprite.checkOutMember("fdas");
cout << "amanda before ben: " << banana.getQuantityAvailable() << endl << endl;
//ben shopping
shoprite.addProductToMemberCart("1010", "CMN34"); // add banana to ben's cart
shoprite.addProductToMemberCart("1010", "CMN34"); // add banana to bens's cart
shoprite.addProductToMemberCart("1010", "CMN34"); // add banana to ben's cart
shoprite.addProductToMemberCart("1010", "CMN34"); // add banana to ben's cart
shoprite.addProductToMemberCart("1010", "CMN34"); // add banana to ben's cart
cout << "amanda after ben shops (before checking out): " << banana.getQuantityAvailable() << endl << endl;
// Checkout ben (premium member!)
shoprite.checkOutMember("CMN34");
cout << "amanda after ben shops (and checks out): " << banana.getQuantityAvailable() << endl << endl;
return 0;
}
void printVector(std::vector<std::string> vect)
{
cout << "Vector has " << vect.size() << " elements, which are: ";
for (int i = 0; i < vect.size(); i++)
{
cout << vect.at(i) << " ";
}
cout << endl;
}
|