Array Of Class Object

Array of class objects

Array is a collection of similar type of data’s that are referenced by a common name. Similarly, array of class objects means a collection of similar type of objects referenced by a common name. Hence, an array having class type element is known as array of object. The syntax for defining the array of class objects is as follows:-

Class_name object_name [size];

Where, size is a size of the array of class objects.

E.g. A  program to input ‘n’ student’s information such as roll o, age, sex, height and weight and display the data at the end.

[Note: Here, class student is defined as an array of class objects. This program shows how to create an array of class objects and how to access these data member and member functions in c++]

Class student
Int rollno, age;
Char sex;
Float weight, height;
Void get info ()
Cout<<”\n Enter roll number”;
Cout<<”\n Enter age”;
Cout<<”\n enter sex”;
Cout<<”\n enter weight”;
Cout<<”\n enter height”;
Void disinfo ()
Cout<<”\n roll no=”<<rollno;
Cout<<”\n Age=”<<age;
Cout<<”\n sex=”<<sex;
Cout<<”\n height=”<<height;
Cout<<”n weight=”<<weight;
Void main ()
Student obj [100];
Int I, n;
Cout<<”How many student?”;
Cout<<”\n enter the information:”;
For (i=0; i<n;i++)
Obj [I].disinfo ();
getch ();

Related posts:

  1. C++ Object Initialization Dynamic initialization of objects in c++ The dynamic initialization means...
  2. Class In C++ Class in c++ Class is a group of similar object....
  3. Object oriented programming Object oriented programming : The main idea behind object oriented...
  4. Defining Member Function In C++ Class methods definitions  (Defining the member functions) Member functions can...
  5. Constructor in C++ Constructor in C++ Constructor is a member function with the...