Question: C++ Programming::::::::::::::::::::::::::::::::::::::::::::::::::::::: ===================================================== =------------------------------------------------------------------------------------------------ Code for Collection.h: #pragma once #include #include #include #include using namespace std; template class Collection; template ostream& operator& c); template class
C++ Programming:::::::::::::::::::::::::::::::::::::::::::::::::::::::
=====================================================
=------------------------------------------------------------------------------------------------

Code for Collection.h:
#pragma once #include #include #include #include
using namespace std;
template class Collection;
template ostream& operator& c);
template class Collection { public: Collection(); Collection(int size); Collection(Collection- & a); virtual int size(); virtual Item get(int ndx) const; virtual void add(Item e); virtual void removeEnd(); virtual Collection
- & operator= (Collection
- &a); virtual Item operator [](int ndx); virtual void operator-(int num); friend ostream& operator(ostream& out, const Collection
- &c);
protected: int capacity; int curSize; static const int INITIAL_CAPACITY = 8; void expand(); unique_ptr - elements;
};
template Collection- ::Collection() {
capacity = INITIAL_CAPACITY; curSize = 0; elements = make_unique- (capacity); }
template Collection- ::Collection(int size) { capacity = size; curSize = 0; elements = make_unique
- (capacity);
} template Collection- ::Collection(Collection
- & a) {
capacity = a.capacity; curSize = a.curSize;
elements = make_unique- (capacity); for (int i = 0; i
template int Collection- ::size() { return curSize; } template Item Collection
- ::get(int ndx) const { return elements[ndx]; }
template void Collection- ::add(Item e) { if (curSize == capacity) { expand(); } elements[curSize] = e; curSize++; }
template void Collection- ::removeEnd() {
curSize--; if (curSize
template Collection- & Collection
- :: operator=(Collection
- & a) { auto newElements = make_unique
- (a.capacity); for (int i = 0; i
return *this; }
template Item Collection- ::operator [](int ndx) { return get(ndx); }
template void Collection- ::operator-(int num){ for (int i = 0; i
template void Collection- ::expand() { auto newElements = make_unique
- (capacity * 2); for (int i = 0; i
template ostream&operator& c){ for (int i = 0; i }
Code for SortedCollectionTesting.cpp:
#include #include "SortedCollection.h" using namespace std;
void TestSortedCollection(); void TestSortedCollectionConstructors(); void TestAddToOperatorCollection(); void TestRemoveCollection(); bool checkCase(string name, bool condition);
int main() { TestSortedCollection(); TestSortedCollectionConstructors(); TestAddToOperatorCollection(); TestRemoveCollection(); return 0; } void TestSortedCollection(){ SortedCollectionone; one one(10); for(double i = 0.0; i two(one); checkCase("Constructor Test", two[0] == 0);
}
void TestAddToOperatorCollection(){ SortedCollection one; one + 19 + 9 + 2 + 8 + 7 + 12 + 17 + 0 + 11 + 6 + 3 + 1; checkCase("Add In Order 1", one[0] == 0); checkCase("Add In Order 2", one[11] == 19); checkCase("Add Check Size", (one one; one + 19 + 9 + 2 + 8 ;
checkCase("Original Size", one.size() == 4); one -2; checkCase("Remove 2 Size", one.size() == 2); checkCase("Still In Order", one[1] == 8); bool exception_caught = true; try{ one - 3; exception_caught = false; } catch (exception& a){ exception_caught = true; } checkCase("Exception Caught", exception_caught); } bool checkCase(string name, bool condition){ if(!condition){ cout
This assignment will help you practice Smart pointers, Inheritance, and Overloaded Operators. Description Open the assignment we did with the Collection example. Create a new templated class called Sorted Collection that inherits the Collection class. Add the following items to the SortedCollection class. Overload the three constructors such that you can make a call to SortedCollection using no parameters, a single int parameter to specify the max size, and with a parameter of another Sorted Collection to start with a given collection. Create an additional overload operator for the + operator. This will help you practice with overloaded operators. This time we will use it to add an Item to the Collection class (and thus Sorted Collection class). When implementing the operator, you are welcome to call the add method that has already been coded. Create an additional overload operator for the that inherits the Collection class. Add the following items to the SortedCollection class. Overload the three constructors such that you can make a call to SortedCollection using no parameters, a single int parameter to specify the max size, and with a parameter of another Sorted Collection to start with a given collection. Create an additional overload operator for the + operator. This will help you practice with overloaded operators. This time we will use it to add an Item to the Collection class (and thus Sorted Collection class). When implementing the operator, you are welcome to call the add method that has already been coded. Create an additional overload operator for the