Search This Blog

Friday, 21 August 2020

Construction call by arguments

 #include<iostream>

#include<conio.h>

using namespace std;

class test

{

int a,b;

public:

test();                     //default constructoe

test(int x);                 //constructi0on with one argument

test(int x,int y);           //construction with 2 arguments

void disp();                  //member function of display the all of this data

};

test::test()

{

a=0;

b-0;

}

test::test(int x)

{

a=b=x;

}

test::test(int x,int y)

{

a=x;

b=y;

}

void test::disp()                    //function define

{

cout<<"\nValue of A : "<<a;

cout<<"\nValue of B : "<<b;

}

int main()

{

int a;

int b;

cout<<"\nEnter the values of a & b:\n";

cin>>a>>b;

test A;              //efault constructor call

test B(a);         //constructor call of one argument

test C(a,b);      //construction call of two arguments

cout<<"\n\nObject A:\n";

A.disp();

cout<<"\n\nObject B:\n";

B.disp();

cout<<"\n\nObject C:\n";

C.disp();

getch();

return 0;

}



No comments:

Post a Comment

Search This Blog

Contact Form

Name

Email *

Message *

Popular Posts