This week you will start on an Italian Restaurant Ordering Program. For starters
ID: 3688094 • Letter: T
Question
This week you will start on an Italian Restaurant Ordering Program.
For starters, you will create an abstract base class called menuItem. This will have an attribute of name, a method getName, virtual method getPrice, and virtual method toString (which returns a string with the item name, description, and price) You will create subclasses (all of which extend from menuItem) for
* Pizza,
personal,
medium,
large
family
* Sandwich
6 Inch
Foot Long
* Appetizer
o Wings
Traditional
Boneless
o Bread
Cheesy Bread
Garlic Bread
For starters (we will revise this later):
- Pizzas will have a price based on their size ($5.99, $6.99, $12.99, $14.99).
- Sandwiches will be priced based on size ($6.00, $8.00)
- Wings will cost $.70 per boneless and $.60 per traditional (to keep it simple each wing order
will have a type and quantity – no mixing).
- Bread will be $7.99 for Cheesy and $6.99 for garlic.
Create a main program that will allow you to build a list of menu items ordered. Add at least one item
from each category to your order and then print out the list of items ordered (name, description, and
price). Display the number of items ordered and the total price.
Explanation / Answer
// ConsoleApplication2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
#include<string>
#include<iomanip>
#include<cstdlib>// allows use of system pause
using namespace std;
struct menuItemType
{
string menuItem;
double menuPrice;
};
void getdata(menuItemType[], menuItemType[], int&);// array for user to enter data
void showMenu(menuItemType[], int);// array displaying options
void printCheck(menuItemType[], int); //array stores data
int main()
{
int items = 0;
menuItemType menuList[] = {
"Pizza (Personel) ", 5.99,
"Pizza (Medium) ",6.99,
"Pizza (Large) ",12.99,
"Pizza (Family) ",14.99,
"Sandwhich(6 inch) ",6,
"Sandwhich(footlong) ",8,
"Wings(Traditional) ",0.6,
"Wings(Boneless) ",0.7,
"Bread(cheesy Bread) ",7.99,
"bread(Garlic Bread) ",6.99,
};
menuItemType order[10];
cout << "Welcome to the Baltazar Kitchen! Menu: Item: Price: ";
showMenu(menuList, 10);// displays menu directly underneath item
getdata(menuList, order, items);// user inputs data
printCheck(order, items);//stores and asks for other items
system("pause");
return 0;
}
void printCheck(menuItemType order[], int items)
{
int i;
double total = 0, tax;
cout << "Your Check Ordered Items Item price ";
showMenu(order, items);
for (i = 0; i<items; i++)
total += order[i].menuPrice;
cout << " Item total " << "$" << setprecision(2) << fixed << total << endl;
tax = total*.07;//standard tax for st. louis area
cout << "Tax " << "$" << setprecision(2) << fixed << tax << endl;
cout << "Amount Due " << "$" << setprecision(2) << fixed << total + tax << endl;
}
void getdata(menuItemType menu[], menuItemType order[], int& items)
{
char yesno = 'Y';
int n;
while (toupper(yesno) == 'Y')
{
cout << "Enter your order item number: ";
cin >> n;
while (n<1 || n>10)
{
cout << "invalid item number ";
cout << "Enter your order item number: ";
cin >> n;
}
order[items].menuItem = menu[n - 1].menuItem;
order[items].menuPrice = menu[n - 1].menuPrice;
items++;
cout << "Would you like another item?(y/n)? ";
cin >> yesno;
}
}
void showMenu(menuItemType a[], int n)
{
int i;
for (i = 0; i<n; i++)
cout << i + 1 << ". " << setw(16) << left << a[i].menuItem << "$" << setprecision(2) << fixed << a[i].menuPrice << endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.