Simple Interest | Simple Interest Program in C++

Simple Interest

Simple interest is the simple and easiest way to calculate interest charge on a loan. This type of interest usually applies to short-term loans.
There are three values involved in simple interest, Principal, Rate and Time.

Here we have the formula to calculate Simple Interest.

Simple Interest formula = (Principle * Time * Rate)/100


Simple Interest program using C++ 

#include<iostream>
#include<cmath>
using namespace std;
 class InterestRate
{
protected:
float interest,rate,principal,time;
int n;
public:
InterestRate(float p,float r, float t,float no=0)
{
principal=p;
rate=r;
time=t;
n=no;
}
virtual void calculateInterest()
{}
};
 class SimpleInterest:public InterestRate
{
public:
SimpleInterest(float p,float r, float t):InterestRate(p,r,t)
{}
void calculateInterest()
{
interest = principal*time*rate/100;
cout<<“Simple interest: “<<interest<<endl;
}};
 class CompoundInterest:public InterestRate
{
public:
CompoundInterest(float p,float r, float t,int n):InterestRate(p,r,t,n)
{}
void calculateInterest()
{interest = principal*(pow(1+rate/100/n,n*time)-1);
cout<<“Compound interest : “<<interest<<endl;
}};
 int main()
{InterestRate *i1;
SimpleInterest s1(2000,5,2);
i1=&s1;
i1->calculateInterest();
CompoundInterest c1(1000,5,2,4);
i1=&c1;
i1->calculateInterest();
return 0;
}

OUTPUT:
Simple interest: 200
Compound interest: 104.486



You must be also searching for these programming languages :


tags : c programs , c++ programs, programs of c++ , simple interest , simple interest formula, c programs for beginners.

Post a Comment

Previous Post Next Post