943,163 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2318
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Feb 9th, 2010
0

Need Help w/ a simple banking program

Expand Post »
I'm taking my first class in c++ this semester, so i'm a newb. The only other programming experience i have is in python. My teacher gave me this assignment and i don't even know where to start. I don't want anyone to post any code, but a few tips on what implementation files i need to create and what they should contain would be great.

Here's the assignment:

Your header file has been given to you, so you only need to create the implementation and main files. However, you may have to make some changes to the supplied file. Your program should work like the following:

Please make a selection:
1) Display Current Account Balance
2) Deposit Money
3) Withdraw Money
4) Exit

< user enters 1 >
You have $2000.00 in your account.


Please make a selection:
1) Display Current Account Balance
2) Deposit Money
3) Withdraw Money
4) Exit

< user enters 2 >
How much would you like to deposit? < user enters 300.57 >

You have deposited $300.57, and you now have $2300.57 in your account.


Please make a selection:
1) Display Current Account Balance
2) Deposit Money
3) Withdraw Money
4) Exit

< user enters 3 >
How much would you like to withdraw? < user enters 4500 >

Sorry, you don’t have that much in your account.


Please make a selection:
1) Display Current Account Balance
2) Deposit Money
3) Withdraw Money
4) Exit

< user enters 3 >
How much would you like to withdraw? < user enters 450 >
You have withdrawn $450.00, and you now have $1850.57 in your account.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
blakenbama is offline Offline
6 posts
since Feb 2010
Feb 9th, 2010
0
Re: Need Help w/ a simple banking program
So you say you know python. Why not make it in Python first and then translate it to C++. This assignment only requires the most basic function of C++ and the structure of the program in C++ wouldn't differ very much from the structure in C++.
Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is offline Offline
4,132 posts
since Oct 2006
Feb 9th, 2010
0
Re: Need Help w/ a simple banking program
To answer your primary question, you'll need 3 files:
1.) The provided header file (a *.h file)
2.) The class implementation file (a *.cpp) file.
3.) The main application file (another *.cpp) file.

The structure of the program will be the same as any other you should have done to this point. You just need to adapt your header usage (#includes) to the one provided by your instructor and be sure you fill in the implementation file correctly.
Last edited by Fbody; Feb 9th, 2010 at 11:08 am.
Featured Poster
Reputation Points: 833
Solved Threads: 392
Posting Maven
Fbody is offline Offline
2,846 posts
since Oct 2009
Feb 9th, 2010
0
Re: Need Help w/ a simple banking program
Click to Expand / Collapse  Quote originally posted by Fbody ...
To answer your primary question, you'll need 3 files:
1.) The provided header file (a *.h file)
2.) The class implementation file (a *.cpp) file.
3.) The main application file (another *.cpp) file.

The structure of the program will be the same as any other you should have done to this point. You just need to adapt your header usage (#includes) to the one provided by your instructor and be sure you fill in the implementation file correctly.

Thanks for the reply,

What i was really wanting/needing to know was:
1) Do i need to make functions for all the private and public members of the header file in a separate .cpp file or just the public members?
2) What's the best way of implementing the menu?

Here is the code that our instuctor gave us as our header file:

C++ Syntax (Toggle Plain Text)
  1. #ifndef ACCOUNT // this redundancy checking statement looks to see if this section has
  2. #define ACCOUNT // already been included. if it has already been included, it is ignored.
  3.  
  4. #include <iostream>
  5. #include <string>
  6. using namespace std;
  7.  
  8. class account {
  9. private:
  10. //private members
  11. string ownerFirstName;
  12. string ownerLastName;
  13. float balance;
  14.  
  15. //private methods
  16.  
  17. public:
  18. //constructor
  19. account(string, string, float);
  20. void depositFunds(float);
  21. void withdrawFunds(float);
  22. float getBalance();
  23.  
  24. };
  25.  
  26. #endif //this is the end of the redundancy checking statement
Last edited by Nick Evan; Feb 9th, 2010 at 1:44 pm. Reason: Added code-tags
Reputation Points: 10
Solved Threads: 0
Newbie Poster
blakenbama is offline Offline
6 posts
since Feb 2010
Feb 9th, 2010
0
Re: Need Help w/ a simple banking program
Please use [code=syntax] ... code tags ... [/code] they make code contained in your posts easier to read. niek_e has added them for you so far, but you need to start doing that.

RE: Q1.)
Any user-defined function that exists as a member of your class must be implemented (i.e. deposit(), withdraw(), checkBalance()) in the *.cpp file by you. I see 4 member functions that need implementation. They are all public. As far as implementation is concerned, you would not treat them any differently if they were private.

RE: Q2.)
Personally, I would create an int variable (I'll call it 'selection') then get the user's numeric selection. After that use some sort of branching control statement (such as switch or if...then...else) to determine what was entered and respond accordingly to what you determine the input was.
Last edited by Fbody; Feb 9th, 2010 at 2:01 pm.
Featured Poster
Reputation Points: 833
Solved Threads: 392
Posting Maven
Fbody is offline Offline
2,846 posts
since Oct 2009
Feb 9th, 2010
0
Re: Need Help w/ a simple banking program
Thanks Fbody,

I'm gonna get to work on it tomorrow and i'll let you know how it works out, but i think i've got the general idea now.

Click to Expand / Collapse  Quote originally posted by Fbody ...
Please use [code=syntax] ... code tags ... [/code] they make code contained in your posts easier to read. niek_e has added them for you so far, but you need to start doing that.

RE: Q1.)
Any user-defined function that exists as a member of your class must be implemented (i.e. deposit(), withdraw(), checkBalance()) in the *.cpp file by you. I see 4 member functions that need implementation. They are all public. As far as implementation is concerned, you would not treat them any differently if they were private.

RE: Q2.)
Personally, I would create an int variable (I'll call it 'selection') then get the user's numeric selection. After that use some sort of branching control statement (such as switch or if...then...else) to determine what was entered and respond accordingly to what you determine the input was.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
blakenbama is offline Offline
6 posts
since Feb 2010
Feb 22nd, 2010
0
Re: Need Help w/ a simple banking program
Okay, so far this is what i have:

C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <string>
  3. #include "account.h"
  4. using namespace std;
  5.  
  6. int main(){
  7.  
  8. account a("Blake", "Hunter", 5000.00); // default account
  9. int selection = 0;
  10. while ( selection != 1){ // end program when terminate = 1
  11.  
  12. float amt = 0;
  13. float amnt = 0;
  14. cout << "Please make a selection:\n"; //Display user menu
  15. cout << "1) Display Current Account Balance\n";
  16. cout << "2) Deposit Money\n";
  17. cout << "3) Withdraw Money\n";
  18. cout << "4) Exit\n\n\n";
  19. cin >> selection;
  20.  
  21. if (selection == 1){ // view account
  22. cout << "You have " << a.getBalance() << " dollars in your account.\n";
  23. system("pause");
  24. }
  25.  
  26. else if(selection == 2){ // deposit
  27. cout << "How much would you like to deposit: ";
  28. cin >> amt;
  29. cout << "You've successfully deposited: $" << amt << " \nYour new balance is: $" << a.getBalance() + amt << "\n\n";
  30. system("pause");
  31. }
  32.  
  33. else if(selection == 3){ // withdraw
  34. cout << "How much would you like to withdraw: ";
  35. cin >> amnt;
  36.  
  37. if (a.getBalance() >= amnt){ // restricts user from withdrawing more than they have in their account
  38. cout << "You've successfully withdrawn: $" << amnt << "\nYour new balance is:" << a.getBalance() - amnt << " \n\n";
  39. system("pause");
  40. }
  41.  
  42. else{
  43. cout << "You don't have enough money for that! If\n";
  44. system("pause");
  45. }
  46. }
  47.  
  48. else if(selection == 4){ //exit
  49. cout << endl << endl <<"Thank you for using Compass Bank 1.0!!!\n\n";
  50. selection++; //increase to exit loop/program
  51. system("pause");
  52. }
  53.  
  54. else{
  55. cout << "Only numerical selections 1-4 work....Please try again.\n"; //tells user how to correct mistakes
  56. system("pause");
  57. }
  58. system("cls");
  59. }
  60. }


SOURCE FILE:
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <string>
  3. #include "account.h"
  4. using namespace std;
  5.  
  6. account::account(std::string first, std::string last, float bal) {
  7. ownerFirstName = first;
  8. ownerLastName = last;
  9. balance = bal;
  10. }
  11.  
  12. void account::depositFunds() {
  13. }
  14.  
  15. void account::withdrawFunds() {
  16. }
  17.  
  18.  
  19. float account::getBalance(){
  20. return balance;
  21. }
  22. [code = syntax] [\code]
  23.  
  24. HEADER FILE:
  25. [code = syntax] [\code]
  26. #ifndef ACCOUNT
  27. #define ACCOUNT
  28.  
  29. #include <iostream>
  30. #include <string>
  31. using namespace std;
  32.  
  33. class account {
  34. private:
  35. //private members
  36. string ownerFirstName;
  37. string ownerLastName;
  38. float balance;
  39. //private methods
  40.  
  41. public:
  42. //constructor
  43. account(string, string, float);
  44. void depositFunds();
  45. void withdrawFunds();
  46. float getBalance();
  47.  
  48. };
  49.  
  50. #endif


The program works like i want it to except for one thing. I CAN'T get the getBalance() function to update when the user deposit's or withdraws money.....Does anyone see a solution?
Last edited by Nick Evan; Feb 22nd, 2010 at 2:17 pm. Reason: Fixed tags.. Again.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
blakenbama is offline Offline
6 posts
since Feb 2010
Feb 22nd, 2010
0
Re: Need Help w/ a simple banking program
There are 2 reasons they don't do anything:

1.) You never call withdraw or deposit. You need to add lines to cases 2 and 3 that call them.

2.) Assuming you did properly call them, they wouldn't do anything. They have no code in them.

Be sure that you keep in mind what they are intended to do and add the appropriate code to them. There is code contained in the case statements in main() that would be rendered redundant if you implement withdraw and deposit correctly. Be sure you update your case statements appropriately after you figure out what is missing in withdraw and deposit.
Featured Poster
Reputation Points: 833
Solved Threads: 392
Posting Maven
Fbody is offline Offline
2,846 posts
since Oct 2009
Feb 22nd, 2010
0
Re: Need Help w/ a simple banking program
How can i capture the value of void account::depositFunds() and then be able to use it in the getBalance() function. That's what i think needs to happen, but i don't know how to do it.

Click to Expand / Collapse  Quote originally posted by Fbody ...
There are 2 reasons they don't do anything:

1.) You never call withdraw or deposit. You need to add lines to cases 2 and 3 that call them.

2.) Assuming you did properly call them, they wouldn't do anything. They have no code in them.

Be sure that you keep in mind what they are intended to do and add the appropriate code to them. There is code contained in the case statements in main() that would be rendered redundant if you implement withdraw and deposit correctly. Be sure you update your case statements appropriately after you figure out what is missing in withdraw and deposit.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
blakenbama is offline Offline
6 posts
since Feb 2010
Feb 22nd, 2010
0
Re: Need Help w/ a simple banking program
You have some floats located in a while loop, you should fix that, always place your variable either at the start of int main() or right after you include the headers.
Reputation Points: 8
Solved Threads: 4
Junior Poster in Training
Shinedevil is offline Offline
71 posts
since Nov 2008

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 help, searching txt file for keyword c++
Next Thread in C++ Forum Timeline: Tracing a two deminsional Array





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


Follow us on Twitter


© 2011 DaniWeb® LLC