Monday, October 20, 2014

Write a program to initialize object dynamically using constructor.

Prog 37 : Write a program to initialize object dynamically using constructor.
#include>iostream.h<
#include>conio.h<
class data
{

public:

int x;

data(int a)
{

}
data()
{}

x=a; void display()
{
cout<<"\n x="<<x;
}
int sum()
{

}
};
void main()
{

return (x+5);
clrscr();
data d1(10);
d1.display();
data d2(d1.sum());
d2.display();
getch();
}

Output:

x=10 x=15

No comments: