The following code :
===========================
#include<iostream.h>
#include<string.h>
#include<conio.h>
class Banking{
private:
int id;
char name[20];
float amount;
public:
Banking(){
id=0;strcpy(name,"Unknown");amount=0.00;
}
Banking(int i,char *n,float a){
id=i;strcpy(name,n);amount=a;
}
int getid(){return id;}
void input(){
cout<<"Input Id : ";cin>>id;
cout<<"Input Name : ";cin.clear();cin.seekg(0,ios::end);cin.get(name,20);
cout<<"Input Amount : ";cin>>amount;
}
void output(){
cout<<id<<"\t"<<name<<"\t"<<amount<<endl;
}
void deposit(float m){
amount+=m;
}
void withdraw(float m){
if(amount==0) cout<<"Sorry You can't Withdraw Money"<<endl;
else if(amount<=m) amount=0;
else amount-=m;
}
};
int search(Banking a[],int n, int id){
int index=-1;
for(int i=0;i<n;i++)
if(a[i].getid()==id){index=i;break;}
return index;
}
void main(){
int i,n,pos,id;
float m;
char ch;
do{
cout<<"Input Customer : ";cin>>n;
Banking *p=new Banking[n];
for(i=0;i<n;i++)
p[i].input();
cout<<"****************************"<<endl;
cout<<"All Customer Data"<<endl;
cout<<"ID"<<"\t"<<"Name"<<"\t"<<"Amount"<<endl;
for(i=0;i<n;i++)
p[i].output();
cout<<"****************************"<<endl;
cout<<"Input Position of customer's deposit:";cin>>id;
pos=search(p,n,id);
if(pos==-1) cout<<"Search Not Found"<<endl;
else{
cout<<"Input Deposit Money:";cin>>m;
p[pos].deposit(m);
}
cout<<"****************************"<<endl;
cout<<"Input Position of customer's withdraw:";cin>>id;
pos=search(p,n,id);
if(pos==-1) cout<<"Search Not Found"<<endl;
else{
cout<<"Input Withdraw Money:";cin>>m;
p[pos].withdraw(m);
}
cout<<"****************************"<<endl;
cout<<"All Customer Data"<<endl;
cout<<"ID"<<"\t"<<"Name"<<"\t"<<"Amount"<<endl;
for(i=0;i<n;i++)
p[i].output();
ch=getch();
}while(ch!=27);
}
0 comments:
Post a Comment