Create a class named Collection for which each object can hold integers. The class should have following two private data members 1. An integer pointer named data that holds a reference of an array created dynamically according to the specified size. 2. A constant integer named size to hold the maximum size of the array. Provide the implementation of following constructors and a destructor 1. A constructor which accepts an integer that represents the size of an array and initializes it to the "empty collection," i.e., a collection whose array representation contains all 0. 2. An additional constructor that receives an array of integers and the size of that array and uses the array to initialize a collection object. 3. A copy constructor to initialize a collection object with already existing object. 4. A destructor to free any memory resources occupied by the collection object. Provide following member functions for the common set operations 1. getSize returns the size of collection. 2. setElement that inserts a new integer k at index i ( both passed as argument) into a collection, if possible. 3. countElement that counts and return the total occurrences of an integer key (passed as argument) in a collection, -1 otherwise. Overload following operators 1. Assignment (=) which copies the data of one object to another. The copy should only be done if both the objects have same sizes also avoid self-assignment. 2. Stream extraction to take input from user for the ‘data’ of a collection. 3. Stream insertion to display the contents of ‘data’ on the screen of a collection. 4. Addition (+) binary operator which perform the addition of two collections if possible and return the result. 5. Arithmetic assignment operator (–=) which subtract the right hand side collection from left if possible and assign the result back to left hand side collection. 6. Minus (–) unary operator which return true if all the elements of a collection are negative, false otherwise. 7. Pre increment (++) and post decrement (--) to increment a collection by 1 and to decrement it by 1 respectivel
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Create a class named Collection for which each object can hold integers.
The class should have following two private data members
1. An integer pointer named data that holds a reference of an array created dynamically according to the specified size.
2. A constant integer named size to hold the maximum size of the array.
Provide the implementation of following constructors and a destructor
1. A constructor which accepts an integer that represents the size of an array and initializes it to the "empty collection,"
i.e., a collection whose array representation contains all 0.
2. An additional constructor that receives an array of integers and the size of that array and uses the array to initialize a
collection object.
3. A copy constructor to initialize a collection object with already existing object.
4. A destructor to free any memory resources occupied by the collection object.
Provide following member functions for the common set operations
1. getSize returns the size of collection.
2. setElement that inserts a new integer k at index i ( both passed as argument) into a collection, if possible.
3. countElement that counts and return the total occurrences of an integer key (passed as argument) in a collection, -1
otherwise.
Overload following operators
1. Assignment (=) which copies the data of one object to another. The copy should only be done if both the objects have
same sizes also avoid self-assignment.
2. Stream extraction to take input from user for the ‘data’ of a collection.
3. Stream insertion to display the contents of ‘data’ on the screen of a collection.
4. Addition (+) binary operator which perform the addition of two collections if possible and return the result.
5. Arithmetic assignment operator (–=) which subtract the right hand side collection from left if possible and assign the
result back to left hand side collection.
6. Minus (–) unary operator which return true if all the elements of a collection are negative, false otherwise.
7. Pre increment (++) and post decrement (--) to increment a collection by 1 and to decrement it by 1 respectivel
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 5 images