OOP Concepts

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2008
Posts: 40
Reputation: midimatt is an unknown quantity at this point 
Solved Threads: 2
midimatt's Avatar
midimatt midimatt is offline Offline
Light Poster

OOP Concepts

 
0
  #1
Nov 15th, 2008
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.

  1. void Bank::mainMenu()
  2. {
  3. do
  4. {
  5. char menu;
  6. system("cls");
  7. draw();
  8. cout << "Main Menu" << endl;
  9. draw();
  10. cout << "1 - Accounts Menu" << endl;
  11. cout << "2 - Cards Menu" << endl;
  12. cout << "3 - Lending Menu" << endl;
  13. cout << "4 - Investements Menu" << endl;
  14. cout << "5 - Exit" << endl;
  15. draw();
  16. cout << "Please Make Your Choice: ";
  17. cin >> menu;
  18. switch (menu)
  19. {
  20. case '1':
  21. accMenu();
  22. break;
  23. case '2':
  24. cardMenu();
  25. break;
  26. // only showing a couple you get the point :P
  27. }
  28. }while(menu != '5');
  29. }

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

  1. int main ()
  2. {
  3. Bank b;
  4. b.mainMenu();
  5.  
  6. //End Sequence
  7. cin.ignore(1000, '\n'); //Ignores all input up till next line
  8. cout << "Press Enter to Continue" << endl;
  9. cin.get(); //makes the program wait before continuing
  10. }

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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,653
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1500
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: OOP Concepts

 
0
  #2
Nov 16th, 2008
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.
  1. int DisplayMenu();
  2. const int DONE = 5 // menu item 5
  3. int main()
  4. {
  5. Bank bank;
  6. int option;
  7. while( (option = DisplayMenu()) != DONE )
  8. {
  9. switch(option)
  10. {
  11. case 1:
  12. // do something here
  13. break;
  14. <etc, etc for the other menu items
  15. }
  16. }
  17. }
  18. int DisplayMenu()
  19. {
  20. int choice = 0;
  21. system("cls");
  22. draw();
  23. cout << "Main Menu" << endl;
  24. draw();
  25. cout << "1 - Accounts Menu" << endl;
  26. cout << "2 - Cards Menu" << endl;
  27. cout << "3 - Lending Menu" << endl;
  28. cout << "4 - Investements Menu" << endl;
  29. cout << "5 - Exit" << endl;
  30. draw();
  31. cout << "Please Make Your Choice: ";
  32. cin >> choice;
  33. return choice;
  34. }
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 973
Reputation: Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough 
Solved Threads: 107
Alex Edwards's Avatar
Alex Edwards Alex Edwards is offline Offline
Posting Shark

Re: OOP Concepts

 
0
  #3
Nov 16th, 2008
You could also make a Menu class to encapsulate the banking operation. However, it might be better to specialize your Menu and give it a name (and make an 'abstract' base class Menu for general Menu's ).

-Alex
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,861
Reputation: ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all 
Solved Threads: 120
ithelp's Avatar
ithelp ithelp is offline Offline
Posting Virtuoso

Re: OOP Concepts

 
0
  #4
Nov 17th, 2008
In C++ if designer properly you could easily avoid switch cases ,etc.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 530 | Replies: 3
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC