11.P1 Vector Class

READ ME (Chapter 10, 11)

This is just the "add_entry" project in a class.

Use templates if it's been covered in your class, or use a typedef. Do not make this a vector of doubles as the book says.Your Vector class will use the add_entry functions written in previous projects to implement a dynamic list class.

Your class must have default constructors, operators, big three, etc.

Your class will have a _capacity and a _size member variable which will hold the space allocated and the space used respectively.

Define appropriate operators including +, +=, <<, >>, etc.

 

template <class T>
class Vector{
public:

    Vector(int capacity = 100);
    Vector(T *arr, int size);
    // big three:
    ...
    //member access functions:
    T& operator [](int index);
    const T& operator [](int index) const;

    T& at(int index);              //return reference to item at position index
    const T& at(int index) const;  //return a const item at position index

    T& front();                         //return item at position 0.
    T& back();                          //return item at the last position


    //Push and Pop functions:
    Vector& operator +=(const T& item); //push_back
    void push_back(const T& item);      //append to the end
    T pop_back();                       //remove last item and return it


    //Insert and Erase:
    void insert(int insert_here, const T& insert_this); //insert at pos
    void erase(int erase_this_index);        //erase item at position
    int index_of(const T& item);             //search for item. retur index.

    //size and capacity:
    void set_size(int size);              //enlarge the vector to this size
    void set_capacity(int capacity);      //allocate this space
    int size() const {return _how_many;}  //return _size
    int capacity() const {return _capacity;} //return _capacity

    bool empty() const;                    //return true if vector is empty

    //OUTPUT:
    template <class U>
    friend ostream& operator <<(ostream& outs, const Vector<U>& _a);
private:
    ...
};