Assignment 5
Vector class

Due: Sunday, Oct. 14, 11:59pm

Please see the general programming webpage for details about the programming environment for this course, guidelines for programming style, and details on electronic submission of assignments.

The only file you will need for this assignment is the Vector.h file that we wrote in class.

Collaboration Policy

For this assignment, you must work alone on your assignment.

Please make sure you adhere to the policies on academic integrity in this regard.


Overview

As you may have noticed, the vector class in C++ has much less functionality than the list class in Python. In addition, we did not even complete all of the vector functionality that is included in the standard template library.

In as effort to ``upgrade" the vector class we wrote, you will write the following functions described below in our Vector.h file. (Please download Vector.h from the course schedule webpage and insert your functions into this class, then submit the entire Vector.h file via email by the due date.)

Functions to code

  • void remove(Object val);

    Removes the earlist occurance of val present in the vector. Note that this changes the size.

  • void reverse();

    Reverses the order of the vector's elements.

  • bool operator<(const Vector& other);

    Returns true if the contents of the current vector are lexicographically less than the contents of other. Note that this function ignores the capacity of the vectors, and only compares the elements that are actually in the vector.

    Note: Be careful of exceeding the capcity of each vector! You should be careful not to run off the end of the array, and only compare the vectors up to the smaller one's size.

  • void replace(const Object& val1, const Object& val2);

    Replace all instances of val1 in the vector with the value val2. Note that this should not just find the first such position, but should replace every instance.

  • Extra Credit

  • void resize ( int sz, Object c );

    Resizes the vector to contain sz elements.

    If sz is smaller than the current vector size, the content is reduced to its first sz elements, the rest being dropped.

    If sz is greater than the current vector size, the content is expanded by inserting at the end as many copies of c as needed to reach a size of sz elements. This may cause a reallocation.

    Notice that this function changes the actual content of the vector by inserting or erasing elements from the vector; it does not only change its storage capacity.


  • Testing

    You are also required to write a test file, similar to our testVector.cpp in class. You our welcome to use our code from class as a starting point, but your grade will be partially based on how well you test your code. Remember to thoroughly test all possible inputs before submitting.

    Analysis

    In addition, your readme file must include a worst case runtime analysis (with a big-O bound) for each function that you code.

    Files to Submit


    Grading Standards

    The assignment is worth 10 points. One point will be based on a checkpoint with the instructor on Thursday, October 11, at which time you will be expected to have completed at least 20 lines of code for the assignment. The remaining 9 points will be based on your implementation, test file, and readme.