I'm new to c++ however, I have been doing C for about a year now so OPP and all its related things are new to me ( classes etc. ), i have the program in C so I'm trying to find a better way to implement it... Thanks in advance
ps: i'm learning it mostly from Visual C++ 2008 by ivor horton (the native c++)

1. Four functions

void logo ( void ); /* Displays a logo made of characters */
void menu ( const char **menuMsg, const int numMenu ); /* Displays a menu using a loop  */
void mainMenu ( const char *id ); /* constains program specific menu items */
void caseMenuOptionChooser ( void ); /* do while switch statment containing functions */

2.

int main ( void )
{
    caseMenuOptionChooser ();
    Pause ();
    return 0;
}
void menu ( const char **menuMsg, const int numMenu ) {
    int i;

    for ( i = 0; i < numMenu; i++ ) {

        printf ( " Enter: \"%d\" %-39s \n", i, menuMsg [ i ] );

    }
}

void mainMenu ( const char *id ) {
    const int numMenu = 7;
    const char *msg [ ]  = {
                          "To exit", "Check for updates",
                          "User Account Management",
                          "Budget Entry",
                          "Change Date",
                          "Account Balance Management",
                          "Budget Report" };

    printf ( "\n\n %s\n\n", PRODUCT_NAME );

    menu ( msg, numMenu );

    printf ( "\n [%s] is currently logged on\n\n", id  ); 
}
void caseMenuOptionChooser ( void ) {
    int option;
    int numOfChose = 7; /* Same as mainMenu : numMenu 7; */
    int err = 0;
    char userName [ SIZE_A ] = "\0"; /* User name (used to check if the user has logged in) */
    char userPwd [ SIZE_A ]  = "\0"; 
    do {

        //system ( "cls" );
        mainMenu ( userName );

        /* Get integer */
        printf ( "Response: " );
        option = getShellBufInt (); /* Basically uses getch */
        //option = getIntReturn ( "Response: " ); /* fgets sscanf combination */

        switch ( option ) {

            case 0 :
                break;

            case 1 :
                /* Program function */
                break;

            /**ETC... */

    } while ( option != 0 );
}

3. The C++ skeleton code

class COutput
{
private:  /* NB this doesn't compile ... think of it as enhanced pseudo-code  */
        int m_noMenuItems; // This is the number of menu items
        string msg;        // This is basically the same msg from line 20
 
        /* I think this is called a constructor */
        COutput ( char **menu /* Pass the string object by reference */, int im /* pass by value */ )
        {
            cout << "Constructor called." << endl; /* ... i got this from ivor's book.. it's not printing tho.. */
            *msg = &menu; /* assign the array of string to msg... or change msg to point to the array of strings (menu)...  */
            m_noMenuItems = im;

        }
public:
       void logo ( void );
       void menu ( const char **menuMsg, const int numMenu );
       void mainMenu ( const char *id );
       void caseMenuOptionChooser ( void );

}

Basically I'm trying to but 1. to 2 in a class
Also you can just tell me how to send an array of string to a constructor ... if you don't understand the previous statments
Thanks!

I would use a std::vector<std::string> to get an array of strings to the constructor. Any time I see **, I think "there is definitely a better way to do this" :)

I agree with daviddoria. C++ has taken several evolutionary steps beyond C. The first (and probably most difficult) step for you to take, is to get out of the C mindset of doing everything the long way, using arrays and pointers for everything. Instead focus for energy on learning the C++ standard libraries - you'll hopefully quickly realise that many common problems which you may be familiar with from C are already solved and packaged up neatly within the STL.

The <string> library replaces everything you might have previously done using char*
The STL replaces almost everything you might have previously done using arrays; particularly vector, list, set and map.
The stream libraries replace functions such as printf/scanf/fgets/sscanf/etc. Use <iostream>, <fstream> and <sstream>

Its probably worth getting familiar with strings, the STL and streams before getting into more hot water with classes on top of that. The worst thing you can do is begin mixing C and C++ - the languages are vastly different to each other, and really don't mix very well.

Careful though, don't say anything is better than anything else or Narue will become angry!

Thanks i appreciate that I will look into that STL and string thanks

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.