#include<iostream>
using namespace std;
#include<conio.h>
#include<string.h>
class bankaccount
{
char m_name[20];
int m_accno;
char m_type[10];
double m_balance;
char m_pswd[10];
public:
void initial_val()
{
cout<<"\n\nName of the depositer: ";
cin>>m_name;
cout<<"\nAccount No. : ";
cin>>m_accno;
cout<<"\nType of the account (saving/current): ";
cin>>m_type;
cout<<"\nBalance amount in the account : Rs ";
cin>>m_balance;
cout<<"\nPassword: ";
cin>>m_pswd;
}
void deposit()
{
double m;
cout<<"\nAmount to be deposited: Rs ";
cin>>m;
m_balance=m_balance+m;
cout<<"\nYour current balance is: Rs "<<m_balance;
cout<<"\n\n";
}
void withdraw()
{
double n;
char a[10];
cout<<"\nEnter password: ";
cin>>a;
if(strcmp(m_pswd,a)==0)
{
cout<<"\nAmount to be withdrawn: Rs ";
cin>>n;
if(m_balance<=n)
{
cout<<"Balance amount is less ==> amount cannot be withdrawn\n";
}
else
{
m_balance=m_balance-n;
cout<<"\nYour current balance is: Rs "<<m_balance;
cout<<"\n\n";
}
}
else
{
cout<<"\nINVALID PASSWORD !!!\n";
}
}
void display()
{
char b[10];
cout<<"\nEnter password: ";
cin>>b;
if(strcmp(m_pswd,b)==0)
{
cout<<"\n\n\nName of the depositer: "<<m_name;
cout<<"\n\nBalance amount in the account : "<<m_balance;
cout<<"\n\n";
}
else
{
cout<<"\nINVALID PASSWORD !!!\n";
}
}
};
void main()
{
bankaccount b;
int i,c;
cout<<"\n* This is your bank account *\n";
cout<<"\n Enter details";
b.initial_val();
while(1)
{
cout<<"\n1. Deposit\n"<<"2.Withdraw\n"<<"3.Display\n"<<"4. Exit\n";
cout<<"\nEnter your choice: ";
cin>>c;
switch(c)
{
case 1:b.deposit();
break;
case 2:b.withdraw();
break;
case 3:b.display();
break;
case 4:exit(0);
default:cout<<"\n**INVALID**";
break;
}
}
getch();
}
Output:
Enter details
Name of the depositer: GAUTAM
Account No. : 4546
Type of the account (saving/current): saving
Balance amount in the account : Rs 60000
Password: xyz
1. Deposit
2.Withdraw
3.Display
4. Exit
Enter your choice: 1
Amount to be deposited: Rs 8000
Your current balance is: Rs 68000
1. Deposit
2.Withdraw
3.Display
4. Exit
Enter your choice: 2
Enter password: xyz
Amount to be withdrawn: Rs 56000
Your current balance is: Rs 12000
1. Deposit
2.Withdraw
3.Display
4. Exit
Enter your choice: