Thursday, 19 January 2012

Program Of Array of Constructor Parameter In C++


#include<iostream.h>
#include<conio.h>
class add
{
private:
int x,y;           // Data Member
public:
add(int p,int q)   // Default Parameter Constructor
{
x=p;
y=q;
}
void display()
{
int r;
r=x+y;
cout<<"\n NAswer="<<r;
}


};
main()
{
clrscr();
int i;
add a[3]={add(2,4),add(5,7),add(9,10)};
for(i=0;i<3;i++)
{
a[i].display();
}
getch();
}

------------------------------------------------------------------------------------

  In this section we consider the Array<T> class constructor which takes two numeric arguments of type unsigned int. The definition of this constructor is given in Program gif. Given argument values m and n, the constructor first allocates an array of n elements of type T using operator new, and then sets the length field to n and the base field to m. The running time is a constant plus the time do the array allocation.

No comments:

Post a Comment