Hi all, NEED HELP PLEASE!!!(i'm not good doing C++)I 'm having hard time doing this Class problem. My task is to implement the class Table. Have to add it to the file that contains the main program.
I have to decide what private data members of the class needs and then the following methods have to be implemented:
default constructor
void addItem(string itemName, double price): adds an item to the tables bill.
void printBill()rints the tables bill onto the screen.
#include <string>
#include <iostream>
// put the Table class here
/* -------------------------------------------------
// don't change anything below this line - but make sure
// you understand what the program is doing
// this structure and the constant array below define the list
// of items that are served in our restaurant.
//
struct MenuItem
{
char name[30];
double price;
};
const MenuItem itemList[] = {
{ "Pizza", 5.90 },
{ "Salad", 3.99 },
{ "Lasagne", 7.99},
{ "Pepsi", 1.00},
{ "Sprite", 1.00},
{ "", 0.0 } // the last item terminates the list
};
//
// prototypes
//
int main();
void addItemFromList(Table&);
//
// implementation
//
int main()
{
Table t;
int choice; // holds the choice entered by the user
do
{
cout << "----------------------------------" << endl;
cout << "Main Menu" << endl << endl;
cout << "1 - Add Menu Item" << endl;
cout << "2 - Print Bill" << endl;
cout << "3 - Quit" << endl << endl;
cout << "Enter choice:";
cin >> choice;
cout << "----------------------------------" << endl;
switch(choice)
{
case 1 : addItemFromList(t); // let the user choose the item to be added
break;
case 2 : t.printBill(); // print the bill for the user
break;
}
}
while (choice != 3);
return(0);
}
void addItemFromList(Table& t)
{
int choice;
int max;
// count available items in itemList
for(max = 0; (itemList[max].price != 0.0); max++);
do
{
cout << "----------------------------------" << endl;
for(int i = 1; i <= max; i++)
cout << i << " - " << itemList[i-1].name << endl;
cout << max+1 << " - Go to main menu" << endl << endl;
cout << "Enter choice: ";
cin >> choice;
cout << "----------------------------------" << endl;
if ((choice >= 1) && (choice <= max))
t.addItem(itemList[choice-1].name, itemList[choice-1].price);
}
while (choice != (max + 1)); // do while the user does not choose quit
}