KPIT Interview question
// superclass cashwidhawal, 2 derived class savingaccount and currentaccount, user can withdraw 10k from saving accoun, if more than that throw you are not eligible
// if user is withdraw from current account you are not authorized
#include <iostream>
using namespace std;
const int CASH_LIMIT = 50000;
class Cashwithdrawal
{
protected:
double value;
public:
virtual void func(double amount) = 0;
virtual void get() = 0;
};
class SavingAccount: public Cashwithdrawal
{
public:
SavingAccount(double value)
{
if(value >= CASH_LIMIT)
{
value = CASH_LIMIT; // cash limit
}
}
void get()
{
cout << value <<endl;
}
void func(double amount)
{
if(amount <= 10000.0)
{
value = value - amount;
}
else
{
cout << "You are not eligible to withdraw beyond 10k" <<endl;
}
}
};
class CurrentAccount: public Cashwithdrawal
{
public:
void func(double amount)
{
cout << "You are not authorize to withdraw from CurrentAccount" <<endl;
}
void get()
{
cout << "get balance isn't avialable feature"<<endl;
}
};
int main()
{
char bal;
char x;
cout << "You want to access using SavingAccount(s) or CurrentAccount(c):";
cin >> x;
double amt;
cout << "Enter the amount:";
cin >> amt;
if(x == 's')
{
Cashwithdrawal *s = new SavingAccount;
s->func(amt);
cout << "Do you want to see the balance?(Y/N)";
cin >> bal;
if(bal == 'Y')
{
s->get();
}
}
else if(x == 'c')
{
Cashwithdrawal *c = new CurrentAccount;
c->func(amt);
}
return 0;
}
Comments
Post a Comment