944,052 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 4397
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Jul 17th, 2007
0

Bank Account ===>Need help >.< Thk

Expand Post »
Hi ,

I am stuck with my this bank account programming. The question is like this:

Create a base class Bank of a bank account with member functions to allow withdrawal, deposit and calculation of balance. Account should have a name, account number and type.

Create derived class Saving of a saving account, which allows overdraft up to $8000 and gives interest of 2% per annum. Create another derived class Current of a current account, which does not allow overdraft and does not give any interest.

Create two objects of the derived classes with initial deposits of $2000 and $5000 each. Demonstrate the use of various member functions for withdrawal, deposit, interest calculation for one month, showing balance and giving warning when the account balance is zero or less.

The display can be as given below (user inputs are in bold):

Account Name: Jacky Chan(in bold)
Account No: 12345(in bold)
Type: Saving
Balance: $6000
Enter positive amount to deposit and negative to withdraw: $1000(in bold)
Balance: $7000
Interest next month: $11.67



This is what i have done so far:
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class Bank
  6. {
  7. private:
  8. string myname;
  9. int number;
  10. double changes;
  11.  
  12. public:
  13. void SetBank(string , int , double);
  14. void EnterName();
  15. void ShowName(void );
  16. void EnterNumber();
  17. void ShowNumber(void );
  18. void EnterChanges();
  19. void ShowChanges(void );
  20. };
  21.  
  22. void Bank::SetBank(string name, int num, double c)
  23. {
  24. myname = name;
  25. number = num;
  26. changes = c;
  27. }
  28.  
  29. void Bank::EnterName()
  30. {
  31. cout<<"Please enter your Account Name: ";
  32. cin>>myname;
  33. }
  34.  
  35. void Bank::ShowName()
  36. {
  37. cout<<"\n\nAccount Name: "<<myname<<endl;
  38. }
  39.  
  40. void Bank::EnterNumber()
  41. {
  42. cout<<"Please enter your Account Number: ";
  43. cin>>number;
  44. }
  45.  
  46. void Bank::ShowNumber()
  47. {
  48. cout<<"Account No: "<<number<<endl;
  49. }
  50.  
  51. void Bank::EnterChanges()
  52. {
  53. cout<<"Please enter positive amount to deposit and negative to withdraw: $";
  54. cin>>changes;
  55.  
  56. }
  57.  
  58. void Bank::ShowChanges()
  59. {
  60. cout<<"Enter positive amount to deposit and negative to withdraw: $"<<changes<<endl;
  61. }
  62.  
  63. void main()
  64. {
  65. Bank bank;
  66.  
  67.  
  68. bank.EnterName();
  69. bank.EnterNumber();
  70. bank.EnterChanges();
  71.  
  72. bank.ShowName();
  73. bank.ShowNumber();
  74. bank.ShowChanges();
  75.  
  76.  
  77. cout<<"\n\n\n ^_^ Thank you for using this program ^_^ "<<endl;
  78. cout<<" Have a nice day "<<endl;
  79. }
Please >.< i need a detail explanation how the program work ... Thankk in advance
Last edited by Ancient Dragon; Jul 17th, 2007 at 9:23 am. Reason: add code tags
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cheongsiwei is offline Offline
5 posts
since Jul 2007
Jul 17th, 2007
0

Re: Bank Account ===>Need help >.< Thk

Quote ...
i need a detail explanation how the program work
Didn't you write it?
Reputation Points: 180
Solved Threads: 34
Posting Whiz
Hamrick is offline Offline
322 posts
since Jun 2007
Jul 17th, 2007
0

Re: Bank Account ===>Need help >.< Thk

>>i need a detail explanation how the program work
I assum then that you did not write that code? If you had then you would know how it works.

What part(s) do you need help with?
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,954 posts
since Aug 2005
Jul 17th, 2007
0

Re: Bank Account ===>Need help >.< Thk

I am sorry for not making my question clear enough .

The part that i need help is :
Create derived class Saving of a saving account, which allows overdraft up to $8000 and gives interest of 2% per annum. Create another derived class Current of a current account, which does not allow overdraft and does not give any interest.

Create two objects of the derived classes with initial deposits of $2000 and $5000 each. Demonstrate the use of various member functions for withdrawal, deposit, interest calculation for one month, showing balance and giving warning when the account balance is zero or less.


By the way the program i wrote only able to display :

Account Name: Jacky Chan
Account No: 12345
Enter positive amount to deposit and negative to withdraw: $1000

I not too sure how to do the saving and current derived class and i need some explanation for it too .
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cheongsiwei is offline Offline
5 posts
since Jul 2007
Jul 17th, 2007
0

Re: Bank Account ===>Need help >.< Thk

>>Create derived class Saving of a saving account
C++ Syntax (Toggle Plain Text)
  1. class Saving : public Bank
  2. {
  3. // put class objects/methods here
  4. };
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,954 posts
since Aug 2005
Jul 17th, 2007
0

Re: Bank Account ===>Need help >.< Thk

i just updated my program , but i encounter some problem . May i know where have i make the mistake ?

The program:
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class Bank
  6. {
  7. private:
  8. //double balance, overdraft, interest;
  9. string myname;
  10. int number;
  11. double changes;
  12. double initialbal;
  13. double endingbal,amount;
  14.  
  15. public:
  16. //Bank(double bal , double o , double i )
  17. // {
  18. // balance = bal;
  19. // overdraft = o;
  20. // interest = i;
  21.  
  22. // }
  23. void SetBank(string , int , double , double , double);
  24. void EnterName();
  25. void ShowName(void );
  26. void EnterNumber();
  27. void ShowNumber(void );
  28. void EnterChanges();
  29. void ShowChanges(void );
  30. void EnternComputeInitialBal(double );
  31. void ComputeEndinglBal(void );
  32.  
  33. };
  34.  
  35. void Bank::SetBank(string name, int num, double c, double ibal, double ebal)
  36. {
  37. myname = name;
  38. number = num;
  39. changes = c;
  40. initialbal = ibal;
  41. endingbal = ebal;
  42.  
  43. }
  44.  
  45. void Bank::EnterName()
  46. {
  47. cout<<"Please enter your Account Name: ";
  48. cin>>myname;
  49. }
  50.  
  51. void Bank::ShowName()
  52. {
  53. cout<<"\n\nAccount Name: "<<myname<<endl;
  54. }
  55.  
  56. void Bank::EnterNumber()
  57. {
  58. cout<<"Please enter your Account Number: ";
  59. cin>>number;
  60. }
  61.  
  62. void Bank::ShowNumber()
  63. {
  64. cout<<"Account No: "<<number<<endl;
  65. }
  66.  
  67. void Bank::EnterChanges()
  68. {
  69. cout<<"Please enter positive amount to deposit and negative to withdraw: $";
  70. cin>>changes;
  71.  
  72. }
  73.  
  74. void Bank::ShowChanges()
  75. {
  76. cout<<"Enter positive amount to deposit and negative to withdraw: $"<<changes<<endl;
  77. }
  78.  
  79. void Bank::EnternComputeInitialBal(double ibal)
  80. {
  81. cout<<"Initial balance : $"<<ibal<<endl;
  82. }
  83.  
  84. void Bank::ComputeEndinglBal()
  85. {
  86. amount=initialbal+changes;
  87. cout<<"Ending balance : $"<<amount<<endl;
  88. }
  89.  
  90. void main()
  91. {
  92. Bank bank;
  93.  
  94.  
  95. bank.EnterName();
  96. bank.EnterNumber();
  97. bank.EnterChanges();
  98.  
  99.  
  100. bank.ShowName();
  101. bank.ShowNumber();
  102. bank.EnternComputeInitialBal(2000);
  103. bank.ShowChanges();
  104. bank.ComputeEndinglBal();
  105.  
  106. cout<<"\n\n\n ^_^ Thank you for using this program ^_^ "<<endl;
  107. cout<<" Have a nice day "<<endl;
  108. }
The error i encounter is the bank.ComputeEndinglBal(); ...
the output is : $-9.25596e+061

Thk in advance
Last edited by Ancient Dragon; Jul 17th, 2007 at 11:48 am. Reason: add code tags -- please learn to use them
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cheongsiwei is offline Offline
5 posts
since Jul 2007
Jul 17th, 2007
0

Re: Bank Account ===>Need help >.< Thk

It is using uninitialized variables -- initialbal was never set to anything. You need to code a default constructur that initializes all variables to 0 or some other known value. Don't assume the compiler will do this for you because it won't.
Last edited by Ancient Dragon; Jul 17th, 2007 at 11:52 am.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,954 posts
since Aug 2005
Jul 22nd, 2007
0

Re: Bank Account ===>Need help >.< Thk

