Develop a class BankAccount that supports these methods; __init__(); Initializes
ID: 3778318 • Letter: D
Question
Develop a class BankAccount that supports these methods; __init__(); Initializes the bank account balance to the value of the input argument, or to 0 if no input argument is given withdraw(): Takes an amount as input and withdraws it from the balance deposit (): Takes an amount as input and adds it to the balance balance (); Returns the balance on the account >>> x = BankAccount (700) >>> x.balance()) 700.00 >>> x.withdraw(70) >>> x.balance() 630.00 >>> x.deposit(7) >>> x.balance() 637.00Explanation / Answer
#include<iostream.h>
#include<conio.h>
#include<string.h>
class bank
{
char name[20];
int ano;
char atype[20];
float bal;
public:
void get(int no,char *n,char *t,float b)
{
strcpy(name,n);
ano=no;
strcpy(atype,t);
bal=b;
}
float deposit()
{
float amt;
cout<<“ Enter amount: “;
cin>>amt;
bal=bal+amt;
return bal;
}
float withdrw()
{
float amt;
cout<<“ How many Rupees withdraw: “;
cin>>amt;
bal=bal-amt;
return bal;
}
void disp()
{
cout<<“ Account number: “<<ano;
cout<<“ Name: “<<name;
cout<<“ Account type: “<<atype;
cout<<“ Deposit Amount: “<<deposit();
cout<<“ After Withdraw Amount balnace: “<<withdrw();
}
};
void main()
{
int n;
char nm[20],t[20];
float a;
bank bk;
clrscr();
cout<<“ Enter Account no.: “; cin>>n;
cout<<“ Enter Name: “; cin>>nm;
cout<<“ Enter account type: “; cin>>t;
cout<<“ Enter balance amount: “;cin>>a;
bk.get(n,nm,t,a);
bk.disp();
getch();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.