Array of Object in C++ with example



An array is the user define data type whose members are homogeneous and stored in contiguous memory location. Array is used to design large size database.

Example:
 #include<iostream.h>
# include<conio.h>
class complex
{
private:
int r,i;
public:
void get();
void put();           
};
void complex :: get()
{
cout<<”Enter the Info = ”;
cin>>r;    
}
void complex :: put()
{
               cout<<”Your number is = ”;
               cout<<r<<”+”<<i<<”i”;
}
void main()
{
int i;
complex c[3];
clrscr();
for(i=0; i<=2; i++)
{
c[i].get();
c[i].put();
}
getch();
}

No comments:

Post a Comment