Click here to Skip to main content
15,893,668 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralC Plus Plus Code Help Forums Pin
Texasgulfcoast9-Sep-04 18:01
sussTexasgulfcoast9-Sep-04 18:01 
GeneralRe: C Plus Plus Code Help Forums Pin
Cedric Moonen9-Sep-04 20:29
Cedric Moonen9-Sep-04 20:29 
Generalschool program =( Pin
ISUstudent9-Sep-04 17:21
ISUstudent9-Sep-04 17:21 
GeneralRe: school program =( Pin
Christian Graus9-Sep-04 17:37
protectorChristian Graus9-Sep-04 17:37 
GeneralRe: school program =( Pin
ISUstudent9-Sep-04 18:06
ISUstudent9-Sep-04 18:06 
GeneralRe: school program =( Pin
David Crow10-Sep-04 3:05
David Crow10-Sep-04 3:05 
GeneralRe: school program =( Pin
Anonymous10-Sep-04 22:24
Anonymous10-Sep-04 22:24 
GeneralRe: school program =( Pin
9-Sep-04 22:07
suss9-Sep-04 22:07 
hello jason,

try this one.

//======================================================
// menu.h

#include<iostream>
#include<string>

using namespace std;

class CMenu
{
private:
int m_numChoices;
string m_menuItem[8];

public:
// Default constructor
CMenu();

// Special constructor
CMenu(int itemcount,
string item1,
string item2,
string item3 = "",
string item4 = "",
string item5 = "",
string item6 = "",
string item7 = "",
string item8 = "");

void run(char item);
int validateChoice(char item);
void printMenu(int item);



};
//======================================================






//======================================================
// menu.cpp
#include "menu.h"

// Default contructor
CMenu::CMenu()
{
// Initialize the number of menu items
m_numChoices = 0;
}


CMenu::CMenu(int itemcount, string item1, string item2, string item3, string item4, string item5, string item6, string item7, string item8)
{
m_numChoices = 0;

// Process only if the number of requested items is correct
if((itemcount >= 2)&&(itemcount <= 8))
{
m_numChoices = itemcount;
m_menuItem[0] = item1;
m_menuItem[1] = item2;
m_menuItem[2] = item3;
m_menuItem[3] = item4;
m_menuItem[4] = item5;
m_menuItem[5] = item6;
m_menuItem[6] = item7;
m_menuItem[7] = item8;
}// if((itemcount >= 2)&&(itemcount <= 8))
}


void CMenu::run(char item)
{
printMenu(validateChoice(item));
}

int CMenu::validateChoice(char item)
{
int return_value = 0;

char *ptr_tmp = new char;
*ptr_tmp = item;
*(ptr_tmp+1) = 0;

int itmp = atoi(ptr_tmp);
//cout << endl << itmp << endl;

if((itmp >= 1) && (itmp <= m_numChoices))
{
// We need to subtract 1 because the m_menuItem array is zero-based
return_value = itmp - 1;
}

return return_value;
}

// Developer Note
// I am assuming that this method will print only
// the menu item corresponding to the
// integer location
void CMenu::printMenu(int item)
{
cout << m_menuItem[item];

}

//======================================================
// main.cpp

#include "menu.h"


void main()
{
CMenu oMenu(3, "item1", "item2", "item3");

oMenu.run('3');

}
//======================================================


Some notes, i assume this is only for your studies. becuase there are some major flaw in the design.

when you try:
CMenu menu();
this is actually useless.

anyway, hope this helps.


GeneralRe: school program =( Pin
rotu9-Sep-04 22:26
rotu9-Sep-04 22:26 
GeneralRe: school program =( Pin
Mike Beckerleg9-Sep-04 23:50
Mike Beckerleg9-Sep-04 23:50 
GeneralRe: school program =( Pin
ISUstudent10-Sep-04 5:06
ISUstudent10-Sep-04 5:06 
GeneralMFC app doesn't work in debug mode, works in release mode Pin
Indrawati9-Sep-04 17:03
Indrawati9-Sep-04 17:03 
GeneralRe: MFC app doesn't work in debug mode, works in release mode Pin
Christian Graus9-Sep-04 17:38
protectorChristian Graus9-Sep-04 17:38 
GeneralReading a file using serialization Pin
hemanth_phk9-Sep-04 12:17
susshemanth_phk9-Sep-04 12:17 
GeneralRe: Reading a file using serialization Pin
David Crow10-Sep-04 3:15
David Crow10-Sep-04 3:15 
GeneralCan't open listening socket on Win2k3 Server Pin
Jon Betzold9-Sep-04 11:52
Jon Betzold9-Sep-04 11:52 
GeneralFigured it out Pin
Jon Betzold9-Sep-04 12:57
Jon Betzold9-Sep-04 12:57 
GeneralError - windows.h already included Pin
skg7479-Sep-04 11:49
skg7479-Sep-04 11:49 
GeneralRe: Error - windows.h already included Pin
Arsalan Malik9-Sep-04 19:32
Arsalan Malik9-Sep-04 19:32 
GeneralRe: Error - windows.h already included Pin
David Crow10-Sep-04 3:17
David Crow10-Sep-04 3:17 
GeneralRe: Error - windows.h already included Pin
skg74710-Sep-04 6:07
skg74710-Sep-04 6:07 
GeneralRe: Error - windows.h already included Pin
David Crow10-Sep-04 7:59
David Crow10-Sep-04 7:59 
GeneralRe: Error - windows.h already included Pin
skg74710-Sep-04 10:12
skg74710-Sep-04 10:12 
GeneralException "The parameter is incorrect." on CArchive Pin
Ed K9-Sep-04 11:24
Ed K9-Sep-04 11:24 
GeneralRe: Exception "The parameter is incorrect." on CArchive Pin
David Crow10-Sep-04 3:27
David Crow10-Sep-04 3:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.