C++:Define a class to represent a bank account. Include the following members:write a main program to test the program.
Data Members
1 Name of the depositor
2 Account Number
3 Type of account
4 Balance amount in the account
Member function
1 To assign initial values
2 To deposit an amount
3 To withdraw an amount after checking the balance
4 To display name and Balance
#include <iostream.h>
#include <iomanip.h>
#include <conio.h>
class bank
{
private:
char name[20];
int acno;
char actype[20];
int bal;
public :
void opbal(void);
void deposit(int ac);
void withdraw(int ac);
void display(void);
int fo;
};
void bank :: opbal(void)
{
cout<<endl<<endl;
cout<<"Enter Name :-";
cin>>name;
cout<<"Enter A/c no. :-";
cin>>acno;
cout<<"Enter A/c Type :-";
cin>>actype;
cout<<"Enter Opening Balance:-";
cin>>bal;
}
void bank :: display(void)
{
cout<<setw(50)<<"DETAILS"<<endl;
cout<<setw(50)<<"name "<<name<<endl;
cout<<setw(50)<<"A/c. No. "<<acno<<endl;
cout<<setw(50)<<"A/c Type "<<actype<<endl;
cout<<setw(50)<<"Balance "<<bal<<endl;
cout<<setw(50)<<"---------------------";
}
void bank :: deposit(int ac)
{
if(acno==ac)
{
cout<<"Enter Deposit amount :-";
int deposit=0;
cin>>deposit;
deposit=deposit+bal;
cout<<"\nDeposit Balance = "<<deposit;
bal=deposit;
fo=1;
}
}
void bank :: withdraw(int ac)
{
if(acno==ac)
{
int withdraw;
cout<<"\nBalance Amount = "<<bal;
cout<<"\nEnter Withdraw Amount :-";
cin>>withdraw;
bal=bal-withdraw;
cout<<"After Withdraw Balance is "<<bal;
fo=1;
}
}
void main()
{
clrscr();
bank o1[10];
int choice,i=0,j,ac;
do
{
cout<<"\n\nChoice List\n\n";
cout<<"1) To assign Initial Value\n";
cout<<"2) To Deposit\n";
cout<<"3) To Withdraw\n";
cout<<"4) To Display All Details\n";
cout<<"5) EXIT\n";
cout<<"Enter your choice :-";
cin>>choice;
switch(choice)
{
case 1:
o1[i++].opbal();
break;
case 2:
cout<<"Enter A/c no. :-";
cin>>ac;
for(j=0;j<i;j++)
{
o1[j].deposit(ac);
if(o1[j].fo==1)
{
o1[j].fo=0;
break;
}
}
break;
case 3: cout<<"Enter A/c no. :-";
cin>>ac;
for(j=0;j<i;j++)
{
o1[j].withdraw(ac);
if(o1[j].fo==1)
{
o1[j].fo=0;
break;
}
}
break;
case 4: clrscr();
for(j=0;j<i;j++)
{
o1[j].display();
cout<<"Press any key to continue...";
getch();
}
break;
case 5: goto end;
}
}while(1);
end:
}