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!