C++ Syntax (Toggle Plain Text)
  1.  
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. class Bank
  7. {
  8. private:
  9. string myname;
  10. int number;
  11. double changes;
  12. double initialbal;
  13. double endingbal;
  14.  
  15. public:
  16. Bank(string name=" ", int num=0, double c=0, double ibal=0, double ebal=0)
  17. {
  18. myname = name;
  19. number = num;
  20. changes = c;
  21. initialbal = ibal;
  22. endingbal = ebal;
  23. }
  24. void EnterName();
  25. void ShowName(void );
  26. void EnterNumber();
  27. void ShowNumber(void );
  28. void EnterChanges();
  29. void ShowChanges(void );
  30. void EnternComputeInitialBal(double );
  31. void ComputeEndinglBal(double );
  32.  
  33. };
  34.  
  35. void Bank::EnterName()
  36. {
  37. cout<<"Please enter your Account Name: ";
  38. getline(cin, myname);
  39. }
  40.  
  41. void Bank::ShowName()
  42. {
  43. cout<<"\n\nAccount Name: "<<myname<<endl;
  44. }
  45.  
  46. void Bank::EnterNumber()
  47. {
  48. cout<<"Please enter your Account Number: ";
  49. cin>>number;
  50. }
  51.  
  52. void Bank::ShowNumber()
  53. {
  54. cout<<"Account No: "<<number<<endl;
  55. }
  56.  
  57. void Bank::EnterChanges()
  58. {
  59. cout<<"Please enter positive amount to deposit and negative to withdraw: $";
  60. cin>>changes;
  61.  
  62. }
  63.  
  64. void Bank::ShowChanges()
  65. {
  66. cout<<"Enter positive amount to deposit and negative to withdraw: $"<<changes<<endl;
  67. }
  68.  
  69. void Bank::EnternComputeInitialBal(double ibal)
  70. {
  71. cout<<"Enter inital balance : $"<<ibal<<endl;
  72. }
  73.  
  74. void Bank::ComputeEndinglBal(double ibal)
  75. {
  76. endingbal=ibal+changes;
  77. cout<<"Ending balance : $"<<endingbal<<endl;
  78. }
  79.  
  80. void main()
  81. {
  82. Bank bank;
  83.  
  84.  
  85. bank.EnterName();
  86. bank.EnterNumber();
  87. bank.EnterChanges();
  88.  
  89.  
  90. bank.ShowName();
  91. bank.ShowNumber();
  92. cout<<"Type: Saving "<<endl;
  93. bank.EnternComputeInitialBal(6000);
  94. bank.ShowChanges();
  95. bank.ComputeEndinglBal(6000);
  96. cout<<"Interest next month: $11.67"<<endl;
  97.  
  98. cout<<"\n\n\n ^_^ Thank you for using this program ^_^ "<<endl;
  99. cout<<" Have a nice day "<<endl;
  100. }

Sorry ancient dragon ... hopefully this time i can get the code tag works...
Now i had no problem with the initialising of datas , but i am not too sure how to get the derived classes work in my program(as mention in the first post , i need a saving and current derived class) . Any kind person willing to advise me on that ? Thanks in advance :)
Last edited by Ancient Dragon; Jul 22nd, 2007 at 10:39 am. Reason: corrected code tags
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cheongsiwei is offline Offline
5 posts
since Jul 2007
Jul 22nd, 2007
0

Re: Bank Account ===>Need help >.< Thk

Sorry ancient dragon ... hopefully this time i can get the code tag works...
Now i had no problem with the initialising of datas , but i am not too sure how to get the derived classes work in my program(as mention in the first post , i need a saving and current derived class) . Any kind person willing to advise me on that ? Thanks in advance
You need to put the [CODE] tags around the area of text where your code is


To create a derived class which inherits from Bank is as simple as
CPP Syntax (Toggle Plain Text)
  1. class saving : public Bank
  2. {
  3. // saving-specific code in here
  4. };
Last edited by Bench; Jul 22nd, 2007 at 10:40 am.
Reputation Points: 307
Solved Threads: 62
Posting Pro
Bench is offline Offline
565 posts
since Feb 2006
Jul 22nd, 2007
0

Re: Bank Account ===>Need help >.< Thk

I had tried that before .. but a error occur when i compile and run the program . I think the problem is because the main function is used once in the "class Bank" , so i cant use the main function again in the "class Saving" . Is there any other way to run the functions that the "class Saving' without using the main function ?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cheongsiwei is offline Offline
5 posts
since Jul 2007

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: Could someone recomend me a good compiler to start learning C++?
Next Thread in C++ Forum Timeline: hi there!!!hw problem!!





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


Follow us on Twitter


© 2011 DaniWeb® LLC