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
|
void calculateShipDay(int&day, int&shipDay, int&num, double&cost, double&height, double&weight, double&length, double&width, double&rate, double&vol, double&ship, double&tax, double&shipCost)
{
//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);
tax = (tax*cost)/100;
//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);
tax = (tax*cost)/100;
//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);
tax = (tax*cost)/100;
//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);
tax = (tax*cost)/100;
//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, double shipCost, double cost, int quantity)
{
subtotal = (shipCost + cost)*quantity;
return subtotal;
}
float calculateTotal(float&tax, float&subtotal)
{
float total;
total = subtotal + tax;
return total;
}
void testTax()
{
double cityTax = 6.4;
double cost = 7.00;
float final = (cityTax*cost)/100;
cout.setf(ios::fixed);
cout.precision(2);
cout.setf(ios::fixed);
cout.precision(2);
cout << "Test tax = $" << final << endl;
}
void testTotal()
{
float tax = 0.45;
float subtotal = 1145.60;
float shipCost = 13.00;
float final = tax + subtotal + shipCost;
cout << "Test total = $" << final << endl;
}
void testShipping()
{
double cost = 11.50;
double height = 9;
double weight = 5;
double width = 5;
double length = 3;
double rate = 5.4;
double vol;
double ship;
double shipCost;
vol = height*width*length;
ship = vol/1000;
cout.setf(ios::fixed);
cout.precision(2);
float final = cost;
cout << "Test shipping = $" << shipCost << endl;
}
void testSubtotal()
{
int quantity = 4;
double cost = 6.25;
float subtotal = 90.14;
subtotal = subtotal + (cost*quantity);
float final = subtotal;
cout << "Test subtotal = $" << final << endl;
}
int loadRates (Info rates [])
{
int i = 0;
ifstream inStream;
inStream.open("zipcode-list.txt");
if (inStream.fail())
{
cout << "File couldn't be opened!" << endl;
return -1;
}
while (i < 3000)
{
inStream >> rates[i].zipcode >> rates[i].taxrate >> rates[i].USPS >> rates[i].UPS >> rates[i].fedEx >> rates[i].ziplength;
if (rates[i].ziplength > 5)
cout << "Invalid zipcode!" << endl;
else if (rates[i].taxrate > 1 || rates[i].taxrate < 0)
cout << "Invalid taxrate!" << endl;
else if (rates[i].USPS < 0)
cout << "Invalid USPS rate!" << endl;
else if (rates[i].UPS < 0)
cout << "Invalid UPS rate!" << endl;
else if (rates[i].fedEx < 0)
cout << "Invalid FedEx rate!" << endl;
else i++;
}
inStream.close();
return i;
}
void emptyCart(int&num, char&choice, string&cart)
{
cout << "Would you like to empty your cart? (Y or N)" << endl;
cin >> choice;
if (choice == 'y' || choice == 'Y')
{
cout << "Choose between: " << endl;
cout << "1. A specific item" << endl;
cout << "OR" << endl;
cout << "2. The whole cart" << endl;
cin >> num;
cin.clear();
cin.ignore();
if(num == 1)
{
cout << "What item would you like to remove?" << endl;
cin >> num;
}
else if(num == 2)
{
cart = " ";
}
}
else displayMenu();
}
|