Implementing the vector class in the following code (It's C++, not Java). You just need to implement all these methods: PushFront, PopFront, At, Erase, Insert, Clear, Reserve, Copy, Assign, and Destroy, please do not add any new properties. You cannot use std:: functions, && (unless being used for "AND"), or pass by reference. Your solutions must conform to the Big O notations next to each method.
In the following code, I am going to match the names that STL uses so you don't get confused in the real world. I'm skipping operator [] for a specific reason, please don't ask about it.
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 the professor just giving it. 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.
}
void Insert(int tWhere, const T& tWhat)// O(n)
{
// Keep an eye on this one, too.
}
void Clear()// O(1)
{
}
int Size()// O(1)
{
return 0;
}
void Reserve(int tCount)// O(n)
{
}
int Capacity()// O(1)
{
return 0;
}
};
// VectorStub.cpp : This file contains the 'main' function. Program execution begins and ends there.
#include "pch.h"
#include <iostream>
#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 later when 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; // This is a 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
}
Implementing the vector class in the following code (It's C++, not Java). You just need to...
In C++, you are implementing the vector class in the VectorStub zip. You need to implement all of the methods, and that's it. You cannot add any new properties. Your solutions must conform to the Big O notations next to each method. A few things to remember about templates: 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...
vector.h: #ifndef VECTOR_H #define VECTOR_H #include <algorithm> #include <iostream> #include <cassert> template <typename T> class Vector { public: Vector( int initsize = 0 ) : theSize( initsize ), theCapacity( initsize + SPARE_CAPACITY ) { objects = new T[ theCapacity ]; } Vector( const Vector & rhs ) : theSize( rhs.theSize), theCapacity( rhs.theCapacity ), objects( 0 ) { objects = new T[ theCapacity ]; for( int k = 0; k < theSize; ++k) objects[ k ] = rhs.objects[ k...
// I understand what I have to do on a fundamental level however I am having trouble just grasping how to implement them into the program. Explanation greatly appreciated! The files section has a gutted List class for you. Just write all the methods. Easy peasy. Just remember that if your code never calls a template method, the compiler deletes it entirely. Make sure you test everything. List's big three: Destructor, Copy, Assignment. Vanilla constructor is right - don't change...
Please help fix my code C++, I get 2 errors when running. The code should be able to open this file: labdata.txt Pallet PAG PAG45982IB 737 4978 OAK Container AYF AYF23409AA 737 2209 LAS Container AAA AAA89023DL 737 5932 DFW Here is my code: #include <iostream> #include <string> #include <fstream> #include <vector> #include <cstdlib> #include <iomanip> using namespace std; const int MAXLOAD737 = 46000; const int MAXLOAD767 = 116000; class Cargo { protected: string uldtype; string abbreviation; string uldid; int...
10.18 LAB: Plant information (vector) Given a base Plant class and a derived Flower class, complete main() to create a vector called myGarden. The vector should be able to store objects that belong to the Plant class or the Flower class. Create a function called PrintVector(), that uses the PrintInfo() functions defined in the respective classes and prints each element in myGarden. The program should read plants or flowers from input (ending with -1), adding each Plant or Flower to...
C++ EXERCISE (DATA STRUCTURES). I just need a code for some functions that are missing. Please help me figure out. Thanks. C++ BST implementation (using a struct) Enter the code below, and then compile and run the program. After the program runs successfully, add the following functions: postorder() This function is similar to the inorder() and preorder() functions, but demonstrates postorder tree traversal. displayParentsWithTwo() This function is similar to the displayParents WithOne() function, but displays nodes having only two children....
I keep getting errors and i am so confused can someone please help and show the input and output ive tried so many times cant seem to get it.
main.cpp
#include <iostream>
#include <vector>
#include <string>
#include "functions.h"
int main()
{
char option;
vector<movie> movies;
while (true)
{
printMenu();
cin >>
option;
cin.ignore();
switch (option)
{
case 'A':
{
string nm;
int year;
string genre;
cout << "Movie Name: ";
getline(cin, nm);
cout << "Year: ";
cin >> year;
cout << "Genre: ";
cin >> genre;
//call you addMovie() here
addMovie(nm, year, genre, &movies);
cout << "Added " << nm << " to the catalog"
<< endl;
break;
}
case 'R':
{
string mn;
cout << "Movie Name:";
getline(cin, mn);
bool found;
//call you removeMovie() here
found = removeMovie(mn, &movies);
if (found == false)
cout << "Cannot find " << mn << endl;
else
cout << "Removed " << mn << " from catalog"
<< endl;
break;
}
case 'O':
{
string mn;
cout << "Movie Name: ";
getline(cin, mn);
cout << endl;
//call you movieInfo function here
movieInfo(mn, movies);
break;
}
case 'C':
{
cout << "There are " << movies.size() << " movies
in the catalog" << endl;
// Call the printCatalog function here
printCatalog(movies);
break;
}
case 'F':
{
string inputFile;
bool isOpen;
cin >> inputFile;
cout << "Reading catalog info from " << inputFile
<< endl;
//call you readFromFile() in here
isOpen = readFile(inputFile, &movies);
if (isOpen == false)
cout << "File not found" << endl;...
I need a detailed pseudocode for this code in C ++. Thank you #include <iostream> #include <string> #include <iomanip> using namespace std; struct Drink { string name; double cost; int noOfDrinks; }; void displayMenu(Drink drinks[], int n); int main() { const int size = 5; Drink drinks[size] = { {"Cola", 0.65, 2}, {"Root Beer", 0.70, 1}, {"Grape Soda", 0.75, 5}, {"Lemon-Lime", 0.85, 20}, {"Water", 0.90, 20} }; cout <<...
Take the following code for a binary source tree and make it include the following operations. bool replace(const Comparable & item, const Comparable & replacementItem); int getNumberOfNodes() const; (a) The replace method searches for the node that contains item in a binary search tree, if it is found, it replaces item with replacementItem. The binary tree should remain as a binary search tree after the replacement is done. Add the replace operation to the BinarySearchTree class. Test your replace using...
Keep getting this error message when trying to compile in main1.cpp. Need help figuring out how to make it compile. Thank you for your time. Error Message: main.cpp:(.text+0x13): undefined reference to `circle::circle()' main.cpp:(.text+0x32): undefined reference to `circle::circle(double)' main.cpp:(.text+0x3e): undefined reference to `circle::getArea() const' main.cpp:(.text+0x53): undefined reference to `circle::getRadius() const' main.cpp:(.text+0xb3): undefined reference to `circle::getArea() const' main.cpp:(.text+0xc8): undefined reference to `circle::getRadius() const' main.cpp:(.text+0x157): undefined reference to `circle::setRadius(double)' main.cpp:(.text+0x163): undefined reference to `circle::getArea() const' main.cpp:(.text+0x178): undefined reference to `circle::getRadius() const' main.cpp:(.text+0x207): undefined...