Question: This programming assignment explores how the vector class works. The vector class you were introduced to behaves like an array. You used features like pushback

This programming assignment explores how the vector class works. The vector class you were introduced to behaves like an
array. You used features like pushback(), popback(), size(), etc. In this programming assignment you will work with simplified
version of the vector class that only holds integers. This class is named SimpleVectorOfInts.
Your first task is to read and understand the SimpleVectorOfInts.h file. This is the interface for the class i.e. the contract with
external software on the promised behavior. Then your main task is to implement each of the functions in the
SimpleVectorOfints.cpp file.
As you implement each of the functions, you should test your functions by writing code in main. For example, once you finish
the pushback() function, then you should test your pushback() in various scenarios in your main such as pushback() on an empty
vector, pushback on a full vector, etc. The code in the main.cpp will not be uploaded for testing. The only code you will upload
for testing is the SimpleVectorOfInts.h and SimpleVectorOfInts.cpp files.
These two files will be evaluated using what are known as unit tests. A unit test is a test designed to check and verify a single
piece of functionality. While all the tests are run at the same time, you should upload your files as you complete functions. The
test will then let you know that you have passed testing for those functions. You will fail tests for unimplemented functions, but
at least you can see the progress as you go. Note that you will be able to see the majority of the tests, but there will be some
that are hidden. The purpose of this is to have you thoroughly test your code and try to satisfy the unexpected. This will help to
sharpen your testing and programming skills.
Requirements
This SimpleVectorOfInts class is expected to behave like the standard vector class. There are a few requirements that need to
be met:
The default capacity of the vector should be 10 elements, and the default size should be 0.
When a push_back() is performed, the vector is increased by 5 if the vector is already full.
The pop_back() should change the size by -1, but should not affect the capacity.
The getElementAt() should ensure the subscript is within range, however, the [ operator should not.
Submission
Submit your SimpleVectorOfInts.h[cpp] 'for testing each time you think you have finished a function. Ensure that the tested
functions are working before moving on. The sample template is setup using function stubs. This means they are empty
functions that will compile, but will not produce the correct results. Therefore, you do not need to implement each stub before
submitting. main.cpp - #include "SimpleVectorOfInts.h"
#include
#include
int main(){
// Test default constructor
SimpleVectorOfInts emptyVector;
// Check if the default constructor initializes correctly
assert(emptyVector.size()==0);
assert(emptyVector.capacity()==10);
// Test push_back and pop_back
emptyVector.push_back(42);
emptyVector.push_back(17);
emptyVector.push_back(99);
// Check if push_back increases size and capacity as needed
assert(emptyVector.size()==3);
assert(emptyVector.capacity()==10);
// Check if pop_back reduces size
emptyVector.pop_back();
assert(emptyVector.size()==2);
// Test getElementAt
assert(emptyVector.getElementAt(0)==42);
assert(emptyVector.getElementAt(1)==17);
// Test operator []
assert(emptyVector[0]==42);
assert(emptyVector[1]==17);
// Test out of range subscript (should trigger an error)
// Uncomment this to see the error handling
// emptyVector.getElementAt(2);
// Test copy constructor
SimpleVectorOfInts copiedVector(emptyVector);
assert(copiedVector.size()==2);
assert(copiedVector.capacity()==10);
assert(copiedVector.getElementAt(0)==42);
assert(copiedVector.getElementAt(1)==17);
std::cout "All tests passed" std::endl;
return 0;
}
SimpleVectorOfInts.h - #ifndef SimpleVectorOfInts_SimpleVectorOfInts_h
#define SimpleVectorOfInts_SimpleVectorOfInts_h
#include
#include // Needed for the exit function
using namespace std;
class SimpleVectorOfInts
{
private:
int *dynamicArrayPtr; // To point to the allocated array
int numberOfElements; // Number of elements in the array
int arrayCapacity; // capacity of the dynamic array
void memError(); // Handles memory allocation errors
void subError(); // Handles subscripts out of range
public:
// Default constructor
SimpleVectorOfInts();
// Constructor declaration
SimpleVectorOfInts(int);
// Copy constructor declaration
SimpleVectorOfInts(const SimpleVectorOfInts &);
// Destructor declaration
~SimpleVectorOfInts();
// Accessor to return the array size
int size() const
{ return numberOfElements; }
// Accessor to return t
This programming assignment explores how the

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!