Question
In C++; #include Collection.h Collection::Collection(){ } Collection::Collection(int size){ } int Collection::getSize() const{ return -1; } int Collection::getCapacity() const{ return -1; } double Collection::get(int ndx) const{
In C++;
#include "Collection.h"
Collection::Collection(){
} Collection::Collection(int size){
} int Collection::getSize() const{ return -1; } int Collection::getCapacity() const{ return -1; } double Collection::get(int ndx) const{ return 0.0; } double Collection::getFront() const{ return 0.0; } double Collection::getEnd() const{ return 0.0; } int Collection::find(double needle) const{ return -1; } void Collection::add(double item){ } void Collection::removeFront(){ } void Collection::removeEnd(){ } void Collection::remove(double item){ } double& Collection::operator[](int ndx){ //TODO:remove tmp and return a refernce //to the actual value in the collection double* tmp = new double(-1.0); return *tmp; }
Collection& Collection::operator-(int count){ return *this; } Collection& Collection::operator+(double item){ return *this; } Collection& Collection::operator+(const Collection& other){ return *this; } Collection& Collection::operator Create a class named Collection that will store double values in an array. You will need to implement the following public methods. Default constructor Single-argument constructor that takes and integer parameter and use it to set the initial capacity of the array getSize - returns the number of elements in the array. Unlike c-strings where we had a null-terminator to mark the end of the array, in this case you will need a variable to keep track of the number of elements currently in the array. .getCapacity - returns the maximum number of elements allowed in the current array. Again you will probably want to store this value in a variable and update it each time you grow the array to a new size. add - Adds the double to the end of the array. If the array is full it should create a new array that is twice as large and copy all of the existing elements over. get - Gets the value stored at the specified position. Throws and out_of_range exception if the index is outside the bounds of the array. find - Returns the index of the specified value in the array or -1 if the value is not found. getFront - Returns the first value in the array. Throws an out_of_range exception if the array is empty. getEnd - Returns the last value in the array. Throws and out_of_range exception if the array is empty. removeFront - Removes the first value in the array and moves everything else over. If the array is empty this method has no effect. removeEnd - Removes the last value in the array. If the array is empty this method has no effect. remove - Removes the specified value from the array. If there are multiple instances of the same value in the array it removes the first instance. If the value does not occur in the array this method has no effect. operator[] - Allows the class to be accessed like an array (i.e. returns the value stored in the specifed position as a reference operator-- Removes the specified number of items from the end of the array. if the number of items to remove is more than there are items in the array all the existing items in the array are removed. Returns a reference to this instance so that the operator can be chained. operator+ - Adds the double to the end of the array. If the array is full it should create a new array that is twice as large and copy all of the existing elements over. Returns a reference to this instance so that the operator can be chained. operator+(const Collection & other) - Adds all of the elements from the other collection. When the array fills up, it will need to be resized and copied like always. Returns a reference to this instance so that the operator can be chained. operator
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started