942,523 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 793
  • C++ RSS
Nov 15th, 2008
0

OOP Concepts

Expand Post »
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.

C++ Syntax (Toggle Plain Text)
  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

C++ Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 34
Solved Threads: 4
Light Poster
midimatt is offline Offline
49 posts
since Mar 2008
Nov 16th, 2008
0

Re: OOP Concepts

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)
  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. }
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5583
Solved Threads: 2279
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,924 posts
since Aug 2005
Nov 16th, 2008
0

Re: OOP Concepts

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
Reputation Points: 392
Solved Threads: 108
Posting Shark
Alex Edwards is offline Offline
971 posts
since Jun 2008
Nov 17th, 2008
0

Re: OOP Concepts

In C++ if designer properly you could easily avoid switch cases ,etc.
Reputation Points: 769
Solved Threads: 128
Banned
ithelp is offline Offline
1,910 posts
since May 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Need to list an array of strings in reverse order.
Next Thread in C++ Forum Timeline: Py Lame????





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC