0% found this document useful (0 votes)
42 views

Array of Objects: Presented by Anusha Linda Kostka J E Assistant Professor Department of Computer Applications Niche

An array can contain objects of a user-defined class type. This is called an array of objects. The document provides an example of an employee class with data members like name and age. Arrays are then declared for different employee types like managers, foremen, and workers. Each array element contains a separate employee object that can invoke member functions like getdata() and putdata(). An array of objects stores the objects sequentially in memory like a multi-dimensional array, with each object occupying space for its data members. But the class member functions are stored only once, to be used by all objects.

Uploaded by

Anusha K
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

Array of Objects: Presented by Anusha Linda Kostka J E Assistant Professor Department of Computer Applications Niche

An array can contain objects of a user-defined class type. This is called an array of objects. The document provides an example of an employee class with data members like name and age. Arrays are then declared for different employee types like managers, foremen, and workers. Each array element contains a separate employee object that can invoke member functions like getdata() and putdata(). An array of objects stores the objects sequentially in memory like a multi-dimensional array, with each object occupying space for its data members. But the class member functions are stored only once, to be used by all objects.

Uploaded by

Anusha K
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

ARRAY OF OBJECTS

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

You might also like