| | |
OOP Concepts
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Hello everybody,
I'm back, started my 2nd year at Uni now and started programming in the wonder that is C++ and enjoying it tremendously.
but I've hit a slight problem, not with code but with design.
I'm not sure where to put the input/output, sounds weird but I'll elaborate.
i have all my base classes sorted i have a Bank class which contains arrays of Accounts and Customers and contains all the functions required to add/delete/display accounts and customers.
its only a simple console application using a simple menu and the user simply enters a number 1 - 9 (as a char) to navigate the menu.
what i'm confused about is where to put the menu output and where to read the menu input, do i put it all in my bank class or to i put it in my main class.
my original idea was to have all of the menu output in functions within the bank class; for example.
with this method i would call the mainMenu function on a bank object in my main.cpp file and that mainMenu function would do all the output input and validation and then display the next menu. therefore my main function would probably look something like this
but i'm worried that this would be going against oop concepts and i'm just wondering what other members of the community think.
Thanks in advance for any help
-Midi
I'm back, started my 2nd year at Uni now and started programming in the wonder that is C++ and enjoying it tremendously.
but I've hit a slight problem, not with code but with design.
I'm not sure where to put the input/output, sounds weird but I'll elaborate.
i have all my base classes sorted i have a Bank class which contains arrays of Accounts and Customers and contains all the functions required to add/delete/display accounts and customers.
its only a simple console application using a simple menu and the user simply enters a number 1 - 9 (as a char) to navigate the menu.
what i'm confused about is where to put the menu output and where to read the menu input, do i put it all in my bank class or to i put it in my main class.
my original idea was to have all of the menu output in functions within the bank class; for example.
C++ Syntax (Toggle Plain Text)
void Bank::mainMenu() { do { char menu; system("cls"); draw(); cout << "Main Menu" << endl; draw(); cout << "1 - Accounts Menu" << endl; cout << "2 - Cards Menu" << endl; cout << "3 - Lending Menu" << endl; cout << "4 - Investements Menu" << endl; cout << "5 - Exit" << endl; draw(); cout << "Please Make Your Choice: "; cin >> menu; switch (menu) { case '1': accMenu(); break; case '2': cardMenu(); break; // only showing a couple you get the point :P } }while(menu != '5'); }
with this method i would call the mainMenu function on a bank object in my main.cpp file and that mainMenu function would do all the output input and validation and then display the next menu. therefore my main function would probably look something like this
C++ Syntax (Toggle Plain Text)
int main () { Bank b; b.mainMenu(); //End Sequence cin.ignore(1000, '\n'); //Ignores all input up till next line cout << "Press Enter to Continue" << endl; cin.get(); //makes the program wait before continuing }
but i'm worried that this would be going against oop concepts and i'm just wondering what other members of the community think.
Thanks in advance for any help
-Midi
I suppose there are as many ways to design your program as there are people to program it. But if I were going to do it I would not put the menu in the Bank class at all but put it in the main() function.
C++ Syntax (Toggle Plain Text)
int DisplayMenu(); const int DONE = 5 // menu item 5 int main() { Bank bank; int option; while( (option = DisplayMenu()) != DONE ) { switch(option) { case 1: // do something here break; <etc, etc for the other menu items } } } int DisplayMenu() { int choice = 0; system("cls"); draw(); cout << "Main Menu" << endl; draw(); cout << "1 - Accounts Menu" << endl; cout << "2 - Cards Menu" << endl; cout << "3 - Lending Menu" << endl; cout << "4 - Investements Menu" << endl; cout << "5 - Exit" << endl; draw(); cout << "Please Make Your Choice: "; cin >> choice; return choice; }
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
In C++ if designer properly you could easily avoid switch cases ,etc.
![]() |
Similar Threads
- C# Project Ideas (C#)
- OOP in C# (C#)
- OOP in PHP design (PHP)
- PHP OOP Question (PHP)
- Global Data Limit (C++)
- Coolest programming language? (IT Professionals' Lounge)
- OOPS concepts in c++ ... (C++)
- Where to get started with Web Programming (IT Professionals' Lounge)
- graphics - where to start? (C++)
Other Threads in the C++ Forum
- Previous Thread: Need to list an array of strings in reverse order.
- Next Thread: Py Lame????
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator getline graph homeworkhelper iamthwee ifstream image input int integer java lib list loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings struct template text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






