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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
|
int getInventoryCount(int id) {
int count = -1;
for (int i = 0; count == -1 && i < size; i++)
if (id == itemList[i].getId()) {
count = itemList[i].getInventory();
}
return count;
}
/*
* This method will open up a file based on the input fileName parameter. This file contains all of the
* items. It will read in each item from the file and save it to the catalog array. You can use the setItem()
* method in the item class to update all of the values.
* For each line read in from the file, it needs to increment the size property.
*/
void loadInventory(string fileName, Item info, int id, int h, int w, int l, int count, double p, double wt, string n, string r)
{
ofstream outStream;
ifstream inStream;
string line;
inStream.open("inventory.txt");
if (inStream.fail()) {
cout << "Please enter the file name: " << endl;
cin >> fileName;
}
}
};
// OTHER STORE FUNCTIONS GO HERE - MAINTAINCART, CALCULATETAX, ETC.
int maintainCart(Cart&cartItem, Catalog catalogItem, int id, int inventoryCount, Item info, int value)
{
cout << "How many would you like to buy?" << endl;
cin >> cartItem.qtyPurchased;
catalogItem.printCatalog();
while (cartItem.qtyPurchased < 1)
{
cout << "Invalid amount. You must choose one item.";
cin >> cartItem.qtyPurchased;
}
catalogItem.getInventoryCount(id);
info.setInventory(value);
inventoryCount++;
return cartItem.qtyPurchased;
cout << endl;
char choice;
cout << "Would you like to continue shopping? (Y/N)" << endl;
cin >> choice;
cout << endl;
}
string createCustomer (string&name, string&address)
{
cout << "Time to create your customer account." << endl << endl;
cout << "Please enter your name: ";
cin >> name;
cin.clear();
cin.ignore();
cout << "Please enter your address: ";
getline(cin, address);
cout << "Hello " << name << ", your address is " << address << "." << endl;
cout << "Your customer account has been created!" << endl;
cout << endl;
return name;
return address;
}
int displayMenu()
{
int num;
cout << "Please choose a menu option: " << endl;
cout << "1. Create Customer Account" << endl;
cout << "2. Shop for Items" << endl;
cout << "3. Proceed to Checkout" << endl;
cout << "4. Exit Store" << endl;
cout << "5. Debug" << endl;
cout << "6. Empty Cart" << endl;
cin >> num;
cout << endl;
return num;
}
void itemRank (int&num)
{
if (num == 1)
cout << "RATING: ***" << endl;
else if (num == 2)
cout << "RATING: ****" << endl;
else if (num == 3)
cout << "RATING: **" << endl;
else if (num == 4)
cout << "RATING: *" << endl;
else
cout << "RATING: *****" << endl;
}
void catalogChoice(float cost, float price1[], int&num, int id, int count, int value, string&cart, char&choice, Cart&cartItem, Catalog catalogItem, Item info)
{
catalogItem.displayCatalog(cartItem);
string item [5] = {"Ton-Tongue Toffee", "Self-Writing Quill", "Wildfire Whizbangs", "Felix Felicis", "Dragon Fire"};
cout << "You have picked " << item[num] << "." << endl;
itemRank(num);
cost = price1[num];
cout << "Your current total is $" << cost << "." << endl;
cart += item[num];
maintainCart(cartItem, catalogItem, id, count, info, value);
//prompt user about shopping
cout << "Would you like to continue shopping? (Y or N)";
cin >> choice;
cout << endl;
}
void calculateShipping(float cost, float height, float weight, float length, float width,
float rate, float vol, float ship, float&shipCost, Cart cartItem)
{
//package dimensions for cost
cout << "Package's weight?" << endl;
cin >> weight;
cout << endl;
cout << endl;
vol = height*width*length;
ship = vol/1000.0;
cout.setf(ios::fixed);
cout.precision(2);
shipCost = (rate*weight) + ship;
cout.setf(ios::fixed);
cout.precision(2);
cout << "Total shipping cost: $" << shipCost << endl;
}
float calculateTax(float&tax, float&taxCost, float&cityTax, float&cost, int&quantity, float&ship, float&height, float&weight,
float&length, float&width, float&rate, float&vol, int&day, int&shipDay)
{
int cityChoice;
//ask user to choose a store in certain cities
cout << "We offer business in: " << endl;
do{
cout << "1. Los Angeles" << endl;
cout << "2. San Diego" << endl;
cout << "3. Beverly Hills" << endl;
cout << "Choose a city: " << endl;
cin >> cityChoice;
if (cityChoice < 1 || cityChoice > 3)
cout << "Our business isn't located there!" << endl;
}while (cityChoice < 1 || cityChoice > 3);
cout << endl;
switch (cityChoice)
{
case 1:
cityTax = 9.00;
break;
case 2:
cityTax = 9.00;
break;
case 3:
cityTax = 8.00;
break;
}
taxCost = (cityTax/100.0) * cost;
return taxCost;
}
void calculateShipDay(int&day, int&shipDay, int&num, float&cost, float&height, float&weight, float&length,
float&width, float&rate, float&vol, float&ship, float&tax, float&shipCost, Cart&cartItem)
{
//user selected method
cout << "What day of the month is it?" << endl;
cin >> shipDay;
cin.clear();
cin.ignore();
//ask user about shipping method
cout << "Which shipping method do you want to use?" << endl;
cout << "1. USPS (10 days)" << endl;
cout << "2. UPS (7 days)" << endl;
cout << "3. FedEx (4 days)" << endl;
cin >> num;
cin.clear();
cin.ignore();
cout << endl;
switch (num)
{
case 1:
day = 10;
rate = 1.55;
calculateShipping(cost, height, weight, length, width, rate, vol, ship, shipCost, cartItem);
tax = (tax*cost)/100.0;
//estimate shipping date
if (shipDay > 0 && shipDay < 19)
{
cout << "Your product will arrive on day " << (abs)(day + shipDay) << " of this month." << endl;
cout << endl;
}
else if (shipDay >= 19 && shipDay <=30)
{
cout << "Your product will arrive on day " << (abs)(30 - (day + shipDay)) << " of next month." << endl;
cout << endl;
}
break;
case 2:
day = 7;
rate = 1.65;
calculateShipping(cost, height, weight, length, width, rate, vol, ship, shipCost, cartItem);
tax = (tax*cost)/100.0;
//estimate shipping date
if (shipDay > 0 && shipDay < 27)
{
cout << "Your product will arrive on day " << (abs)(day + shipDay) << " of this month." << endl;
cout << endl;
}
else if (shipDay >= 27 && shipDay <= 30)
{
cout << "Your product will arrive on day " << (abs)(30 - (day + shipDay)) << " of next month." << endl;
cout << endl;
}
break;
case 3:
day = 4;
rate = 1.72;
calculateShipping(cost, height, weight, length, width, rate, vol, ship, shipCost, cartItem);
tax = (tax*cost)/100.0;
//estimate shipping date
if (shipDay > 0 && shipDay < 25)
{
cout << "Your product will arrive on day " << (abs)(day + shipDay) << " of this month." << endl;
cout << endl;
}
else if (shipDay >= 25 && shipDay <= 30)
{
cout << "Your product will arrive on day " << (abs)(30 - (day + shipDay)) << " of next month." << endl;
cout << endl;
}
break;
default:
day = 10;
rate = 1.55;
calculateShipping(cost, height, length, weight, width, rate, vol, ship, shipCost, cartItem);
tax = (tax*cost)/100.0;
//estimate shipping date
if (shipDay > 0 && shipDay < 19)
{
cout << "Your product will arrive on day " << (abs)(day + shipDay) << " of this month." << endl;
cout << endl;
}
else if (shipDay >= 19 && shipDay <=30)
{
cout << "Your product will arrive on day " << (abs)(30 - (day + shipDay)) << " of next month." << endl;
cout << endl;
}
break;
}
}
float calculateSubtotal(float&subtotal, float&shipCost, float cost, int quantity)
{
subtotal = (shipCost + cost)*quantity;
return subtotal;
}
float calculateTotal(float&tax, float&subtotal, float&total)
{
total = subtotal + tax;
return total;
}
void testTax()
{
float cityTax = 6.4;
float cost = 7.00;
float final = (cityTax*cost)/100.0;
cout.setf(ios::fixed);
cout.precision(2);
cout.setf(ios::fixed);
cout.precision(2);
cout << "Test tax = $" << final << endl;
}
|