I'm working on this program. There are 3 classes.
These two classes PassengerMenu and SecurityMenu are inherited from the class MainMenu

So the main menu would provide the logo and a description (normal cout). Also an access to either the passnger menu or the security menu. according to your choice.

The passenger menu has another stuff
The security menu has different stuff as well.
Now the whole program is going to be a loop.
How am I going to arrange them this way while they are inherited the easiest way???
I don't know.. It got complicated suddenly! Any suggestions?

This is the implementation for the main menu:

# include <iostream>
# include <string>
# include "MainMenu.h"
using namespace std;

//body intentionally blank.

MainMenu::MainMenu(string the_name)

MainMenu::MainMenu(string the_destanation, string the_departure, string the_date, string the_time)

ostream& operator << (ostream& outs,const MainMenu& settings)
return outs;


istream& operator >> (istream& ins,const MainMenu& settings)
	ins >>settings.departure
return ins;

void MainMenu::display_main_menu ()const
	int number;
cout<<"Hello and welcome to J-Otaku-Air travel agency."<<endl
		<<"Please choose a number from the following menu, then press enter to "
		<<"move to the desired page."<<endl<<endl
		<<"1. About J-Otaku-Air"<<endl
		<<"2. View passenger menu"<<endl
		<<"3. View security menu"<<endl
		<<"* Press 0 to exit"<<endl<<endl;
cin>> number;

	if (number==1)
		<<"J-Otaku-Air was founded on July 1990."<<endl
		<<"Fadia Banafe built this company with the goal of helping"<<endl
		<<"accommodate the curious nature of people and their need for exploration. "<<endl
		<<"Throuh out the years, J-Otaku-Air has been thriving to expand its services and"<<endl;
	cout<<"offer the best for their clients. And along their journey their hard work has"<<endl
		<<"been rewarded by many establishments."<<endl
		<<"In hopes of seeing you in one of our flights."<<endl<<endl
		<<"         J-Otaku-Air"
		<<"\t\t\t\t Fly Safe, Fly Otaku.."<<endl<<endl<<endl;
	if (number==0)
		"You're out of the main menu";

	//if (number==2)

		cout<<"Invalid entry!!"<<endl<<endl;

string MainMenu::choose_from_main_menu (string choice)
return choice;

void MainMenu::JOTAKU_LOGO () const
		cout << "\t\t\t =================    "<<endl;
		cout << "\t\t\t     ||   || || ||    "<<endl;
		cout << "\t\t\t     ||   || || ||    "<<endl;
		cout << "\t\t\t     ||      || ||    "<<endl;
		cout << "\t\t\t \\   ||         ||   "<<endl;
		cout << "\t\t\t  \\  ||              "<<endl;
		cout << "\t\t\t   \\ ||              "<<endl;
		cout << "\t\t\t    \\||  J-Otaku-Air "<<endl;
		cout <<endl;
		cout <<endl;
void MainMenu::display_details()
	cout << "Name: " << name << endl;
	cout<<"destanation: " << destanation<<endl;
	cout<<"departure: " << departure<<endl;
	cout<<"date: "<<date<<endl;
	cout<<"time: "<<time<<endl;

Recommended Answers

All 7 Replies

Show declaration of all classes. And main program.

I didn't write them yet.. I don't know how to implement the main loop let alone start with another classes.

I want the idea how to do them. Have any clue?

You're right to stop where you are until you've sorted out the design. This approach you've taken so far is going to be painful.

So, think about inheritance.
Do your classes pass the basic test - i.e. PassengerMenu 'is a' MainMenu? No they don't. Your MainMenu is a specific menu with specific choices, which is different to PassengerMenu. You could say that a PassengerMenu 'is a' Menu, but it's not a MainMenu as you've defined it.

So how about having a Menu base class and from that you derive MainMenu, PassengerMenu etc.
Menu provides any functionality or data which *all* menus will require.
Menu could have a method Display() which is virtual and you override in your derived classes.

In the derived classes you will specify the menu choices for that menu, and provide the methods to call when each of those choices is selected. If you're up to it you might want to define these as an array of choice strings and an array of choice function pointers. The menu handling could then be provided by the base class as long as it has access to the choice data. But maybe that's jumping ahead a little to far at the moment.

Give the class structure I've described, some of the code might look like this:

MainMenu main;

    PassengerMenu passMenu;
    SecurityMenu secMenu;
    // repeat
       // print your choices for main menu
       // get the selection
       // if passenger menu selected, call passMenu.Display()
       // else if security menu selected, call secMenu.Display()
       // else if some action requested, call DoAction() 
    // until exit chosen

    SomeOtherMenu otherMenu;
    // repeat
       // print your choices for passenger menu
       // get the selection
       // if some other menu selected call otherMenu.Display()
       // else etc...
    // until exit chosen

Lots of gaps I haven't filled in there but I hope it gets you a bit further with the design.

Oh, you may use a polymorphism. I mean virtual functions.

class MainMenu
        virtual void DisplayMenu(){};// here is implementation for MainMenu
        virtual void Choose(){};
        virtual void Details(){};
// and so on

class PassengerMenu: public MainMenu
         void Display(){}; //overloaded method for PassengerMenu class
         void Choose(){};
         void Details(){};
// and so on

class SecurityMenu: public MainMenu
         void Display(){}; //overloaded method for class SecurityMenu

And then, you should declare a three pointers of class MainMenu

MainMenu *main, *passeneger, *security;
main = new MainMenu();
passeneger = new PassengerMenu();
security = new SecurityMenu();

and then call methods Display, Choose and other. Compiler will choose which method it have to call.

Thanks guys..

But.. What are the pointers for? I didn't get the last part.

Can you explain to me what does virtual do?

Guys... You still didn't tell me how to do the main loop??

i'm also having doubts about the private members.. :s

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.