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

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter10: Object-oriented Programming
Section: Chapter Questions
Problem 20RQ
icon
Related questions
Question

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

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 5 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage