Array of Objects: Presented by Anusha Linda Kostka J E Assistant Professor Department of Computer Applications Niche
Array of Objects: Presented by Anusha Linda Kostka J E Assistant Professor Department of Computer Applications Niche
Presented By
Anusha Linda Kostka J E
Assistant Professor
Department of Computer Applications
NICHE
Definition
• An array can be of any data type including struct.
• Similarly we can also have arrays of variables that are of type class. Such
variables are called arrays of objects.
Consider the following class definition:
class employee
{
char name[30];
float age;
public:
void getdata(void);
void putdata(void);
};
• The identifier employee is a user-defined data type and can be used to create
objects that relate to different categories of the employees.
• Example:
employee manager[3];
employee foreman[15];
employee worker[75];
• The array manager contains three objects(managers), namely,
manager[0],manager[1], manager[2], of type employee class.
• Similarly, the foreman array contains 15 objects(foreman) and the worker array
contains 75 objects(worker).
• Example,
• The statement
manager[i].putdata();
will display the data of the ith element of the array manager.
• That is this statement requests the object manager[i] to invoke the member
function putdata().
• An array of objects is stored inside the memory in the same way as a multi-
dimensional array.
• The array manager is represented in Fig 1.
• Note that only the space for the data items of the objects is created.
• Member functions are stored separately and will be used by all the objects.
THANK YOU