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

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

Join Date: Jul 2007
Posts: 5
Reputation: cheongsiwei is an unknown quantity at this point 
Solved Threads: 0
cheongsiwei cheongsiwei is offline Offline
Newbie Poster

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

 
0
  #1
Jul 17th, 2007
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:
  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
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 322
Reputation: Hamrick will become famous soon enough Hamrick will become famous soon enough 
Solved Threads: 33
Hamrick's Avatar
Hamrick Hamrick is offline Offline
Posting Whiz

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

 
0
  #2
Jul 17th, 2007
i need a detail explanation how the program work
Didn't you write it?
The truth does not change according to our ability to stomach it.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,431
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: 1471
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

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

 
0
  #3
Jul 17th, 2007
>>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?
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: Jul 2007
Posts: 5
Reputation: cheongsiwei is an unknown quantity at this point 
Solved Threads: 0
cheongsiwei cheongsiwei is offline Offline
Newbie Poster

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

 
0
  #4
Jul 17th, 2007
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 .
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,431
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: 1471
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

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

 
0
  #5
Jul 17th, 2007
>>Create derived class Saving of a saving account
  1. class Saving : public Bank
  2. {
  3. // put class objects/methods here
  4. };
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: Jul 2007
Posts: 5
Reputation: cheongsiwei is an unknown quantity at this point 
Solved Threads: 0
cheongsiwei cheongsiwei is offline Offline
Newbie Poster

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

 
0
  #6
Jul 17th, 2007
i just updated my program , but i encounter some problem . May i know where have i make the mistake ?

The program:
  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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,431
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: 1471
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

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

 
0
  #7
Jul 17th, 2007
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.
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: Jul 2007
Posts: 5
Reputation: cheongsiwei is an unknown quantity at this point 
Solved Threads: 0
cheongsiwei cheongsiwei is offline Offline
Newbie Poster

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

 
0
  #8
Jul 22nd, 2007
  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
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 488
Reputation: Bench has a spectacular aura about Bench has a spectacular aura about Bench has a spectacular aura about 
Solved Threads: 49
Bench's Avatar
Bench Bench is offline Offline
Posting Pro in Training

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

 
0
  #9
Jul 22nd, 2007
Originally Posted by cheongsiwei View Post
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
  1. class saving : public Bank
  2. {
  3. // saving-specific code in here
  4. };
Last edited by Bench; Jul 22nd, 2007 at 10:40 am.
¿umop apisdn upside down?
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 5
Reputation: cheongsiwei is an unknown quantity at this point 
Solved Threads: 0
cheongsiwei cheongsiwei is offline Offline
Newbie Poster

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

 
0
  #10
Jul 22nd, 2007
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 ?
Reply With Quote Quick reply to this message  
Reply

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



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC