### Inheritance CI/SI/fixedDeposit

Question :
Consider a Base class as defined below:
class fixDeposit {
protected int accno; // account number
protected double amount; // principal amount

public fixDeposit(int a, double p) {accno = a; amount = p;}
public double interest() { cout<<“The memberfunction in fixDeposit”) ; return 0;}
public void update(double d) { amount += d; }
public void display() { cout<<“The memberfunction in fixDeposit”); }
}
Drive classes (from base class fixDeposit) (i) SIdeposit, and (ii) CIdeposit for accounts earning Simple Interest (SI), and Compound Interest (CI) respectively on the principal amount. Besides inherited members, each derived should have additional data members for (i) yearly rate of interest, and (ii) time period of deposit in number of years. Define following methods for each child/derived class:
(a) Constructors for the derived classes, explicitly calling base class constructors
(b) The method ‘interest’ which overrides the method ‘interest’ of the base class, calculates and returns simple/compound interest
(c) The function ‘display’ which overrides the method ‘display’ of the base class, updates the principal amount by adding interest and then displays the final amount
Write a test driver class and explain how the polymorphic feature in C++ is implemented in the above.

Doubt : Getting 0 interest

Code :
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657`` ``````#include #include using namespace std; class fixDeposit { protected : int accno; double amount; public: fixDeposit(int a, double p) {accno = a; amount = p;} double interest() {cout<<"The memberfunction in fixDeposit";} void update(double d) { amount = amount+ d; } void display(){cout<<"The memberfunction in fixDeposit";} }; class SIdeposit : public fixDeposit { protected: double roi; int timePeriod; public: SIdeposit(int ac, int am, int r, int t): fixDeposit(ac,am) { roi = r; timePeriod = t; } double interest(){double SI; SI = (amount*roi*timePeriod)/(100); return SI; } void display(){double inte =interest(); update(inte) ; cout<
Last edited on
line 27, 41 - shouldn't `r` be a double?
Yes, you are right. Thanks
Topic archived. No new replies allowed.