From Classes and Methods chapter in PU/ Object Oriented Programming in C++
Asked by Yogesh thapa on 11 Apr, 2020
1
993 Views
Using a class write a program that receives inputs principle amount, time and rate. Keeping rate 8% as the default argument, calculate the simple interest for three customers.
#include <iostream>
using namepsace std;
class Interest{
public:
void calculate(float p, float t, float r = 8){
cout << "\nThe interest is: "<< (p*t*r/100)<< ".\n" ;
}
};
main(){
Interest interest ;
cout << "\nFor p = 5000, t = 2.5 years, r = 14%:" ;
interest.calculate(500, 2.5, 14);
cout << "\nFor p = 5000, t = 2.5 years, r = 8%:" ;
interest.calculate(500, 2.5, 8);
cout << "\nFor p = 5000, t = 2.5 years, r = 8%:" ;
interest.calculate(500, 2.5);
}
Add your answer