USING C++ write three classes: DietPlan , ExercisePlan, and FitnessAppWrapper .
ID: 3672577 • Letter: U
Question
USING C++ write three classes: DietPlan, ExercisePlan, and FitnessAppWrapper.
Diet Plan Attributes:
The class DietPlan is used to represent a daily diet plan. Your class must include three data members to represent your goal calories (an integer), plan name(a std::string), and date for which the plan is intended (a std::string). The maximum intake of calories for a day is stored in the goal calories.
Exercise Plan Attributes:
The class ExercisePlan is used to represent a daily exercise plan. Your class must include three data members to represent your goal steps (an integer), planname (a std::string), and date for which the plan is intended (a std::string). Your goal steps represent the number of desired steps for a day.
Diet and Exercise Plan Operations:
Both the DietPlan and ExercisePlan should provide several member functions including: a constructor, copy constructor, and destructor. Remember that you will have to think about other appropriate member functions (think about setter and getter functions!). Member function editGoal () should prompt the user for a new goal, and use the value to change the goal in the plan. Each time a plan is changed, the plan must be displayed to the screen, using an overloaded stream insertion operator (see below).
In the same file in which each class declaration exists, three nonmember functions must be declared. Note: an overloaded operator is considered an overloaded function. The overloaded stream insertion (<<) for both displaying a plan to the screen and for writing a plan to a file, and the extraction (>>) operator for reading a plan from a file.
Observation: please notice that the DietPlan and ExercisePlan classes define very similar attributes and operations. In the future, we will be able to design around these similarities (using inheritance and polymorphism).
Explanation / Answer
Program plan: In this we need to write two classes DietPlan and ExercisePlan.
Class Definition:
//including libraries
#include<iostream.h>
#inlcude<conio.h>
namespace std;
//DietPlan class definition
class DietPlan
{
private:
int goalcalories;
std::string planname;
std::string date;
public:
//defining the constructor
DietPlan() //constructors can be called implicitly.and used to initialize data members
{
goalcalories=500;
planname="plan1";
date="1/jan/2016";
}
//defining the copy constructors
Dietplan(const DietPlan &d1) //copy construtor is used to initialize the class object with other object of the same class
{
goalcalories=d1.goalcalories;
planname=d1.planname;
date=d1.date;
}
//defining the destructor
//destructor is used to deallocate the space which is allocated by constructor.
~DietPlan()
{}
//defining the set and get function
void editGoal()
{
cout<<"enter new diet plan name";
cin>>planname;
cout<<"enter goal calories ";
cin>>goalcalories;
cout<<"Enter date on which the the date plan intended ";
cin>>date;
}
void setDiet(int gc,std::string pn,std::string dt)
{goalcalories=gc;
planname=pn;
date=dt;
}
void getDiet()
{
cout<<"the Goal calories are "<<goalcalories<<" "<<"planname is : "<<planname<<" "<<"date on which it is intended is :"<<date;
}
};//end of the DietPlan class
//defining the ExecisePlan class
class ExercisePlan
{
private:
int goalsteps;
std::string planname;
std::string date;
public:
ExercisePlan() //constructors can be called implicitly.and used to initialize data members
{
goalsteps=50;
planname="plan1";
date="1/jan/2016";
}
//defining the copy constructors
Exerciseplan(const ExercisePlan &e1) //copy construtor is used to initialize the class object with other object of the same class
{
goalsteps=e1.goalsteps;
planname=e1.planname;
date=e1.date;
}
//defining the destructor
//destructor is used to deallocate the space which is allocated by constructor.
~ExercisePlan()
{}
//defining the set and get function
setExercisePlan()
{
cout<<"enter new Exercise plan name";
cin>>planname;
cout<<"enter goal steps ";
cin>>goalsteps;
cout<<"Enter date on which the execise plan intended ";
cin>>date;
}
getExercisePlan()
{
cout<<"the Goal steps are "<<goalsteps<<" "<<"planname is : "<<planname<<" "<<"date on which it is intended is :"<<date;
}
friend istream& operator >>(istream &,ExercisePlan&);
friend ostream& operator <<(ostream &,ExercisePlan&);
};
//defining the non member functions which are for overloading the insertion and extraction operator
istream& operator >>(istream &in,ExecisePlan &e1)
{
cout<<"enter new Exercise plan name";
in>>e1.planname;
cout<<"enter goal steps ";
in>>e1.goalsteps;
cout<<"Enter date on which the execise plan intended ";
in>>e1.date;
}//completion of overloaded extraction operator function
ostream& operator <<(ostream &out,ExercisePlan &e1)
{
out<,"the new execise plan ";
out<<"the Goal steps are "<<e1.goalsteps<<" ";
out<<"planname is : "<<e1.planname<<" ";
out<<"date on which it is intended is :"<<e1.date<<" ";
}//completion of the overloaded << operator method
//in the above question i didnt get the fitnessappwarpper definition to include in my file.i hope this two classes wiil help you complete it.thank you
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.