954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Bank account class

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.

bobjohnson
Newbie Poster
5 posts since Jul 2004
Reputation Points: 10
Solved Threads: 0
 

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.

bobjohnson
Newbie Poster
5 posts since Jul 2004
Reputation Points: 10
Solved Threads: 0
 

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: [thread]1739[/thread]

cscgal
The Queen of DaniWeb
Administrator
19,422 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 230
 

Thank you. This is helping. I read over your tutorial as well. Great stuff!

I'm sure I will be back with more questions. :-)

bobjohnson
Newbie Poster
5 posts since Jul 2004
Reputation Points: 10
Solved Threads: 0
 

Never mind. I got the question I posted. I'm sure I will be back with more! :)

bobjohnson
Newbie Poster
5 posts since Jul 2004
Reputation Points: 10
Solved Threads: 0
 

Just want to thank you again. I got it working. It was all due to your help.

Great job!

bobjohnson
Newbie Poster
5 posts since Jul 2004
Reputation Points: 10
Solved Threads: 0
 

#include
#include
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: "<>number;
}
void Bank::ShowNumber()
{
cout<<"Account No: "<>changes;
}
void Bank::ShowChanges()
{
cout<<"Enter positive amount to deposit and negative to withdraw: $"<

roshaero
Newbie Poster
1 post since Sep 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You