Bank account class

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

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

Bank account class

 
0
  #1
Jul 29th, 2004
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 5
Reputation: bobjohnson is an unknown quantity at this point 
Solved Threads: 0
bobjohnson bobjohnson is offline Offline
Newbie Poster

Re: Bank account class

 
0
  #2
Jul 29th, 2004
Maybe a better way to ask my question is... Where online can I find a tutorial or something that will help me understand classes? I am just not getting it. I am trying different things and nothing seems to work.

Thanks for any direction. I need it.
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,036
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 131
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is online now Online
The Queen of DaniWeb

Re: Bank account class

 
0
  #3
Jul 29th, 2004
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
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/daniweb
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 5
Reputation: bobjohnson is an unknown quantity at this point 
Solved Threads: 0
bobjohnson bobjohnson is offline Offline
Newbie Poster

Re: Bank account class

 
0
  #4
Jul 29th, 2004
Thank you. This is helping. I read over your tutorial as well. Great stuff!

I'm sure I will be back with more questions. :-)
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 5
Reputation: bobjohnson is an unknown quantity at this point 
Solved Threads: 0
bobjohnson bobjohnson is offline Offline
Newbie Poster

Re: Bank account class

 
0
  #5
Jul 29th, 2004
Never mind. I got the question I posted. I'm sure I will be back with more!
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 5
Reputation: bobjohnson is an unknown quantity at this point 
Solved Threads: 0
bobjohnson bobjohnson is offline Offline
Newbie Poster

Re: Bank account class

 
0
  #6
Jul 29th, 2004
Just want to thank you again. I got it working. It was all due to your help.

Great job!
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC