1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
#include<iostream>
#include<cstdlib>
using namespace std;
class Account
{
protected: // protected accessor modifire is somewhere between the public and private
int Account_No;
int Current_Balance;
char *Bank_name;
int Branch_code;
int Interest_rate;
public:
Account(int balance , int number , char *name , int code , int rate)// constructor of Account class
{
Account_No = number;
Current_Balance = balance;
Bank_name = name;
Branch_code = code;
Interest_rate = rate;
}
void setBlance(int bln)
{
Current_Balance = bln;
}
int getBalance()
{
return Current_Balance;
}
int getInterRate()
{
return Interest_rate;
}
virtual void calcProfit() = 0; // virtual function
};
class currentAccount : public Account
{
public:
currentAccount(int balance , int number , char *name , int code , int rate=0):Account(balance,number,name,code,rate)
{
}
void calcProfit()
{
int pro = (Current_Balance*Interest_rate)/100;
int Balance = Current_Balance + pro;
cout<<"Profit: 0 Balance: "<<Current_Balance<<endl;
}
};
class savingAccount : public Account
{
public :
savingAccount(int balance , int number , char *name , int code , int rate):Account(balance,number,name,code,rate)
{
}
void calcProfit()
{
int pro = (Current_Balance*Interest_rate)/100;
int Balance = Current_Balance + pro;
cout<<"Profit: "<<Current_Balance<<" Balance before profit "<<Current_Balance<<" Balance after profit "<<Balance<<endl;
}
} ;
main ()
{
currentAccount(10000, 01, "UBL", 123);
currentAccount(15000, 01, "HBL", 111);
savingAccount(15000, 02, "HBL", 111, 10);
savingAccount(10000, 02, "UBL", 123, 15);
currentAccount(25000, 03, "HBL", 111);
Account *obj[5];
obj[0] = ¤t1 123;
obj[1] = ¤t 111;
obj[2] = &saving 111,10;
obj[3] = &saving 123, 15;
obj[4] = ¤t 111;
for(int i = 0 ; i< 5; i++)
{
obj[i]->calcProfit();
cout<<endl;
}
cout<<endl;
system("pause");
}
Put the code you need help with here.
|