I have this code and in the main function I want to display "Daily Total: " however it is displaying "Pizza" instead due to the constructor? Any suggestions on how to fix this problem?
#include<iostream.h>
#include<conio.h>
#include<string.h>
class Meal
{
friend ostream& operator<<(ostream &out, const Meal &aMeal);
friend istream& operator>>(istream &in, Meal &aMeal);
private:
char entree[20];
int calorie;
public:
Meal(char ent[] = "Pizza ", int cal = 25);
Meal operator+(Meal &aMeal);
void displayMeal();
};
Meal::Meal(char ent[], int cal )
{
strcpy(entree, ent);
calorie = cal;
};
Meal Meal:perator+(Meal &aMeal)
{
Meal exam;
exam.calorie = calorie + aMeal.calorie;
return(exam);
};
void Meal::displayMeal()
{
cout<<"The entree: "<<entree<<"has"<<calorie<< " calories."<<endl;
};
ostream& operator<<(ostream &out, const Meal &aMeal)
{
out<<aMeal.entree<<aMeal.calorie<<" calories "<<endl;
return(out);
};
istream& operator>>(istream &in, Meal &aMeal)
{
cout<<endl; //clears
cout<<"Enter the entree name: ";
in>>aMeal.entree;
cout<<"Enter the amount of calories: ";
in>>aMeal.calorie;
return(in);
};
void main()
{
Meal breakfast("Bagel ", 100);
Meal lunch("Hamburger ", 325);
Meal dinner("Steak ", 350);
Meal total("Daily Total: ", 0);
total = breakfast + lunch + dinner;
cout<<"Breakfast: "<<breakfast<<endl;
cout<<"Lunch: "<<lunch<<endl;
cout<<"Dinner: "<<dinner<<endl;
cout<<total<<endl;
getch();
};
#include<iostream.h>
#include<conio.h>
#include<string.h>
class Meal
{
friend ostream& operator<<(ostream &out, const Meal &aMeal);
friend istream& operator>>(istream &in, Meal &aMeal);
private:
char entree[20];
int calorie;
public:
Meal(char ent[] = "Pizza ", int cal = 25);
Meal operator+(Meal &aMeal);
void displayMeal();
};
Meal::Meal(char ent[], int cal )
{
strcpy(entree, ent);
calorie = cal;
};
Meal Meal:perator+(Meal &aMeal)
{
Meal exam;
exam.calorie = calorie + aMeal.calorie;
return(exam);
};
void Meal::displayMeal()
{
cout<<"The entree: "<<entree<<"has"<<calorie<< " calories."<<endl;
};
ostream& operator<<(ostream &out, const Meal &aMeal)
{
out<<aMeal.entree<<aMeal.calorie<<" calories "<<endl;
return(out);
};
istream& operator>>(istream &in, Meal &aMeal)
{
cout<<endl; //clears
cout<<"Enter the entree name: ";
in>>aMeal.entree;
cout<<"Enter the amount of calories: ";
in>>aMeal.calorie;
return(in);
};
void main()
{
Meal breakfast("Bagel ", 100);
Meal lunch("Hamburger ", 325);
Meal dinner("Steak ", 350);
Meal total("Daily Total: ", 0);
total = breakfast + lunch + dinner;
cout<<"Breakfast: "<<breakfast<<endl;
cout<<"Lunch: "<<lunch<<endl;
cout<<"Dinner: "<<dinner<<endl;
cout<<total<<endl;
getch();
};