HOME

Thursday, October 15, 2015

EXAMPLE FOR PARAMETERIZED CONSTRUCTOR

#include<iostream>
using namespace std;
class sample
{
int p,t,r;
public:
    sample(int x, int y, int z)
    {
        p=x;
        t=y;
        r=z;
    }
    void calculate()
    {
    int result=(p*t*r)/100;
    cout<<"The simple interest is "<<result<<endl;
    }
};
int main()
{
sample s1(500,5,2); //parameterized constructor
s1.calculate();
sample s2(300,6,4);
s2.calculate();
sample s3(s1); //copy of constructor is done
s3.calculate(); //it will print same value as object of s1
return 0;
}

No comments:

Post a Comment