Hey guys, I am currently trying to set up a class for my simple menu program that will handle choice selection (1 through 2 right now to keep it simple). I am wondering how I would go about encapsulating (if that's the right term?) my data so that I can have something like this:
Call menu selection class from main
Get user's input from the menu selection class
Utilize user's input to bring up a new menu (haven't created the new menu yet) that has options to choose from for food types
And on and on
So I guess my question is:
How do I return input from my menu class and send it to main, and then have main take that new input and send it to another class (a new menu with food choices as stated above), and so on and so forth?
Doesn't it have to do with data encapsulation? I remember something about how each class needs to be totally stand alone. Can anyone help me out wiht this? Here is my header file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
using namespace std;
class menuClass
{
private:
public:
int switchCase(int);
int menuList();
};
int menuClass::menuList()
{
//Choice
int z;
//Options
cout << "Menu" << endl;
cout << "1. Place Order" << endl;
cout << "2. Exit" << endl;
//Start new segment of menu
//cout << "3. "
//Receive input
cin >> z;
//Return input
return z;
}
int menuClass::switchCase(int menuChoice)
{
//Conditions
switch(menuChoice)
{
case 1:
cout << "ok" << endl;
return 0;
break;
case 2:
cout << "exit" << endl;
return 0;
break;
}
//Error check
if (menuChoice != 1 || menuChoice != 2)
{
//Error response
cout << "Please select an option from the menu and try again. " << endl;
//Restart
switchCase(menuList());
}
}
|
and here is my main file from which I execute my functions that are in the class
1 2 3 4 5 6 7 8
|
int main()
{
menuClass midWip;
midWip.switchCase(midWip.menuList());
}
|
TLDR:
I want to make another class with some food choices so that when the user enters "1" to "place an order" the new function inside of the new class will take that "1" and list off some food choices that the user can then select.