Question
Vector.h defines a vector template class. The class is very similar to the STL vector class. The file dsexceptions.h defines three exception classes which have
Vector.h defines a vector template class. The class is very similar to the STL vector class. The file dsexceptions.h defines three exception classes which have no content but is required by the program. The file TestVector.cpp is the driver program. It tests the vectorclass in vector.h.Compile the program TestVector.cpp and test it. Make sure it works. For this assignment you will add the methods erase and insert to the vector class. You will have to find out the parameters (signature) of these methods and the functionality of the methods. Compile the program using the modified vector class.Submit the files vector.h and TestVector.cpp along with the test results.
Vector.h
#ifndef VECTOR_H #define VECTOR_H #include
Object *newArray = new Object[ newCapacity ]; for( int k = 0; k < theSize; ++k ) newArray[ k ] = std::move( objects[ k ] );
theCapacity = newCapacity; std::swap( objects, newArray ); delete [ ] newArray; } // Stacky stuff void push_back( const Object & x ) { if( theSize == theCapacity ) reserve( 2 * theCapacity + 1 ); objects[ theSize++ ] = x; } // Stacky stuff void push_back( Object && x ) { if( theSize == theCapacity ) reserve( 2 * theCapacity + 1 ); objects[ theSize++ ] = std::move( x ); } void pop_back( ) { if( empty( ) ) throw UnderflowException{ }; --theSize; } const Object & back ( ) const { if( empty( ) ) throw UnderflowException{ }; return objects[ theSize - 1 ]; } // Iterator stuff: not bounds checked typedef Object * iterator; typedef const Object * const_iterator; iterator begin( ) { return &objects[ 0 ]; } const_iterator begin( ) const { return &objects[ 0 ]; } iterator end( ) { return &objects[ size( ) ]; } const_iterator end( ) const { return &objects[ size( ) ]; } static const int SPARE_CAPACITY = 2; private: int theSize; int theCapacity; Object * objects; }; #endif
dsexceptions.h
#ifndef _DSEXCEPTIONS_H_
#define _DSEXCEPTIONS_H_
class Underflow { };
class Overflow { };
class OutOfMemory { };
class BadIterator { };
#endif
TestVector.cpp
#include "Vector.h" #include
void print( const Vector
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started