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.

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.

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]

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

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

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

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

Great job!

#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;
}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.