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
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.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);
Vector
tCopy.PopBack(); cout << tTester.Size() << endl;// 6 cout << tCopy.Size() << endl;// 5
Vector
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
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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
