this is the question
Write two classes
Class RestaurantMenu that has the following members
class RestaurantMenu
{
double price[10];
string Menu[10];
int numMeals;
public:
RestaurantMenu();
void AddToMenu(string s, double d);
void DeleteFromMenu(string s);
void ShowMenu();
double FindMeal(string s);
};
The Constructor: will fill the price array with zeros and fill the Menu array with empty strings and make the numMeals equal zero.
Put the following in the object by default (Mansaf , 2.7) (Burger, 1.50) (Falafel , 0.5)
AddToMenu this function will add a new item to the menu Ex. AddToMenu(“Salad”, 0.30).
DeleteFromMenu function will delete an item from the menu by finding the Meal name and making it empty string and the price equal to zero and decrementing the numMeals. If the Meal name is not found print any message.
ShowMenu function wil print the menu (Item, Price)
FindMeal function will search the array Menu for the string s and return its price otherwise if it is not found it will return return -1
Class RestaurantOrder that has the following members
class RestaurantOrder
{
double Bill[10];
string order[10];
public:
RestaurantOrder();
~RestaurantOrder();
void AddToOrder(RestaurantMenu obj, string s);
void DeleteFromOrder(string s);
double CalculateBill();
};
The constructor: will fill the array Bill with zeros and the array order with empty strings
The Destructor will print a Good Bye
AddToOrder function will search for the string s in the Menu object (obj) to find its price and add the string and the price to the order
DeleteFromOrder function will search for the string s in the order object to delete it by making its Bill equal zero and its name equal empty string
CalculateBill function will return the summation of the Bill
and this is my work and the problem insid the code :
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
|
#include <iostream>
#include <string>
using namespace std;
class RestaurantMenu
{
double price[10];
string Menu[10];
int numMeals;
public:
RestaurantMenu();
void AddToMenu(string s, double d);
void DeleteFromMenu(string s);
void ShowMenu();
double FindMeal(string s);
};
RestaurantMenu ::RestaurantMenu()
{
for(int i=0;i<10;i++)
{
price[i]=0;
}
for(int i=0;i<10;i++)
{
Menu[i]="";
}
numMeals=0;
Menu[0]="Mansaf";
Menu[1]="Burger";
Menu[2]="Falafel";
price[0]=2.7;
price[1]=1.50;
price[2]=0.5;
};
void RestaurantMenu ::AddToMenu(string s ,double d)
{
for(int i=3;i<10;i++)
{
Menu[i]=s;
price[i]=d;
numMeals++;
}
};
void RestaurantMenu ::DeleteFromMenu(string s)
{
for(int i = 0; i <10; i++)
{
if(s == Menu[i])
{
Menu[i] = "";
price[i] = 0.0;
numMeals--;
}
else
cout<<"This Meal Is Not Here"<<endl;
}
};
void RestaurantMenu ::ShowMenu()
{
cout<<"Menu"<<" "<<"Price"<<endl;
for ( int i=0;i<10;i++)
cout<<"("<<Menu[i]<<" , "<<price[i]<<")"<<endl;
};
double RestaurantMenu ::FindMeal(string s)
{
for (int i=0;i<10;i++)
{
if (s == Menu[i])
return price[i];
else
return -1;
}
};
//--------------------------------------------------------------------------------
class RestaurantOrder
{
double Bill[10];
string order[10];
public:
RestaurantOrder();
~RestaurantOrder();
void AddToOrder(RestaurantMenu obj, string s);
void DeleteFromOrder(string s);
double CalculateBill();
};
RestaurantOrder ::RestaurantOrder()
{
for(int i=0;i<10;i++)
{
Bill[i]=0;
}
for(int i=0;i<10;i++)
{
order[i]="";
}
;
};
RestaurantOrder ::~RestaurantOrder()
{
cout<<"Good Bye"<<endl;
};
void RestaurantOrder ::AddToOrder(RestaurantMenu obj, string s)
{
/*my problem is how could i search for the string s in the Menu object and find its price and add the string and the price to the order i try this way but it dosent work ?!!*/
double a;
a=obj.FindMeal(s);
for(int i=0;i<10;i++)
{
if(order[i] == a)
{
order[i] = a;
break;
}
else
continue;
}
cout<<"the meal is :"<<" "<<s<<" "<<"and it's price is: "<<a;
cout<<endl;
};
void RestaurantOrder ::DeleteFromOrder(string s)
{ /* and how could i find the the string s in the order */
};
double RestaurantOrder ::CalculateBill()
{
return 1;
};
|