STATEMENT: 1. Define a class to represent a bank account include the following members:
Data Members:
· Name of the depositor
· Account no
· Type of the account
· Balance amount in the account
Member Functions:
· Constructor with arguments to assign initial value
· Destructor to destroy objects
· Function to deposit an amount
· Function to withdraw an amount after checking balance
· Function to display name and balance
Write main() function and initialize three different objects in it. Invoke all member functions with these three objects.
Solution :
#include<iostream.h>
#include<conio.h>
#include<string.h>
class bank
{
private:
char a[10];
int acc_no;
char typ[10];
int balance;
public:
bank(char h[10],int j,char k[10],int l)
{
strcpy(a,h);
acc_no=j;
strcpy(typ,k);
balance=l;
}
void deposit();
void withdraw();
void showdata();
~bank()
{
cout<<"object is going to destroy"<<endl;
showdata();
getch();
}
};
void main()
{
clrscr();
bank t1("ehsan",1,"BBA",100),t2("aqeel",2,"BBc",200);
cout<<"1st object"<<endl;
t1.showdata();
cout<<"For deposit ammount"<<endl;
t1.deposit();
cout<<"For with draw ammount"<<endl;
t1.withdraw();
cout<<"1st object updata"<<endl;
t1.showdata();
getch();
}
void bank::deposit()
{
int m;
cout<<"enter ammount to diposit"<<endl;
cin>>m;
balance=balance+m;
}
void bank::withdraw()
{
int n;
cout<<"your remaining balance"<<endl;
cout<<balance<<endl;
cout<<"Enter ammount enter"<<endl;
cin>>n;
balance=balance-n;
cout<<"your current balance is ="<<endl;
cout<<balance<<endl;
}
void bank::showdata()
{
cout<<"Account title"<<endl;
cout<<a<<endl;
cout<<"balanc="<<balance<<endl;
cout<<"=================================="<<endl;
}