FIRST METHOD
#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
class bank
{
char name[10],type;
int acno;
float amt,dep,bal;
public:
void init();
void depo();
void with();
void disp();
};
void bank::init()
{
cout<<"Name::";
cin>>name;
cout<<"Enter s for savings or C for current account::";
cin>>type;
}
void bank::depo()
{
cout<<"Account no & amt to deposit::";
cin>>acno>>dep;
bal=0;
bal+=dep;
}
void bank::with()
{
cout<<"Amt to withdraw::";
cin>>amt;
if(amt>bal)
cout<<"Insufficient balance";
else
bal-=amt;
}
void bank::disp()
{
cout<<"Name::"<<name<<endl
<<"Balance::"<<bal<<endl;
}
void main()
{
clrscr();
bank b;
b.init();
b.depo();
b.with();
b.disp();
getch();
}
ANOTHER WAY TO SOLVE THE PROBLEM
#include<conio.h>#include<iostream.h>
#include<stdlib.h>
class bank
{
char name[10],type;
int acno;
float amt,dep,bal;
public:
void init();
void depo();
void with();
void disp();
};
void bank::init()
{
cout<<"Name::";
cin>>name;
cout<<"Enter s for savings or C for current account::";
cin>>type;
}
void bank::depo()
{
cout<<"Account no & amt to deposit::";
cin>>acno>>dep;
bal=0;
bal+dep;
}
void bank::with()
{
cout<<"Amt to withdraw::";
cin>>amt;
if(amt>bal)
cout<<"Insufficient balance";
else
bal-=amt;
}
void bank::disp()
{
cout<<"Name::"<<name<<endl
<<"Balance::"<<bal<<endl;
}
void main()
{
clrscr();
bank b[10];
int ch,i,j;
for(i=1;i<=2;i++)
{
b[i].init();
}
while(1)
{
cout<<"1 to deposit"<<endl
<<"2 to withdraw"<<endl
<<"3 to deposit"<<endl
<<"4 to Exit::";
cin>>ch;
if(ch==1||ch==2||ch==3)
{
cout<<endl<<"Which customer details do you want to enter or view::";
cin>>j;
}
else
exit(1);
getch();
switch(ch)
{
case 1:
b[j].depo();
break;
case 2:
b[j].with();
break;
case 3:
b[j].disp();
break;
case 4:
exit(1);
}
getch();
}
}

No comments:
Post a Comment