Question: Project part 1 - Please make beginner friendly in c + + You have been using std::vector for a while now. In this assignment you

Project part 1- Please make beginner friendly in c++
You have been using std::vector for a while now. In this assignment you will implement a simple version of vector, that just holds ints. You will define some of the same member functions that std::vector does, and they will behave the same way. The goal of this project is to learn how to manage dynamic memory on the heap. You will allocate an array on the heap for your Vector class to store ints in. When your underlying memory is used up, and you want to append or insert a new element, you will need to allocate a new array, copy the current elements to it, and then delete the old array.
Requirements
Call your class Vector (capital-v). Your constructor should allocate an initial array big enough to hold 10 ints (a constant named CHUNK), which is its initial "capacity", but the "size" (the numbers of elements currently in use) will initially be zero. Do not hard-code the 10.
When you expand the array, make the new capacity 1.6 times the current capacity (initially CHUNK).
I am providing the Vector.h file for you that declares everything in the class. Your job is to implement the member functions in the file Vector.cpp.
Vector.h:
#ifndef VECTOR_H
#define VECTOR_H
#include
using std::size_t;
class Vector
{
enum
{
CHUNK =10
};
int *data_ptr;
size_t capacity;
size_t n_elems;
void grow();
public:
Vector();
Vector(const Vector &v);
Vector &operator=(const Vector &v);
~Vector();
int front() const;
int back() const;
int at(size_t pos) const;
size_t size() const;
bool empty() const;
int &operator[](size_t pos);
void push_back(int item);
void pop_back();
void erase(size_t pos);
void insert(size_t pos, int item);
void clear();
int *begin();
int *end();
bool operator==(const Vector &v) const;
bool operator!=(const Vector &v) const;
};
#endif
In this project we are using the size_t type synonym, defined in . size_t is used for array/vector index positions and for the size (number of elements) of allocated memory. We use it whenever we refer to array sizes or positions.
You are also provided a test driver, testVector.cpp, and a test framework in test.h, to rigorously test
your project before you turn it in. The expected output is:
grow
Test Report:
Number of Passes =78
Number of Failures =0
The occurrence of grow above is a trace statement from your grow function, to verify that it
executed once.
Implementation Notes
I have given you the hint that will need a private grow function whenever you need to expand the
array from the push_back or insert functions.
In all cases where an array position is mentioned, check if it is within bounds, except for in
the operator[] function. Throw a std::range_error (defined in ) in that case. This
includes front and back as well, since they fail when the size is 0. Six functions need to throw
exceptions. Include an informational message inside the exception object.
Remember that you will be doing dynamic memory allocation in the copy constructor, copy
assignment operator and copy assignment operator. The destructor frees the heap memory with
the delete [] operator.
Project part 2- also in c++ and beginner friendly please
In part 1 you built your own vector of ints. In this project you will make your vector generic by using a class template.
Requirements
Make a copy of your Vector class from part 1 and change all references to the type of element contained in your array to be the template parameter T.
Once again, you are provided a test driver, testVector.cpp, and the test framework in test.h, to rigorously test your project before you turn it in. The expected output is:
Test Report:
Number of Passes =84
Number of Failures =0
You can remove the trace print from the grow function for this lab. Once again, your grade will be the
percentage of tests that you pass.
Implementation Notes
Remember that templates must all be defined inline within a single .h file.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!