Question: I need help with my c++ program, i need to implement all of the methods, and that's it. I cannot add any new properties. My

I need help with my c++ program, i need to implement all of the methods, and that's it. I cannot add any new properties.

My assignment is just implementing the methods

-All the code is in the h file

-When testing a template, any method you don't call gets deleted. So make sure you test them all, or you might secretly have one that doesn't compile.

-If you make your Vector not a template (change all the T's to int or something) it becomes easy to test as long as you remember to re-template it. (VS has trouble autocompleting a template since the code doesn't exist yet.)

-I'm going to drop your vector in to my project, so don't bother changing main unless you want to test something differently.

Here is main

#include "pch.h" #include #include "Vector.h"

using namespace std;

int main() { // Remember, you have to test all template functions since if you don't call it then it gets deleted. Otherwise a week from now you'll call the one you forgot and it will crash. Vector tTester; tTester.PushBack(4); tTester.PushBack(5); tTester.PushBack(6); tTester.PushBack(7); tTester.PushBack(8); tTester.PushBack(9);

tTester.PushFront(3); tTester.PushFront(2); tTester.PushFront(1); tTester.PushFront(0);

cout << tTester.Size() << endl;// 10 cout << tTester.At(5) << endl;// 5 cout << tTester.At(0) << endl;// 0

cout << tTester.Capacity() << endl; // 15 tTester.PushBack(11); tTester.PushBack(11); tTester.PushBack(11); tTester.PushBack(11); tTester.PushBack(11); tTester.PushBack(11); tTester.PushBack(111); tTester.PushBack(11); cout << tTester.Capacity() << endl; // 30

tTester.Reserve(50); cout << tTester.Capacity() << endl; // 50

tTester.PopFront(); cout << tTester.At(0) << endl;// 1

tTester.PopBack(); cout << tTester.At(tTester.Size() - 1) << endl;// 111

tTester.Erase(2); cout << tTester.At(2) << endl;// 4

tTester.Insert(1, 99); cout << tTester.At(2) << endl;// 2

tTester.Clear(); cout << tTester.Size() << endl;// 0

tTester.PushBack(0); tTester.PushBack(1); tTester.PushBack(2); tTester.PushBack(3); tTester.PushBack(4); tTester.PushBack(5);

VectortCopy(tTester); cout << tTester.Size() << endl;// 6 cout << tCopy.Size() << endl;// 6

tCopy.PopBack(); cout << tTester.Size() << endl;// 6 cout << tCopy.Size() << endl;// 5

Vector tAssign; tAssign.PushBack(999); tAssign = tTester; // Tricky thing, if you do an initialization (Vector A = B;) even though it has a = it runs the copy constructor instead.)

cout << tTester.Size() << endl;// 6 cout << tAssign.Size() << endl;// 6

tAssign.PopBack(); cout << tTester.Size() << endl;// 6 cout << tAssign.Size() << endl;// 5

}

.h file

template class Vector { T* mData; int mSize; int mCapacity;// For testing purposes, initialize this to 15. Whenever you allocate new memory, double it.

T mUndefined;// Lots of STL functions say that doing something naughty gets "undefined behavior". It could throw, crash, make you eggs, or return nonsense. // Return this undefined one if anybody ever tries to go out of bounds.

public: Vector()// O(1) { mSize = 0; mData = nullptr; } Vector(const Vector& tOther) : Vector()// O(n) { } Vector &operator =(const Vector& tRHS)// O(n) { return *this; // This line is weird so I'm just giving it to ya. It's just the definition of an = } void PushBack(const T &tItem)// O(1) { // We take a const reference, but we _copy_ it in to our personal array. } void PopBack()// O(1) { } void PushFront(const T &tItem)// O(n) { } void PopFront()// O(n) { } T& At(int tWhere)// O(1) { return mUndefined; } void Erase(int tWhere)// O(n) { // Keep an eye on this one. We'll change its prototype next week } void Insert(int tWhere, const T& tWhat)// O(n) { // Keep an eye on this one. We'll change its prototype next week } void Clear()// O(1) { } int Size()// O(1) { return 0; } void Reserve(int tCount)// O(n) { } int Capacity()// O(1) { return 0; } };

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 Databases Questions!