| | |
Bank Account ===>Need help >.< Thk
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2007
Posts: 5
Reputation:
Solved Threads: 0
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:
Please >.< i need a detail explanation how the program work ... Thankk in advance
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)
#include <iostream> #include <string> using namespace std; class Bank { private: string myname; int number; double changes; public: void SetBank(string , int , double); void EnterName(); void ShowName(void ); void EnterNumber(); void ShowNumber(void ); void EnterChanges(); void ShowChanges(void ); }; void Bank::SetBank(string name, int num, double c) { myname = name; number = num; changes = c; } void Bank::EnterName() { cout<<"Please enter your Account Name: "; cin>>myname; } void Bank::ShowName() { cout<<"\n\nAccount Name: "<<myname<<endl; } void Bank::EnterNumber() { cout<<"Please enter your Account Number: "; cin>>number; } void Bank::ShowNumber() { cout<<"Account No: "<<number<<endl; } void Bank::EnterChanges() { cout<<"Please enter positive amount to deposit and negative to withdraw: $"; cin>>changes; } void Bank::ShowChanges() { cout<<"Enter positive amount to deposit and negative to withdraw: $"<<changes<<endl; } void main() { Bank bank; bank.EnterName(); bank.EnterNumber(); bank.EnterChanges(); bank.ShowName(); bank.ShowNumber(); bank.ShowChanges(); cout<<"\n\n\n ^_^ Thank you for using this program ^_^ "<<endl; cout<<" Have a nice day "<<endl; }
Last edited by Ancient Dragon; Jul 17th, 2007 at 9:23 am. Reason: add code tags
>>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?
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.
•
•
Join Date: Jul 2007
Posts: 5
Reputation:
Solved Threads: 0
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 .
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 .
>>Create derived class Saving of a saving account
C++ Syntax (Toggle Plain Text)
class Saving : public Bank { // put class objects/methods here };
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.
•
•
Join Date: Jul 2007
Posts: 5
Reputation:
Solved Threads: 0
i just updated my program , but i encounter some problem . May i know where have i make the mistake ?
The program:
The error i encounter is the bank.ComputeEndinglBal(); ...
the output is : $-9.25596e+061
Thk in advance
The program:
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <string> using namespace std; class Bank { private: //double balance, overdraft, interest; string myname; int number; double changes; double initialbal; double endingbal,amount; public: //Bank(double bal , double o , double i ) // { // balance = bal; // overdraft = o; // interest = i; // } void SetBank(string , int , double , double , double); void EnterName(); void ShowName(void ); void EnterNumber(); void ShowNumber(void ); void EnterChanges(); void ShowChanges(void ); void EnternComputeInitialBal(double ); void ComputeEndinglBal(void ); }; void Bank::SetBank(string name, int num, double c, double ibal, double ebal) { myname = name; number = num; changes = c; initialbal = ibal; endingbal = ebal; } void Bank::EnterName() { cout<<"Please enter your Account Name: "; cin>>myname; } void Bank::ShowName() { cout<<"\n\nAccount Name: "<<myname<<endl; } void Bank::EnterNumber() { cout<<"Please enter your Account Number: "; cin>>number; } void Bank::ShowNumber() { cout<<"Account No: "<<number<<endl; } void Bank::EnterChanges() { cout<<"Please enter positive amount to deposit and negative to withdraw: $"; cin>>changes; } void Bank::ShowChanges() { cout<<"Enter positive amount to deposit and negative to withdraw: $"<<changes<<endl; } void Bank::EnternComputeInitialBal(double ibal) { cout<<"Initial balance : $"<<ibal<<endl; } void Bank::ComputeEndinglBal() { amount=initialbal+changes; cout<<"Ending balance : $"<<amount<<endl; } void main() { Bank bank; bank.EnterName(); bank.EnterNumber(); bank.EnterChanges(); bank.ShowName(); bank.ShowNumber(); bank.EnternComputeInitialBal(2000); bank.ShowChanges(); bank.ComputeEndinglBal(); cout<<"\n\n\n ^_^ Thank you for using this program ^_^ "<<endl; cout<<" Have a nice day "<<endl; }
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
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.
•
•
Join Date: Jul 2007
Posts: 5
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <string> using namespace std; class Bank { private: string myname; int number; double changes; double initialbal; double endingbal; public: Bank(string name=" ", int num=0, double c=0, double ibal=0, double ebal=0) { myname = name; number = num; changes = c; initialbal = ibal; endingbal = ebal; } void EnterName(); void ShowName(void ); void EnterNumber(); void ShowNumber(void ); void EnterChanges(); void ShowChanges(void ); void EnternComputeInitialBal(double ); void ComputeEndinglBal(double ); }; void Bank::EnterName() { cout<<"Please enter your Account Name: "; getline(cin, myname); } void Bank::ShowName() { cout<<"\n\nAccount Name: "<<myname<<endl; } void Bank::EnterNumber() { cout<<"Please enter your Account Number: "; cin>>number; } void Bank::ShowNumber() { cout<<"Account No: "<<number<<endl; } void Bank::EnterChanges() { cout<<"Please enter positive amount to deposit and negative to withdraw: $"; cin>>changes; } void Bank::ShowChanges() { cout<<"Enter positive amount to deposit and negative to withdraw: $"<<changes<<endl; } void Bank::EnternComputeInitialBal(double ibal) { cout<<"Enter inital balance : $"<<ibal<<endl; } void Bank::ComputeEndinglBal(double ibal) { endingbal=ibal+changes; cout<<"Ending balance : $"<<endingbal<<endl; } void main() { Bank bank; bank.EnterName(); bank.EnterNumber(); bank.EnterChanges(); bank.ShowName(); bank.ShowNumber(); cout<<"Type: Saving "<<endl; bank.EnternComputeInitialBal(6000); bank.ShowChanges(); bank.ComputeEndinglBal(6000); cout<<"Interest next month: $11.67"<<endl; cout<<"\n\n\n ^_^ Thank you for using this program ^_^ "<<endl; cout<<" Have a nice day "<<endl; }
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
•
•
•
•
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
To create a derived class which inherits from Bank is as simple as
CPP Syntax (Toggle Plain Text)
class saving : public Bank { // saving-specific code in here };
Last edited by Bench; Jul 22nd, 2007 at 10:40 am.
¿umop apisdn upside down? •
•
Join Date: Jul 2007
Posts: 5
Reputation:
Solved Threads: 0
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 ?
![]() |
Similar Threads
- Unable to view yahoo mail or online bank account etc (Viruses, Spyware and other Nasties)
- bank account (C++)
- Bank account class (C++)
Other Threads in the C++ Forum
- Previous Thread: Could someone recomend me a good compiler to start learning C++?
- Next Thread: hi there!!!hw problem!!
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets







