It is possible to create array of objects of a class. Though class is a user defined data type it behaves like built in data type.
Syntax for creating array of objects is as follows
class name(data type) array name[size];
e.g. staff arr;
here staff is the name of the class, arr is the name of array and 10 is the size of array.
Below is the program which creates an array of objects with member variables staff name and department. Program ask user to enter the department name to find out the staff belongs to that particular department.
Please include iostream.h, conio.h and string.h header files before declaration of class.
//PROGRAM TO FIND STAFF OF PERTICULAR DEPARTMENT FROM GROUP OF STAFF.
void display(char * s)
class staff arr;
cout<<"Enter name and department for 10 staff members\n";
cout<<"\nYou can enter department names as co(computer), ej(electronics), me(mechanical), ee(electrical)\n";
cout<<"\nEnter the name of department of staff to be found\n";
cout<<"\nDetails of employees having department as "< for(i=0;i<10;i++)