Default argument c++

From Classes and Methods chapter in PU/ Object Oriented Programming in C++

Asked by Yogesh thapa on 11 Apr, 2020

Like 1 Dislike 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.

Add a comment

1 Answers

arjun adhikari on 24 Jul, 2020 Like 0 Dislike

#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 a comment


Add your answer