Assignment:
Write a C++ program to read the menu information from menu.txt. First letter in item code specifies whether it is an appetizer (A), entrée (E), dessert (D) or beverage (S).
A1 Bruschetta 5.29
A2 Caprese_Flatbread 6.10
A3 Artichoke-Spinach_Dip 3.99
A4 Lasagna_Fritta 4.99
A5 Mozzarella_Fonduta 5.99
E1 Lasagna_Classico 6.99
E2 Capellini_Pomodoro 7.99
E3 Eggplant_Parmigiana 8.99
E4 Fettuccine_Alfredo 7.49
E5 Tour_of_Italy 14.99
D1 Tiramisu 2.99
D2 Zeppoli 2.49
D3 Dolcini 3.49
S1 Soda 1.99
S2 Bella_Limonata 0.99
S3 Berry_Acqua_Fresca 2.88
then prompt the user for the orders. For each order, you should compute & output the total amount. Items may be listed in any order in each line.
A1 E1 D1 S1
S2 D3 E4 A4
E3 E5 A2 A4 S2 S1 D2 D2 E2
X
Once the user enters “X”, program should output the most popular appetizer, entrée, dessert, beverage. If there is a tie, you can output any one of them.
The problem I’m having is taking the input (for example, A1) and then parsing the array for the appropriate item and location in the array (for example, A1 would be test2[1], E1 would hopefully be test2[5]). I know the arrays are populated correctly. What I’m trying to use to search the array is :
for(int l = 0; l<SIZE; l++)
{ //I get an operator error every time here
if(s == (test2[l]))
{ //Just a test to see if I am pulling
//any information
cout << test2[l].getCode() << endl;
}
}
Test was was instantiated as MenuItem test2[SIZE].
When I try to use the above method I always the error
no match for ‘operator==’ in ‘s == test2[l]’
Below is my MenuItem.h:
#ifndef MENUITEM_H
#define MENUITEM_H
#include <iostream>
#include <string>
using namespace std;
class MenuItem
{
private:
string code;
string name;
double price;
public:
MenuItem(string mcode = "", string mname = "", double mprice = 0);
~MenuItem();
string getCode() const { return code; }
string getName() const { return name; }
double getPrice() const { return price; }
void setCode(string mcode){ code = mcode; }
void setName(string mname){ name = mname; }
void setPrice(double mprice) { price = mprice; }
};
#endif
Thanks for any help and input.
Sincerely,
Jason
I am wondering what is the type of the variable s in the following code:
Is s a string containing the user’s input eg. “A1” ?
Or is s a MenuItem object?
If it is a string, then the condition would simply be
If s is a MenuItem object, then you should implement operator== for MenuItem objects
It’s signature might look something like this:
and the implementation would involve checking if the two MenuItem objects have the same code, name and price.