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 ie 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 elements, and the default size should be
When a pushback is performed, the vector is increased by if the vector is already full.
The popback should change the size by but should not affect the capacity.
The getElementAt should ensure the subscript is within range, however, the operator should not.
Submission
Submit your SimpleVectorOfInts.hcpp '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
assertemptyVectorsize;
assertemptyVectorcapacity;
Test pushback and popback
emptyVector.pushback;
emptyVector.pushback;
emptyVector.pushback;
Check if pushback increases size and capacity as needed
assertemptyVectorsize;
assertemptyVectorcapacity;
Check if popback reduces size
emptyVector.popback;
assertemptyVectorsize;
Test getElementAt
assertemptyVectorgetElementAt;
assertemptyVectorgetElementAt;
Test operator
assertemptyVector;
assertemptyVector;
Test out of range subscript should trigger an error
Uncomment this to see the error handling
emptyVector.getElementAt;
Test copy constructor
SimpleVectorOfInts copiedVectoremptyVector;
assertcopiedVectorsize;
assertcopiedVectorcapacity;
assertcopiedVectorgetElementAt;
assertcopiedVectorgetElementAt;
std::cout "All tests passed" std::endl;
return ;
SimpleVectorOfInts.h #ifndef SimpleVectorOfIntsSimpleVectorOfIntsh
#define SimpleVectorOfIntsSimpleVectorOfIntsh
#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
SimpleVectorOfIntsint;
Copy constructor declaration
SimpleVectorOfIntsconst SimpleVectorOfInts &;
Destructor declaration
~SimpleVectorOfInts;
Accessor to return the array size
int size const
return numberOfElements;
Accessor to return t
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
