Question: Assignment Description We will implement a struct int Vector using procedural programming that has behavior similar to C + + ' s stan - dard
Assignment Description
We will implement a struct int Vector using procedural programming that has behavior similar to Cs stan
dard template library std::vector. Vector will not have any member functions. We will restrict our Vector to
only have member variables. We will write helperfunctions to construct and destruct our Vector and to add
elements to the Vector, check the size of the Vector, etc. See below for function prototypes and descriptions.
HelperFunctions and Vector Member Variables
The helperfunctions that operate on our Vector will be written as standalone functions. The member variables
and helperfunctions are listed below and follow the standard std::vector class definition. We will only
implement a subset of the std::vector features for Assignment The exception handling is optional.
A file called CSVector.h with a struct Vector; & all function declarations ie prototypes and
definitions
# include
# include
struct vector data type
struct Vector
int size ; int capacity ; int data nullptr ;
;
Vector prototypes
Construct a Vector v with a default size
void constructvector Vector & v int size int initVal ;
Destroy Vector v and return memory to the freestore heap
void destroyvector Vector & v ;
optional Helper function to copy v
void copydata Vector & v ;
Returns pointer to the first element in Vector v
int data const Vector & v ;
Returns the number of elements in Vector v
int size const Vector & v ;
Returns a reference to the element at location i or throws an exception
int & at Vector & v int i ;
Returns a reference to the last element or throws an exception
int & back const Vector & v ;
Returns the allocated storage for Vector v
int capacity const Vector & v ;
Erases the elements of Vector v but does not change capacity.
void clear Vector & v ;
If Vector v is empty return true, else false.
bool empty const Vector & v ;
Returns a reference to the first element or throws an exception
int & front const Vector & v ;
Add element to the end of the Vector v
void pushback Vector & v int element ;
Search for a key in Vector v return index of key or if not found
int find Vector &v int key ;
The function definitions ie implementations also included in a file called CSVector.h
Assignment : Implement all Vector functions i e define the functions
Construct a Vector v with a default size
void constructvector Vector & v int size int initVal
Your A code goes here
Destroy Vector v and return memory to the freestore heap
void destroyvector Vector & v
Your A code goes here
optional Helper function to copy v
void copydata Vector & v
Your A code goes here
Returns pointer to the first element in Vector v
int data const Vector & v
Your A code goes here
Returns the number of elements in Vector v
int size const Vector & v
Your A code goes here
Returns a reference to the element at location i in Vector v
Throws outofrange exception if out of bounds
int & at Vector & v int i
if empty v
throw std :: outofrange at exception ;
Your A code goes here
Returns a reference to the first element in the Vector
Throws outofrange exception if Vector is empty
int & front const Vector & v
if empty v
throw std :: outofrange front exception ;
Your A code goes here
Returns a reference to the last element in Vector v
Throws outofrange exception if Vector is empty
int & back const Vector & v
if empty v
throw std :: outofrange back exception ;
Your A code goes here
Returns the allocated storage for Vector v
int capacity const Vector & v
Your A code goes here
Erases the elements of Vector v but does not change capacity
void clear Vector & v
Your A code goes here
If Vector v is empty return true else false
bool empty const Vector & v
Your A code goes here
Add element to the end of the Vector v
void pushback Vector & v int element
Your A code goes here
Search for a key in Vector v return index of key or if not found
int find Vector &v int key
Your A code goes here
return ; not found
Example driver code to test functions with Vector a eg atai construct vectora at destroy vectora
fronta backa etc.: i provied SS below
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
