| | |
Bank account class
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2004
Posts: 5
Reputation:
Solved Threads: 0
I have to write a C++ program that:
Declares and defines a class called “bankAccount� . This class has two private variables, accountNubmer and balance, It also is supposed to have a member functions that will:
a. Create an account (Takes account number as a parameter)
b. Deposit money in the account.
c. Withdraw money from the account.
d. Display the balance in current account.
e. Close the account(which can be simulated byprinting out that the client has been issued the check of the balance amount in his/her account and then printing the account is closed.) I'm also supposed to write the client code for this class, which instantiates two objects of this class, and uses all these member functions at least once.
To say the least I am lost. Any help or direction would be appreciated.
Declares and defines a class called “bankAccount� . This class has two private variables, accountNubmer and balance, It also is supposed to have a member functions that will:
a. Create an account (Takes account number as a parameter)
b. Deposit money in the account.
c. Withdraw money from the account.
d. Display the balance in current account.
e. Close the account(which can be simulated byprinting out that the client has been issued the check of the balance amount in his/her account and then printing the account is closed.) I'm also supposed to write the client code for this class, which instantiates two objects of this class, and uses all these member functions at least once.
To say the least I am lost. Any help or direction would be appreciated.
You could have a variable called marys_account_number, a variable called marys_balance, a variable called joes_account_number, and a variable called joes_balance. You could also have a function that withdraws money into Mary's account by decreasing the marys_balance variable, etc. But doesn't that all seem a bit redundant? What if we're talking about 20 people instead of just two? Classes allow us to formulate a template for one person. We can then create what is called an instance of a class.
So, for example, take a class called bankAccount. You could have one instance of the class called MarysAccount which contains all the information about Mary's bank account. You could also have JoesAccount which contains all the information about Joe's bank account.
Classes contain two kinds of information/data: public and private. Public variables and public functions can be accessed from anywhere. However, private variables and functions can only be accessed from within the class itself.
For example, suppose there is a public variable balance inside the bankAccount class. Now suppose there was an instance of this class called joesaccount. With that balance variable public, anyone can simply say joesaccount.balance = 1000000; and Joe made himself a millionaire.
That's why we use private data members. By making balance private, it can only be accessed from a public function inside the bankAccount class. For example, take the public function "withdraw". We can call joesaccount.withdraw(500); The withdraw class would first make sure that there is $500 in the account to withdraw. If there is, it will do balance = balance - 500; Since balance is a member of the same class, by simply using the variable "balance" it is known that it is Joe's account we're talking about.
I hope this was a starter. The reason I went so detailed is because a bank account class was actually the way I first learned about classes, too. I also figured it might be of some help to others out there. There is also a tutorial I wrote on classes here: http://www.daniweb.com/forums/thread1739.html
So, for example, take a class called bankAccount. You could have one instance of the class called MarysAccount which contains all the information about Mary's bank account. You could also have JoesAccount which contains all the information about Joe's bank account.
Classes contain two kinds of information/data: public and private. Public variables and public functions can be accessed from anywhere. However, private variables and functions can only be accessed from within the class itself.
For example, suppose there is a public variable balance inside the bankAccount class. Now suppose there was an instance of this class called joesaccount. With that balance variable public, anyone can simply say joesaccount.balance = 1000000; and Joe made himself a millionaire.
That's why we use private data members. By making balance private, it can only be accessed from a public function inside the bankAccount class. For example, take the public function "withdraw". We can call joesaccount.withdraw(500); The withdraw class would first make sure that there is $500 in the account to withdraw. If there is, it will do balance = balance - 500; Since balance is a member of the same class, by simply using the variable "balance" it is known that it is Joe's account we're talking about.
I hope this was a starter. The reason I went so detailed is because a bank account class was actually the way I first learned about classes, too. I also figured it might be of some help to others out there. There is also a tutorial I wrote on classes here: http://www.daniweb.com/forums/thread1739.html
![]() |
Similar Threads
- C++ Bank account - help!! (C++)
- Design a class named BankAccount to hold the following data for a bank account: (Java)
- Another Bank Account class (C++)
- Bank Account class (C++)
- Bank Account ===>Need help >.< Thk (C++)
- Unable to view yahoo mail or online bank account etc (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: Displaying a League Table
- Next Thread: User defined functions
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets







