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++]
Int rollno, age;
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;
Void main ()
Student obj ;
Int I, n;
Cout<<”How many student?”;
Cout<<”\n enter the information:”;
For (i=0; i<n;i++)
Obj [I].disinfo ();
- C++ Object Initialization Dynamic initialization of objects in c++ The dynamic initialization means...
- Class In C++ Class in c++ Class is a group of similar object....
- Object oriented programming Object oriented programming : The main idea behind object oriented...
- Defining Member Function In C++ Class methods definitions (Defining the member functions) Member functions can...
- Constructor in C++ Constructor in C++ Constructor is a member function with the...