Question: Lab: Inheritance Extend your Account class using inheritance of class from Lab 4 for simplicity --- class accountFX: public account Methods setExchangeRate(int rate) convertMOPtoRMB(int amountInMOP)
Lab: Inheritance
Extend your Account class using inheritance of class from Lab 4 for simplicity
---
class accountFX: public account
Methods
setExchangeRate(int rate)
convertMOPtoRMB(int amountInMOP)
exchangeRMBtoMOP(int amountInRMB)
Data members
RMB
exchangeRate, e.g. exchangeRate=1.25 (default value 1.25 in default constructor)
---
class accountSecurity: public account
/* Assuming there is no transaction fee (no bid-ask spread either) */
Methods
setHSBCpricePerShare(int price)
buyHSBC(int numberShares)
sellHSBC(int numberShares)
Data members
pricePerShare (default value MOP400 in default constructor)
numberSharesHSBC?
lab4:
#include
using namespace std;
class Account{
public:
//Constructor
Account(){ balance = interestRate = 0.0; term = 0;}
Account(double b, double r, int t){
balance = b;
interestRate = r;
term = t;
}
//Accessor
double getBalance() { return balance; }
double getInterestRate() { return interestRate;}
int getTerm() { return term;}
//Mutator
void Deposit(double amount){
balance += amount;
}
int WithDraw(double amount){
if (amount > balance) return -1;
else {
balance -= amount;
return 1;
}
}
void AdjustRate(double newRate){
interestRate = newRate;
}
void SetTerm(int newTerm){
term = newTerm;
}
void CalBalanceMaturity(){
double s = balance + balance * interestRate/100 * term/12;
cout << "After the term of " << term << "months" << endl;
cout << "Your account will have a balance (Maturity) of MOP " << s << endl;
}
private:
double balance;
double balanceMaturity;
double interestRate;
int term;
};
int main(){
Account a;
cout << "-----Operations on Henry's Account----- " << endl;
cout << "Your account has MOP " << a.getBalance() << endl;
cout << "The current interest rate is " << a.getInterestRate() << endl;
cout << "The deposit term is " << a.getTerm() << endl;
a.CalBalanceMaturity();
a.Deposit(5000);
a.AdjustRate(1.5);
a.SetTerm(6);
cout << "Your account has MOP " << a.getBalance() << endl;
cout << "The current interest rate is " << a.getInterestRate() << endl;
cout << "The deposit term is " << a.getTerm() << endl;
a.CalBalanceMaturity();
cout << "-----End of Operations on Henry's Account----- " << endl;
Account b(10000, 3, 18);
cout << "-----Operations on Raymond's Account----- " << endl;
cout << "Your account has MOP " << b.getBalance() << endl;
cout << "The current interest rate is " << b.getInterestRate() << endl;
cout << "The deposit term is " << b.getTerm() << endl;
b.CalBalanceMaturity();
b.WithDraw(2000);
b.AdjustRate(3);
b.SetTerm(18);
cout << "Your account has MOP " << b.getBalance() << endl;
cout << "The current interest rate is " << b.getInterestRate() << endl;
cout << "The deposit term is " << b.getTerm() << endl;
b.CalBalanceMaturity();
cout << "-----End of Operations on Raymond's Account----- " << endl;
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
