You are on page 1of 2

Object Oriented Programming

Lab 08
Topic Covered: Array Operator [ ] Overloading

Q1. Create a class named Array that represents a safe array.


1. It has two attribute
2. ptr as an integer pointer for pointer to an integer array.
3. size as an integer number for size of an array.

4. Make no argument constructor to set size equals to 0 and ptr


equals to NULL.

5. Make one argument constructor, the data type of the argument is


int.
6. Set size equals to the argument value.
7. Now make array of this size dynamically, and store its address
in ptr.
8. Now fill this array with zeros.

9. Make two argument constructor, the first argument is an integer


array and the 2nd argument is sz.
10. Set size equals to the sz.
11. Now make array of this size dynamically, and store its address
in ptr.
12. Fill this array with the array passed through argument.

13. Make a destructor to free the memory if ptr is not equal to


NULL.

14. Make int Size() function to return array size.

15. Make int Resize( int newSize) function to resize the array.
For this you have to delete the previous array and then make the
new array dynamically.

16. Make void Show() function to show numbers stored in the dynamic
array on screen.

1
17. Make operator overloading of == operator to see if the two
arrays are same or not.
18. Make operator overloading of += operator to concatenate two
arrays objects. Answer should be copied to the calling object.
19. Hint: You have to resize the array to accommodate two arrays
20. Make operator overloading of [] operator to read or write any
position of the array.
21. Also write the code to check out of bound errors
22. Make two Array Objects in main() function and call the above
functions and operators.

Here is the output of program

You might also like