I have created a class Menu that may be used to facilitate making choices in Console programs. The base class menu has the following class definition:
typedef Array < string > StringArray;
class Menu
{
public:
Menu(){}
Menu(const StringArray &s):choices(s){size = s.numberInArray();}
int makeChoice()const;
void setChoices( int sz,const StringArray &s);
private:
void showChoices()const;
int readChoice()const;
StringArray choices;
int size;
};
The function makeChoice is used to make a choice from amoung the list of choices. It returns a number between 0 and one less than the number of choices. The list of choices may be initiaized for each application by calling on setChoices. I highly recommend making a descendent of this class whose constructor initializes the choices. For an example click here.