Lec14 - Object Oriented programmingIIIaudio
Lec14 - Object Oriented programmingIIIaudio
What if you have a large collection of identical data items which you want to
process.
Examples :
• Sort n numbers.
• Compute the diameter of a set of 100 points in 2-D space.
• Compute the smallest enclosing sphere for a set of 10000 points in 3-D
space.
We need an easy way to identify and manipulate large number of variables
Arrays
Array : An Object which is an ordered collection of data items. These data items
could be
• primitive types.
• references to objects of a class.
Array : declaration and creation
Array : declaration and creation
int[ ] A ;
A = new int[4];
Array : declaration and creation
int[ ] A ;
A = new int[4];
BUT: What if we wish to sort the marks? How can we maintain the roll
numbers etc?
Student records
regNum= {6016, 6024, 6078};
midsemMarks = {61.7, 54 , 74.2 };
name = {"Ali",“John",“Sheila"};
In practice, parallel arrays are hard to maintain.
Better is to define an object STUDENT with data:
regNum, marks, and name, and define arrays of
the STUDENT object: Student[ ]
Arrays of Objects
Parallel array solution:
regNum= {6016, 6024, 6078};
midsemMarks = {61.7, 54 , 74.2 };
name = {"Ali", “John",“Sheila"};