PROGRAM:
//BANK TRANSACTION
#include<iostream.h>
#include<conio.h>
#include<string.h>
class bank //declaring class
{
public:
long int accno,bal,dep,witdr; //declaring varirables
char name[50];
public:
bank(long int x,char c[50],long int y) //parameterized constructor
{
accno=x; //assigning parameters to data members
bal=y;
strcpy(name,c);
}
void deposit() //deposit function
{
cout<<"\nEnter the amount you wish to deposit"; //getting the amount to be deposited
cin>>dep;
bal=bal+dep;
display(); //invoking the display function
}
void withdraw() //withdraw function
{
cout<<"\nEnter the amount you wish to withdraw"; //getting the amount to withdraw
cin>>witdr;
if(bal>witdr) //checking balance
{
bal=bal-witdr;
display(); //invoking display function
}
else
{
cout<<"\nINSUFFICIENT BALANCE";
display();
}
}
void transfer(bank &t1,int amt) //transfer function
{
bal=bal-amt;
t1.bal=t1.bal+amt;
display(); //calling display fuction for object
t1.display(); //calling display function for other object }
void display()
{
cout<<"\n\nACCOUNT\t:\t"<<accno; //display function definition
cout<<"\n\nNAME\t:\t"<<name;
cout<<"\n\nBALANCE\t:\t"<<bal;
}
};
int main()
{
clrscr();
char nam1[50],nam2[50]; //variable declaration
long int inbal1,inbal2,amount,ch;
cout<<"************WELCOME TO***********";
cout<<"\n**************SKCET BANK***************\n";
cout<<"\n1.Enter the details for user 1"; //getting details of user 1(mandatory)
cout<<"\nEnter your name\t:\t";
cin>>nam1;
cout<<"\nEnter your initial balance\t:\t"; //getting details of user2(mandatory)
cin>>inbal1;
bank s1(1000,nam1,inbal1);
cout<<"\nEnter the details for user 2";
cout<<"\nEnter your name\t:\t";
cin>>nam2;
cout<<"\nEnter your initial balance\t:\t";
cin>>inbal2;
bank s2(1001,nam2,inbal2);
do
{ //implementing menu driven manner
cout<<"\n1.DEPOSIT AMOUNT\n2.WITHDRAW AMOUNT\n3.TRANSFER AMOUNT\n4.VIEW BALANCE DETAILS\n5.EXIT\n";
cin>>ch;
switch (ch)
{
case 1:
{
int cho;
cout<<"\n1.DEPOSIT AMOUNT IN "<<s1.name<<"'s ACCOUNT"<<"\n2.DEPOSIT AMOUNT IN "<<s2.name<<"'s ACCOUNT\n";
cin>>cho;
switch (cho)
{
case 1:
{
s1.deposit(); //calling deposit function for object 1
break;
}
case 2:
{
s2.deposit(); //calling deposit function for object 2
break;
}
}
break;
}
case 2:
{
int cho;
cout<<"\n1.WITHDRAW AMOUNT FROM "<<s1.name<<"'s ACCOUNT"<<"\n2.WITHDRAW AMOUNT FROM "<<s2.name<<"'s ACCOUNT\n";
cin>>cho;
switch(cho)
{
case 1:
{
s1.withdraw(); //calling withdraw function for object 1
break;
}
case 2:
{
s2.withdraw(); //calling withdraw function for object 2
break;
}
}
break;
}
case 3:
{
int cho;
cout<<"\n1.TRANSFER AMOUNT FROM "<<s1.name<<"'s ACCOUNT TO "<<s2.name<<"'s ACCOUNT \n";
cout<<"\n2.TRANSFER AMOUNT FROM "<<s2.name<<"'s ACCOUNT TO "<<s1.name<<"'s ACCOUNT \n";
cin>>cho;
switch (cho)
{
case 1:
{
cout<<"\nEnter the amount you wish to transfer\t:\t";
cin>>amount;
s1.transfer(s2,amount); //calling transfer function of object 1
break;
}
case 2: //implemented using object as parameters
{
cout<<"\nEnter the amount you wish to transfer\t:\t";
cin>>amount;
s2.transfer(s1,amount); //calling transfer function for object 2
break;
}
}
break;
}
case 4:
{
int cho;
cout<<"\n1.DISPLAY THE DETAILS OF "<<s1.name<<"'s ACCOUNT\n";
cout<<"\n2.DISPLAY THE DETAILS OF "<<s2.name<<"'s ACCOUNT\n";
cout<<"\n3.DISPLAY BOTH THE ACCOUNTS\n";
cin>>cho;
switch (cho)
{
case 1:
{
s1.display(); //calling display function for object 1
break;
}
case 2:
{
s2.display(); //calling display function for object 2
break;
}
case 3:
{
s1.display(); //calling display function for object 1,2
s2.display();
break;
}
}
break;
}
}
}while(ch<5);
cout<<"**********THANK YOU***********";
return 0;
}
OUTPUT:
************WELCOME TO***********
**************SKCET BANK***************
1.Enter the details for user 1
Enter your name : HARRY
Enter your initial balance : 15000
Enter the details for user 2
Enter your name : RON
Enter your initial balance : 18000
1.DEPOSIT AMOUNT
2.WITHDRAW AMOUNT
3.TRANSFER AMOUNT
4.VIEW BALANCE DETAILS
5.EXIT
1
1.DEPOSIT AMOUNT IN HARRY's ACCOUNT
2.DEPOSIT AMOUNT IN RON's ACCOUNT
1
Enter the amount you wish to deposit3000
ACCOUNT : 1000
NAME : HARRY
BALANCE : 18000
1.DEPOSIT AMOUNT
2.WITHDRAW AMOUNT
3.TRANSFER AMOUNT
4.VIEW BALANCE DETAILS
5.EXIT
1
1.DEPOSIT AMOUNT IN HARRY's ACCOUNT
2.DEPOSIT AMOUNT IN RON's ACCOUNT
2
Enter the amount you wish to deposit2000
ACCOUNT : 1001
NAME : RON
BALANCE : 20000
1.DEPOSIT AMOUNT
2.WITHDRAW AMOUNT
3.TRANSFER AMOUNT
4.VIEW BALANCE DETAILS
5.EXIT
2
1.WITHDRAW AMOUNT FROM HARRY's ACCOUNT
2.WITHDRAW AMOUNT FROM RON's ACCOUNT1
Enter the amount you wish to withdraw2000
ACCOUNT : 1000
NAME : HARRY
BALANCE : 16000
1.DEPOSIT AMOUNT
2.WITHDRAW AMOUNT
3.TRANSFER AMOUNT
4.VIEW BALANCE DETAILS
5.EXIT
2
1.WITHDRAW AMOUNT FROM HARRY's ACCOUNT
2.WITHDRAW AMOUNT FROM RON's ACCOUNT
2
Enter the amount you wish to withdraw1700
ACCOUNT : 1001
NAME : RON
BALANCE : 18300
1.DEPOSIT AMOUNT
2.WITHDRAW AMOUNT
3.TRANSFER AMOUNT
4.VIEW BALANCE DETAILS
5.EXIT
3
1.TRANSFER AMOUNT FROM HARRY's ACCOUNT TO RON's ACCOUNT
2.TRANSFER AMOUNT FROM RON's ACCOUNT TO HARRY's ACCOUNT
1
Enter the amount you wish to transfer : 3020
ACCOUNT : 1000
NAME : HARRY
BALANCE : 12980
ACCOUNT : 1001
NAME : RON
BALANCE : 21320
1.DEPOSIT AMOUNT
2.WITHDRAW AMOUNT
3.TRANSFER AMOUNT
4.VIEW BALANCE DETAILS
5.EXIT
3
1.TRANSFER AMOUNT FROM HARRY's ACCOUNT TO RON's ACCOUNT
1.TRANSFER AMOUNT FROM RON's ACCOUNT TO HARRY's ACCOUNT
2
Enter the amount you wish to transfer :5000
BALANCE : 16320
ACCOUNT : 1000
NAME : HARRY
BALANCE : 17980
1.DEPOSIT AMOUNT
2.WITHDRAW AMOUNT
3.TRANSFER AMOUNT
4.VIEW BALANCE DETAILS
5.EXIT
4
1.DISPLAY THE DETAILS OF HARRY's ACCOUNT
2.DISPLAY THE DETAILS OF RON's ACCOUNT
3.DISPLAY BOTH THE ACCOUNTS
1
ACCOUNT : 1000
NAME : HARRY
BALANCE : 17980
1.DEPOSIT AMOUNT
2.WITHDRAW AMOUNT
3.TRANSFER AMOUNT
4.VIEW BALANCE DETAILS
5.EXIT
4
ACCOUNT : 1000
NAME : HARRY
BALANCE : 17980
1.DEPOSIT AMOUNT
2.WITHDRAW AMOUNT
3.TRANSFER AMOUNT
4.VIEW BALANCE DETAILS
5.EXIT
4
1.DISPLAY THE DETAILS OF HARRY's ACCOUNT
2.DISPLAY THE DETAILS OF RON's ACCOUNT
3.DISPLAY BOTH THE ACCOUNTS
2
ACCOUNT : 1001
NAME : RON
BALANCE : 16320
1.DEPOSIT AMOUNT
2.WITHDRAW AMOUNT
3.TRANSFER AMOUNT
4.VIEW BALANCE DETAILS
5.EXIT
4
1.DISPLAY THE DETAILS OF HARRY's ACCOUNT
2.DISPLAY THE DETAILS OF RON's ACCOUNT
3.DISPLAY BOTH THE ACCOUNTS
3
ACCOUNT : 1000
NAME : HARRY
BALANCE : 17980
ACCOUNT : 1001
NAME : RON
BALANCE : 16320
1.DEPOSIT AMOUNT
2.WITHDRAW AMOUNT
3.TRANSFER AMOUNT
4.VIEW BALANCE DETAILS
5.EXIT
5
No comments:
Post a Comment