Here is a class declaration.  The only member data is a vector holding ints, your job is to implement the six member functions. class IntCollection {   private:     vector data;   public:     void add(int value);     int get(int index);     int getSize();   IntCollection& operator=(const IntCollection &c);       bool operator==(const IntCollection &c);           IntCollection& operator<<(int value);             }; Because a vector handles everything we need under the hood, we don't need the addCapacity function, constructors, or a destructor.  The rest of the functions are described below.  They should be simple to implement, most only require one or two lines! add() should add the value to the end of the vector.  get() should return the element at the given index. getSize() should return the number of elements in the vector. The Assignment operator (=). The assignment operator should perform a deep copy of the argument object.  It must return itself (or more efficiently, a reference to itself) in order to support multiple assignments on the same line, e.g. a = b = c.  If you implement your assignment operator first it could be used in the copy constructor, but this is not a requirement. The Is Equals operator (==). The "is equals" operator should return true if the argument object has the same size as the receiving object, and the values in both objects’ data arrays are identical. The insertion operator (<<). The insertion operator should add the int parameter into the receiving IntCollection.  The functionality is the same as the add() function, i.e. add ints to the collection.  Note, however, that this function must return a reference to itself in order to support multiple insertions on the same line, e.g. c << 45 << -210.  Unlike the assignment operator, this return must be done by reference, because each insertion actually modifies the IntCollection object, and insertion is done from left to right.     What to Submit? You should test all of your functions to your own satisfaction using a test program, e.g. a main() function in main.cpp.  Make sure your tests demonstrate all of the required functionality including multiple assignments on the same line and multiple insertions on the same line.  Paste sample output showing your test results at the bottom of your main program file main.cpp.   Submit a zip file containing three files to Canvas: IntCollection.h (or IntCollection.hpp) IntCollection.cpp main.cpp, including sample output

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Here is a class declaration.  The only member data is a vector holding ints, your job is to implement the six member functions.

class IntCollection
{
  private:
    vector<int> data;
  public:
    void add(int value);
    int get(int index);
    int getSize();
  IntCollection& operator=(const IntCollection &c);    
  bool operator==(const IntCollection &c);        
  IntCollection& operator<<(int value);            
};

Because a vector handles everything we need under the hood, we don't need the addCapacity function, constructors, or a destructor.  The rest of the functions are described below.  They should be simple to implement, most only require one or two lines!

  1. add() should add the value to the end of the vector. 
  2. get() should return the element at the given index.
  3. getSize() should return the number of elements in the vector.
  4. The Assignment operator (=). The assignment operator should perform a deep copy of the argument object.  It must return itself (or more efficiently, a reference to itself) in order to support multiple assignments on the same line, e.g. a = b = c.  If you implement your assignment operator first it could be used in the copy constructor, but this is not a requirement.
  5. The Is Equals operator (==). The "is equals" operator should return true if the argument object has the same size as the receiving object, and the values in both objects’ data arrays are identical.
  6. The insertion operator (<<). The insertion operator should add the int parameter into the receiving IntCollection.  The functionality is the same as the add() function, i.e. add ints to the collection.  Note, however, that this function must return a reference to itself in order to support multiple insertions on the same line, e.g. c << 45 << -210.  Unlike the assignment operator, this return must be done by reference, because each insertion actually modifies the IntCollection object, and insertion is done from left to right.  

 

What to Submit?

You should test all of your functions to your own satisfaction using a test program, e.g. a main() function in main.cpp.  Make sure your tests demonstrate all of the required functionality including multiple assignments on the same line and multiple insertions on the same line.  Paste sample output showing your test results at the bottom of your main program file main.cpp.  

Submit a zip file containing three files to Canvas:

  • IntCollection.h (or IntCollection.hpp)
  • IntCollection.cpp
  • main.cpp, including sample output 

Note: you will not receive credit for a solution which does not use a vector.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education