
// Program to illustrate constructor overloading
#include<iostream.h>
class sample
{
     private:
          float p,n,r,i;
     public:
     sample(float x,float y)
     {
          p=x;
          n=y;
          r=12.5;
     }
     sample(float x,float y,float z)
     {
          p=x;
          n=y;
          r=z;
     }
     float calculate()
     {
          i=p*n*r/100.0;
          return i;
     }
     void display()
     {
          cout<<"\n Interest amount :"<<i;
     }
};
void main()
{
     sample obj1(15000.0,5.0);
     obj1.calculate();
     cout<<"\n Interest amount using two arguments ";
     obj1.display();
     sample obj2(15000.0,5.0,15.0);
     obj2.calculate();
     cout<<"\n Interest amount using three arguments ";
     obj2.display();
}
Test data
Interest amount using two arguments
Interest amount : 9375
Interest amount using three arguments
Interest amount : 11250