In this program my operator+ first creates a Meal with the default constructor. The default constructor makes exam.entree equal "Pizza" and exam.calorie equal 25. Then exam.calorie is set to the sum of calories.
I need to define an operator= so the computer will simply copy all members from the source object to the destination object (total).
However I can not figure out how to put this in my program. Can anyone help me create an assignment operator for Meal which only copies the calorie member and not the entree member?
friend ostream& operator<<(ostream &out, const Meal &aMeal);
friend istream& operator>>(istream &in, Meal &aMeal);
Meal(char *ent = "Pizza ", int cal = 25);
Meal operator+(Meal &aMeal);
void operator=(Meal &otherMeal);//is this right?
Meal::Meal(char *ent, int cal )
calorie = cal;
Meal Meal::operator+(Meal &aMeal)
exam.calorie = calorie + aMeal.calorie;
void Meal::operator = (Meal &otherMeal)
//if so, what here?
cout<<"The entree: "<<entree<<"has"<<calorie<< " calories."<<endl;
ostream& operator<<(ostream &out, const Meal &aMeal)
out<<aMeal.entree<<aMeal.calorie<<" calories "<<endl;
istream& operator>>(istream &in, Meal &aMeal)
cout<<"Enter the entree name: ";
cout<<"Enter the amount of calories: ";
Meal breakfast("Bagel ", 100);
Meal lunch("Hamburger ", 325);
Meal dinner("Steak ", 350);
Meal total("Daily Total: ", 0);
total = breakfast + lunch + dinner;