Friday, March 26, 2010

Basic OOPS concept Ques 4(Account)

#include iostream.h
#include conio.h
#include stdio.h

class account
{
private:
int accountno;
long balance_amount;
char name[25];
public:
void getdata();
int transaction(char,long,long&,long&);
int check_account(int);
void show_balance();
};

void account::getdata()
{
cout<<"Name: "; gets(name);
cout<<"Account no.: "; cin>>accountno;
cout<<"\nAccount Balance "; cin>>balance_amount;
cout<}

int account::transaction(char ans, long tran_amount,long &totwith, long &totdep)
{
int f=1;
if(ans=='w')
{
if(balance_amount-tran_amount<=100)
f=-1;
else
{
balance_amount-=tran_amount;
totwith+=tran_amount;
}
}
else if(ans=='d')
{
balance_amount+=tran_amount;
totdep+=tran_amount;
}
return(f);
}

int account::check_account(int accno)
{
int flag=0;
if(accountno==accno)
flag=1;
return(flag);
}

void account::show_balance()
{
cout<<"\nName: "; puts(name);
cout<<"Remaining Balance: "; cout<}

void main()
{
clrscr();
int accno, f, flag, k=-1;
long tran_amt, totalwith=0, totaldep=0;
char ans, ch;
account acc[2];

cout<<"Enter Details..\n";
for( int i=0; i<2; i++)
{
cout<<"Person "< acc[i].getdata();
}
cout<<"\nDo you want to make a transaction(y/n)? ";
cin>>ch;

while(ch=='y')
{
cout<<"Enter account no.: ";
cin>>accno;

for(i=0; i<2; i++)
{
flag=acc[i].check_account(accno);
if(flag==1)
{
k=i;
break;
}
}
if(flag==0)
{
cout<<"Account not found!!";
f=-1;
}
if(k!=-1 && k<2)
{
cout<<"\nWhat do you want to do??\n Withdrwal(w) or Deposit(d) ";
cin>>ans;

cout<<"\nEnter transaction amount: ";
cin>>tran_amt; cout<
f=acc[k].transaction(ans, tran_amt, totalwith, totaldep);
}

if(f==-1)
cout<<"\nTransaction Unsuccesful!!\a";
else
cout<<"\nTransaction Successful!!";

cout<<"\n\nDo you want to make another transaction(y/n)?? ";
cin>>ch;
}
for(i=0; i<2; i++)
acc[i].show_balance();

cout<<"\nTotal withdrawal: "< cout<<"\nTotal deposit: "< getch();
}

No comments:

Post a Comment