c++ to display the values we are passing from parameterised constructor.
//To display the values of parameterised constructor.
#include<iostream>
using namespace std;
class add
{
int num1,num2,sum;
public :
add(int x,int y);
void display();
};
add::add(int x,int y)
{
num1=x;
num2=y;
sum=x+y;
}
void add::display()
{
cout<<"The nummbers are "<<num1<<"\t"<<num2<<"\n";
}
int main()
{
add b=add(10,20);
b.display();
}
#include<iostream>
using namespace std;
class add
{
int num1,num2,sum;
public :
add(int x,int y);
void display();
};
add::add(int x,int y)
{
num1=x;
num2=y;
sum=x+y;
}
void add::display()
{
cout<<"The nummbers are "<<num1<<"\t"<<num2<<"\n";
}
int main()
{
add b=add(10,20);
b.display();
}
OUT-The numbers are 10 20
Comments
Post a Comment