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:
- I recommend solving the pieces least to most difficult. Points are correlated to difficulty.
- If you are ever unsure of the behavior of
Array
, you can always write code and compare it to what happens when you usestd::vector
. - 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
(iterator first, iterator last);
Array
// [10] Copy constructor
(const Array&);
Array
// [4] Destructor
~Array();
// [10] Copy assignment
& operator= (const Array& other);
Array
// [2] empty
bool empty() const;
// [2] capacity
size_t capacity() const;
// [6] subscript
& operator[] (size_type pos);
Tconst 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;
const_iterator begin();
iterator end() const;
const_iterator end
// [10] insert (before pos)
(iterator pos, const T& value);
iterator insert
// [8] erase (at pos)
(iterator pos); iterator erase
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:
- Write comments where appropriate
- Remember to include a comment block at the top of your program that
includes:
- Your name
- The course
- The last date of modification
- The assignment name
- A brief description of what your program does
- FORMAT YOUR CODE CONSISTENTLY
Submission
Please submit Array.hpp
to autolab
Grading
This lab is graded out of 100 points
- [85pts] Unit tests for
Array
- [15pts] Clean and clear formatting/style points
- NOTE: if your program does not compile/run, the highest score you will earn will be a 15/100