Menu

Custom Search

C++ lab program

/*modify above problem to include a destructor using appropriate output messages. discuss the effect of execution of program.*/
#include
#include
class test
{
int x,y;
public:
test()
{ x=0;
y=0;
cout<<"Default constructor:"<
}
test(int a,int b)
{ x=a;
y=b;
cout<<"Parameterized constructor:"<
}
void show();
~test()
{ cout<<"object destroy with value:"< cout<<"X="< cout<<"Y="< }
};
void main()
{
clrscr();
test t1;
test t2(1,1);
t1.show();
t2.show();
getch();
}

void test::show()
{
cout<<"X="< cout<<"Y="< cout<<"X*Y="< }
/*
message:
//in compilation there is no show of destructor because object is still
//running and after pressing alt+F5 we observe the output of destructor
//i.e after we once move to our code ie after '}'of main() */

No comments:

Post a Comment