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 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 capitalv Your constructor should allocate an initial array big enough to hold 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 hardcode the
When you expand the array, make the new capacity 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 VECTORH
#define VECTORH
#include
using std::sizet;
class Vector
enum
CHUNK
;
int dataptr;
sizet capacity;
sizet nelems;
void grow;
public:
Vector;
Vectorconst Vector &v;
Vector &operatorconst Vector &v;
~Vector;
int front const;
int back const;
int atsizet pos const;
sizet size const;
bool empty const;
int &operatorsizet pos;
void pushbackint item;
void popback;
void erasesizet pos;
void insertsizet pos, int item;
void clear;
int begin;
int end;
bool operatorconst Vector &v const;
bool operator!const Vector &v const;
;
#endif
In this project we are using the sizet type synonym, defined in sizet is used for arrayvector 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
Number of Failures
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 pushback 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::rangeerror defined in in that case. This
includes front and back as well, since they fail when the size is 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 also in c and beginner friendly please
In part 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 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
Number of Failures
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
