#include <iostream>
#include <typeinfo>
usingnamespace std;
class Dessert
{
public:
Dessert()
{
calories = 10;
}
void addSugar(double s)
{
calories += s*3;
return;
}
void printDetails()
{
cout << "Calories of " << typeid(this).name() << " is " << calories << "\n";
return;
}
protected:
double calories;
};
//Add Chef class here
//1. Add constructor as specified
//2. Add isHealthy function
//3. Add member variable qualified
class Chef : public Dessert {
private:
bool qualified;
public:
Chef() {
qualified = true;
}
bool isHealthy(Dessert D)
{
if (D.calories < 300)
returntrue;
returnfalse;
}
friendbool checkQualifications(Chef C);
};
//Uncomment for final solution
bool checkQualifications(Chef c)
{
return c.qualified;
}
int main()
{
cout << "Q1 running..." << endl;
Dessert d;
//Uncomment and fix typos
//DO NOT ADD NEW LINES or cout statements
double increment;
cout << "Input sugar increment: ";
cin >> increment;
int count = 0;
Chef c;
if(checkQualifications(c))
{
cout << "Chef is qualified" << endl;
d.printDetails();
while (c.isHealthy(d))
{
count++; //increment count
d.addSugar(increment);
d.printDetails();
}
cout << "The chef added " << count*increment << " sugar units before it became unhealthy" << endl;
}
}
FYI, I can't access calories inside of Chef::isHealthy();
Another thing, I'm using public inheritance but I really do feel like I should be using protected or private inheritance since this function is essentially a "has-a" relationship. Am I correct?
ONE LAST THING: This is a practice exam. My teacher explicitly said to not use getters/accessors and to not make calories public. But I need to access calories. Is using "Friend" a possible with derived classes?