//Program : Part B-1
//Create a class Bank which include data members-Acno, Name, Balance and //parameterized constructor to initialize the data members and other methods like //deposit, withdrawal, and display the detail of the customer. (Hint : Minimum //balance of Rs.500/- should be maintained and the amount should be positive.)
//Name : LDK E-NOTES Reg.No. : **********
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdlib.h>
#include<string.h>
class bank
{
int acno;
char name[20];
float bal;
public:
bank(int a,char n[20],float b);
void deposit();
void withdraw();
void display();
};
bank::bank(int a,char n[20],float b)
{
acno=a;
strcpy(name,n);
bal=b;
}
void bank::deposit()
{
float dep;
cout<<"Enter the amount to be deposited : ";
cin>>dep;
bal=bal+dep;
cout<<"Current balance = "<<bal;
}
void bank::withdraw()
{
float draw;
cout<<"Enter the amount to be withdrawn : ";
cin>>draw;
if((bal-draw)<500)
{
cout<<"Insufficient balance...";
}
else
{
bal=bal-draw;
cout<<"Current balance = "<<bal;
}
}
void bank::display()
{
cout<<"\nAccount number = "<<acno;
cout<<"\nName = "<<name;
cout<<"\nBalance = "<<bal;
}
void main()
{
bank b(101,"Anand",600);
int ch=0;
clrscr();
while(ch<4)
{
cout<<endl<<"1.Deposit"<<endl;
cout<<"2.Withdraw"<<endl;
cout<<"3.Dispaly"<<endl;
cout<<"4.Exit"<<endl;
cout<<"Enter your choice [1/2/3/4] : ";
cin>>ch;
switch(ch)
{
case 1 : b.deposit();
break;
case 2 : b.withdraw();
break;
case 3 : b.display();
break;
case 4 : exit(0);
break;
default : cout<<"\nInvalid choice...";
}
getch();
}
}
Output :
1.Deposit
2.Withdraw
3.Dispaly
4.Exit
Enter your choice [1/2/3/4] : 1
Enter the amount to be deposited : 5000
Current balance = 5600
1.Deposit
2.Withdraw
3.Dispaly
4.Exit
Enter your choice [1/2/3/4] : 2
Enter the amount to be withdrawn : 5300
Insufficient balance...
1.Deposit
2.Withdraw
3.Dispaly
4.Exit
Enter your choice [1/2/3/4] : 2
Enter the amount to be withdrawn : 4700
Current balance = 900
1.Deposit
2.Withdraw
3.Dispaly
4.Exit
Enter your choice [1/2/3/4] : 3
Account number = 101
Name = Anand
Balance = 900
No comments:
Post a Comment