CS计算机代考程序代写 Templates and STL

Templates and STL
The Big Three
If you implemented either a Destructor, a Copy Constructor, or a Copy Assignment Operator, you should ensure that all 3 are defined
If you needed one, you probably need all of them This rule of thumb goes by a few names
The Big Three
The Rule of Three
The Law of the Big Three
For this lab we will make our own templated vector class, and then compare it with the STL vector class.
(6 pts) Implementing the Big Three for the Vector
class
Copy the vector.hpp and try_vector.cpp files below. Note that this current implementation doesn’t have a function for capacity().
vector.hpp
#include
template
class vector {
private:
T *v;
int s;
public:

vector(){
s=0;
v=NULL; }
~vector(){
delete [] v;
}
int size() {
return s;
}
void push_back(T ele) {
T *temp;
temp = new T[++s];
for(int i=0; i
#include
//using namespace std;
//using std::vector;
using std::cout;
using std::endl;
int main (){
vector v; //Our vector class
std::vector stdv; //Standard vector
//Compare operation of our vector to std
v.push_back(23);
stdv.push_back(23);
cout << "Our vector size: " << v.size() << endl; cout << "STL vector size: " << stdv.size() << endl; return 0; } You need to finish implementing the Big Three for your vector template class, since vectors use dynamic memory. Copy Constructor //We do not want to include either statement. We wouldn't be able to compare our vector template to the Standard vector(vector &other){…}
Assignment Operator Overload
void operator=(vector &other){…}
(1 pt) Testing Your Template
Convince yourself and the TAs that your templated vector class constructors and Big Three are working as intended. Modify the try_vector.cpp file as needed to show this.
(5 pts) Adding Functions
After you’ve got the previous section working, it is time to move forward towards implementing the rest of your vector template class. Two key functions for vectors are used for accessing the elements. Implement the functions below:
T& operator[](int); //Only performs address arithmetic
T& at(int); //Check to make sure not out of bounds
(2 pt) Testing Functions
Convince yourself and the TAs that both of your templated vector class functions for accessing data work. Modify the try_vector.cpp file as needed to show this.
(6 pt) Rounding out the Vector class
How would this change for having capacity and size members?
What will you have to change in your vector class when you add a capacity private member? The capacity is the actual number of elements allocated on the heap for the vector, and the size is the number that is being used.
How would the constructors and push_back() function change?
Write out a plan for the extra constructors you might need for testing this and how the push_back() function changes with regard to having both capacity and size members.
(Optional) Implement these extra constructors and change your push_back() function to operate correctly with capacity and size, now that they may differ.

(Optional) Include a resize() function.
Rubric
Criteria
Pts
This criterion is linked to a Learning Outcome Implementing the Big Three for the Vector class
6 pts
This criterion is linked to a Learning Outcome Testing Big Three
1 pts
This criterion is linked to a Learning Outcome Creating T& operator[ ]( int ) and testing
3.5 pts
This criterion is linked to a Learning Outcome Creating T& at( int ) and testing
3.5 pts
This criterion is linked to a Learning Outcome
Modifying constructors with regard to having both capacity and size members.
2 pts
This criterion is linked to a Learning Outcome
Modifying push_back( ) with regard to having both capacity and size members
2 pts

This criterion is linked to a Learning Outcome Create a resize( ) function
2 pts