< Previous | Contents | Next >

Exercises

1. Improve the Critter Caretaker program so that you can enter an unlisted menu choice that reveals the exact values of the critters hunger and boredom levels.

2. Change the Critter Caretaker program so that the critter is more expressive about its needs by hinting at how hungry and bored it is.

3. What design problem does the following program have?

#include <iostream> using namespace std;


class Critter

{

public:

int GetHunger() const {return m_Hunger;}

286 Chapter 8 n Classes: Critter Caretaker


private:

int m_Hunger;

};


int main()

{

Critter crit;

cout << crit.GetHunger() << endl; return 0;

}



chapter 9


image