Write a program that will demonstrate
parameterized constructor function. The program that uses the following
properties – class names- test; two integer type private member variables- e,f;
one parameterized constructor function test(int m, int n); one public member
function add_display(). Constructor function test(int m, int n) get the value
from parameterized object xx(6,7) and assigns the values for e, f; add_output()
member function do the addition for e, f and displays the result as output.
#include<iostream>
using namespace std;
class test
{
int e,f;
public:
test(int m,int n);
void add_display();
};
test::test(int m,int n)
{
e=m;
f=n;
}
void test::add_display()
{
cout<<"Addition
is : "<<e+f<<endl;
}
int main()
{
test xx(6,7);
xx.add_display();
return 0;
}
No comments:
Post a Comment