Write a function to calculate interest based on principle nu
Write a function to calculate interest, based on principle, number of years, and interest rate. Specifically, the calculation of the simple interest is on a principal amount of 10,000 for duration of 5 years with the rate of interest equal to 12.5%. As a clue, here is the formula for simple interest: simple_interest = principle*time*rate_of_interest
Solution
#include<iostream>
using namespace std;
class simpleInterest
{
private:
int principle;
float rate;
int years;
public:
simpleInterest(int p,float r,int y)
{
principle=p;
rate=r;
years=y;
}
float calculate_Interest()
{
float simple_interest=principle*(float)rate*years;
return simple_interest;
}
};
int main()
{
simpleInterest ob(10000,12.5,5);
float interest=ob.calculate_Interest();
cout<<\"Simple Interest : \"<<interest;
return 0;
}
