Hi, im having trouble writing the class for this homework assignment and im hoping you guys can help me out.
You are to design a Class that will represent a restaurant order. The Class will have two public methods,
one to place an order and the second to calculate and display the order items and prices, the order subtotal,
the tip, the tax, and the check total. The method to place the order will allow the User to enter up to
5 order items. The method is to present a Menu of items for selection. You are to create two const static,
parallel arrays for the menu items, one for the item descriptions (string) and the second for the item costs
(double), which, of course, will be class private data members. You are to provide 10 items for selection.
You might want to find a restaurant menu online to use for your 10 items, or you may use the ones
shown in the example below. You will store the items selected in another one-dimensional array. The
element values of this array are the element values of the selected items in the two static arrays. You
are to use a Sentinel value to terminate the items entry (one of the Menu selections) OR terminate entry
after 5 items have been entered. You are to clear the Console screen (see page 355 in the text) and
present the User with a Menu of items and costs (from the two parallel arrays), two items per line. Each
item shall have an integer selection number that the User will use to select the item, as an example:
1: Breakfast roll $1.75.
Display a prompt following the Menu presentation to enter the next item, indicating the order item number
(1 – 5, maximum).
The second, public class method, which displays the customer’s check will sub-total the cost of the items
ordered, calculate a tip based on the sub-total amount only, then calculate the tax, again based only on
the sub-total amount, then calculate the check total as the sum of the order subtotal, the tax, and the tip.
The method will display the entire order (each item description and cost), the tax, the tip, and the check
total. If no items were ordered, do not display a check, but display a message indicating the order was
cancelled (use the RETurn value from method placeOrder to determine this case).
Your project must meet these minimum requirements:
Name the class: RestaurantCheck
Include a Constructor that takes two arguments, the tax rate and the tip, both as a percentage:
1. Validate that the tax rate is greater than or equal to 1% (0.01) and less than or equal to
12% (0.12). If the value passed to the Constructor is invalid, set the tax rate to 0.065
2. Validate that the tip percentage is greater than or equal to 5% (0.05) and less than or
equal to 20% (0.20). If the value passed to the Constructor is invalid, set the tip to 15%
(0.15)
Include a Default Constructor that sets the tax rate to 0.065 (6.5%) and the tip percentage to 15%
The default values and the limit values should be declared as class private, static const values.
Provide a public static class method, named testTaxRate, to test a tax rate percentage value
passed to it as a parameter. The method will RETurn a bool value, true: The parameter value is
valid.
Provide a public static class method, named testTipRate, to test a tip percentage value passed to
it as a parameter. The method will RETurn a bool value, true: The parameter value is valid.
Name the public class method to place an order: placeOrder
Name the public class method to display the check: issueCheck
Create a private class method to display the Menu and name it: presentMenu
Note: This method is called by method placeOrder to present the menu of items
Create a private class method to calculate the tax and name it: calculateTax
Create a private class method to calculate the tip and name it: calculateTip
When displaying the check, make sure all amounts have their decimal points vertically aligned
and display 2 digits of precision to the right of the decimal point (all amounts are double)
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
|
double taxRate = 6.5,
tipRate = 15;
cout << "Enter the tax rate, as a %: ";
cin >> taxRate;
cout << "Enter the tip, as a %: ";
cin >> tipRate;
system("cls");
cout << setw(26) << "Joe's Diner" << endl;
cout << setw(22) << "Menu" << endl << endl;
cout << "1: BLT Sandwich" << setw(34) << "2: Ham and Cheese Sandwich" << endl;
cout << "3: Hot Chocolate" << setw(27) << "4: Breakfast Special" << endl;
cout << "5: House Sandwich" << setw(28) << "6: Full Stack Pancakes" << endl;
cout << "7: Club Sandwich" << setw(16) << "8: Coffee" << endl;
cout << "9: Ham and Eggs" << setw(25) << "10: Steak and Eggs" << endl;
cout << "11: Order Complete" << endl << endl;
int Choice = 0;
int itemNum = 1;
int i = 1;
char doneOrder = 'N';
while (Choice != 11)
{
cout << "Enter Order item #" << itemNum << ": ";
itemNum++;
cin >> Choice;
if (Choice > 11)
{
cout << "Please enter a number between 1 and 11." << endl;
itemNum--;
cout << "Enter Order item #" << itemNum << ": ";
cin >> Choice;
itemNum++;
}
menuOrder[i] = Choice;
i++;
}
cout << fixed << setprecision(2);
cout << endl << "Confirming your customer's Order:" << endl;
i = 1;
int l = 1;
while (doneOrder != 'Y' && doneOrder != 'y')
{
cout << "Item " << l << ":" << endl;
l++;
Choice = menuOrder[i];
switch (Choice)
{
case 1:
cout << menu[0] << ", Price: $" << menuPrice[0] << endl;
menuOrder[i] = 1;
i++;
break;
case 2:
cout << menu[1] << ", Price: $" << menuPrice[1] << endl;
menuOrder[i] = 2;
i++;
break;
case 3:
cout << menu[2] << ", Price: $" << menuPrice[2] << endl;
menuOrder[i] = 3;
i++;
break;
case 4:
cout << menu[3] << ", Price: $" << menuPrice[3] << endl;
menuOrder[i] = 4;
i++;
break;
case 5:
cout << menu[4] << ", Price: $" << menuPrice[4] << endl;
menuOrder[i] = 5;
i++;
break;
case 6:
cout << menu[5] << ", Price: $" << menuPrice[5] << endl;
menuOrder[i] = 6;
i++;
break;
case 7:
cout << menu[6] << ", Price: $" << menuPrice[6] << endl;
menuOrder[i] = 7;
i++;
break;
case 8:
cout << menu[7] << ", Price: $" << menuPrice[7] << endl;
menuOrder[i] = 8;
i++;
break;
case 9:
cout << menu[8] << ", Price: $" << menuPrice[8] << endl;
menuOrder[i] = 9;
i++;
break;
case 10:
cout << menu[9] << ", Price: $" << menuPrice[9] << endl;
menuOrder[i] = 10;
i++;
break;
case 11:
cout << endl << "Is this order correct? (Y or N):";
cin >> doneOrder;
break;
}
}
system("cls");
double total = 0;
double tax;
double tip;
cout << setw(26) << "Joe's Diner" << endl;
cout << setw(23) << "Check" << endl << endl;
i = 0;
while (menuOrder[i] != 11)
{
Choice = menuOrder[i];
i++;
switch (Choice)
{
case 1:
cout << menu[0] << setw(20) << " $ " << menuPrice[0] << endl;
total = total + menuPrice[0];
break;
case 2:
cout << menu[1] << setw(9) << " $ " << menuPrice[1] << endl;
total = total + menuPrice[1];
break;
case 3:
cout << menu[2] << setw(19) << " $ " << menuPrice[2] << endl;
total = total + menuPrice[2];
break;
case 4:
cout << menu[3] << setw(15) << " $ " << menuPrice[3] << endl;
total = total + menuPrice[3];
break;
case 5:
cout << menu[4] << setw(18) << " $ " << menuPrice[4] << endl;
total = total + menuPrice[4];
break;
case 6:
cout << menu[5] << setw(14) << " $ " << menuPrice[5] << endl;
total = total + menuPrice[5];
break;
case 7:
cout << menu[6] << setw(19) << " $ " << menuPrice[6] << endl;
total = total + menuPrice[6];
break;
case 8:
cout << menu[7] << setw(26) << " $ " << menuPrice[7] << endl;
total = total + menuPrice[7];
break;
case 9:
cout << menu[8] << setw(20) << " $ " << menuPrice[8] << endl;
total = total + menuPrice[8];
break;
case 10:
cout << menu[9] << setw(17) << " $ " << menuPrice[9] << endl;
total = total + menuPrice[9];
break;
}
}
cout << "-------------------------- ---------" << endl;
cout << "Sub Total" << setw(23) << "$ " << total << endl;
tax = total * (taxRate/10);
tip = total * (tipRate/10);
cout << "Tax (" << taxRate << "%)" << setw(21) << "$ " << tax << endl;
cout << "Tip (" << tipRate << "%)" << setw(20) << "$ " << tip << endl;
cout << "-------------------------- ---------" << endl;
total = total + tax + tip;
cout << "Total Due" << setw(23) << "$ " << total << endl << endl;
|