Overview

    User-Defined Vector Assignment

 As introduced in class, a vector class is C++'s answer to the limitations of arrays. As compared with arrays, vectors protect the user from accessing out-of-bounds ranges, they resize dynamically on demand, and they know and can report their length.

This assignment will test your ability to create a "class library." This means that, while you may create a main function for testing your own code, the main function may not be submitted. Your code will be tested against a different main function. As a result, it is very important that you match class and function names to what we specify.

This assignment will be due on 12/19. However, no resubmission will be possible unless you submit by 12/12.

Your class must be named myvector and take one template type argument. Your class must have at least the following public members, which shall function as described:

int size() -- return the current length of the vector
int capacity() -- return the current capacity of the vector
bool empty() -- return whether or not the vector is empty
void resize(int) -- resize the vector (change length) to the specified size, changing capacity as needed
void reserve(int) -- change the vector capacity to the specified size, or give an error if capacity would get smaller than length

You must also implement the [] operator, which should return a member of the vector at the index specified. An error should be thrown if the index is out of range. A function named at should also exist and perform the exact same functionality. Thus I should be able to do:

myvector x(5);
x[0] = 10;

void assign(int, T) -- assign the second argument as the value of the vector at the position of the first argument
void push_back(T) -- increase length by 1 and add the argument as the value at the end
T pop_back() -- decrease length by 1, returning the value removed from the vector
void insert(int, T) -- increase length by 1, put the value specified in the second argument at index specified by first argument and shift all values to the right in the vector down by one index
void erase(int) -- decrease length by 1, remove the item at the specified index and shift all other items left to eliminate the "hole"
void erase(int, int) -- same as erase(int), but removes all elements between the indexes specified by the first and second argument
void clear() -- remove all elements from the list

You also need constructors that take the following arguments:
int -- initial length of the vector
another vector of the same type (as a const reference) -- copy the contents of the vector
an array of the same type -- copy contents of array into the vector

Any destructor is added only if you feel it is necessary.

Extra Credit Opportunity

You can earn 15 points extra credit by detecting all overflow conditions, and throwing an overflow_error rather than crashing. Make sure you put in your readme file that you attempted this bonus or we will not test your assignment to see if it works.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.