CSCI 362: Array – a std::vector-like class

NO GRACE DAYS MAY BE USED ON THIS LAB

Handout

Grab the handout tarfile from Autolab

You can extract the tarfile with the tar command:

tar xvf handout.tar

Overview

I have given you a somewhat incomplete implementation of Array. Array is a simplified version of std::vector which is very similar to what we discussed in class.

This is not a small file! I’m giving you almost 300 lines of code and you’ll be adding to it. It’s easy to become overwhelmed — so I make the following recommendations:

  1. I recommend solving the pieces least to most difficult. Points are correlated to difficulty.
  2. If you are ever unsure of the behavior of Array, you can always write code and compare it to what happens when you use std::vector.
  3. There is an included file: ArrayDriver.cc. Augment this to include your own tests. It will not be submitted as part of the assignment, but you will find it useful to write your own tests!

Required functions

// [8] Range constructor
Array(iterator first, iterator last);

// [10] Copy constructor
Array(const Array&);

// [4] Destructor
~Array();

// [10] Copy assignment
Array&          operator= (const Array& other);

// [2] empty
bool            empty() const;

// [2] capacity
size_t          capacity() const;

// [6] subscript
T&              operator[] (size_type pos);
const T&        operator[] (size_type pos) const;

// [8] push_back (add to end)
void            push_back (const T& value);

// [2] pop_back (remove from end)
void            pop_back();

// [7] resize
void            resize (size_type count, const T& value = T());

// [8] iterators
iterator        begin();
const_iterator  begin() const;
iterator        end();
const_iterator  end() const;

// [10] insert (before pos)
iterator        insert (iterator pos, const T& value);

// [8] erase (at pos)
iterator        erase (iterator pos);

Work on the easier functions first, then move on to the harder ones.

You will want to write your OWN TESTS instead of relying on autolab. Remember, Array is very similar to std::vector, so you can often compare behaviors!

Style

Use good programming style:

Submission

Please submit Array.hpp to autolab

Grading

This lab is graded out of 100 points