Goldman Sachs Interview Question
Analysts// code showing basic software design
class ATM; class ReceiptInfo;
class ATMImpl{
friend class ATM;
private:
ATMImpl(){/*implementation*/}
public:
float getBalanceInfo(){/*implementation*/}
ReceiptInfo getReceiptInfo(){/*implementation*/}
bool deposit(float val){/*implementation*/}
bool withdraw(float val){/*implementation*/}
bool verifyPIN(int pinVal){/*implementation*/}
~ATMImpl(){/*implementation*/}
};
class ATM{
private:
ATMImpl *d; //pointer to ATM implementation
public:
inline float getBalance(){return d->getBalance();}
inline ReceiptInfo getReceiptInfo(){return d->getReceiptInfo();}
inline bool deposit(float val){return d->deposit(val);}
inline bool withdraw(float val){return d->withdraw(val);}
inline bool verifyPIN(int pinVal){return d->verifyPIN(pinVal);}
};
class ATM_GUI{
private:
ATM atmObj;
public:
ATM_GUI(){/*initialize GUI*/}
void printReceipt(){atmObj.getReceiptInfo();/*more implementation*/}
void printBalance(){atmObj.getBalance();/*more implementation*/}
inline bool verifyPIN(int pinVal){atmObj.verifyPIN(pinVal);}
inline bool withdraw(float amount){atmObj.withdraw(amount);}//Atomic operation
inline bool deposit(float amount){atmObj.deposit(amount);}//Atomic operation
//more methods (operations)
};
#include<iostream.h>
#include<conio.h>
class BANK
{ private:
int acno;
char name[30];
long balance;
public:
void open_account()
{
cout<<"enter the account nomber";
cin>> acno;
cout<<"enter the name";
cin>>name;
cout<<"enter the balane";
cin>>balance;
}
void show_account()
{
cout<<acno<<","<<name<<","<<balance<<","<<endl;
}
void deposite()
{
long ammount;
cout<<"enter the ammount";
cin>>ammount;
balance=balance+ammount;
cout<<balance;
}
void withdrawal()
{
long ammount;
cout<<"enter the ammount";
cin>>ammount;
if(balance-ammount>=0)
{
balance=balance-ammount;
cout<<balance<<endl;
}
else
{
cout<<"less amount........."<<endl;
}
}
int search(int);
};
int BANK::search(int an)
{
if(acno==an)
{
show_account();
return(1);
}
return(0);
}
void main()
{
int a,found,an,i;
clrscr();
BANK c[5];
for(i=0;i<=4;i++)
{
c[i].open_account();
}
do
{
clrscr();
cout<<" display all account no."<<endl;
cout<<"1.desplay by account no."<<endl;
cout<<"2.desplay deposite ammount"<<endl;
cout<<"3.desplay withdrawal ammount"<<endl;
cout<<"4.exit "<<endl;
cout<<" enter or choice";
cin>>a;
switch(a)
{
case 1:
for(i=0;i<=4;i++)
{
c[i].show_account();
}
break;
case 2:
cout<<"enter the account no.";
cin>>an;
for(i=0;i<=4;i++)
{
found=c[i].search(an);
if(found)
{break;}
}
if(!found)
{
cout<<"invalid account .........."<<endl;
}
break;
case 3:
cout<<"enter account no.";
cin>>an;
for(i=0;i<=4;i++)
{
found=c[i].search(an);
if(found)
{
c[i].deposite();
break;
}
}
if(!found)
{
cout<<"invalid account no."<<endl;
}
break;
case 4:
cout<<"enter the account no.";
cin>>an;
for(i=0;i<=4;i++)
{
found=c[i].search(an);
if(found)
{
c[i].withdrawal();
break;
}
}
if(!found)
{
cout<<"invalid account no."<<endl;
}
break;
case 5:
break;
default:
cout<<"enter option..........."<<endl;
}
cout<<" press any to countinue........."<<endl;
cin>>a;
getch();
}
while(!a);
}
How about using state pattern
- Anonymous August 01, 2012