Answer to Question #174881 in C++ for Kaviyan P

Question #174881

Declare a class Fixed_Deposit with member variables are principal, rate and time, and member functions are MaturityAmount() to calculate the compound interest and maturity amount, and display() to print the total maturity amount(principal+compound interest)


1
Expert's answer
2021-03-26T19:18:35-0400
#include <iostream>
#include <iomanip>
using namespace std;

class Fixed_Deposit {
    double principal;
    double rate;
    int time;
public:
    Fixed_Deposit(double p, double r, int t);
    double MaturityAmount() const;
    void display(ostream& os) const;    
};

Fixed_Deposit::Fixed_Deposit(double p, double r, int t) :
    principal(p), rate(r), time(t) {}

double Fixed_Deposit::MaturityAmount() const
{
    double result = principal;
    for (int i=0; i<time; i++) {
        result *= (1 + rate/100);
    }

    return result;
}

void Fixed_Deposit::display(ostream& os) const
{
    os << "Maturity amount is " << fixed << setprecision(2) 
       << MaturityAmount();
} 

int main() {
    double pr, r;
    int t;

    cout << "Principal, rate, time ";
    cin >> pr >> r >> t;
    Fixed_Deposit fd(pr, r, t);
    fd.display(cout);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS