Question: DONT EDIT HEADER #ifndef MYVECTOR _ H #define MYVECTOR _ H #include #include #include using std::cerr; using std::cin; using std::cout; using std::endl; using std::string; class

DONT EDIT HEADER
#ifndef MYVECTOR_H
#define MYVECTOR_H
#include
#include
#include
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
using std::string;
class ArrayListIterator {
int index;
public:
ArrayListIterator(int i) : index(i){}
operator int(){
return index;
}// allows Iterator to be used like an int/index
ArrayListIterator operator+(int increment){
index += increment;
return *this;
}// allows +/++
bool operator>(int comp){ return index > comp; }
bool operator(int comp){ return index comp; }
};
template class MyVector {
private:
T *data = nullptr;
int max_elements;
int num_elements;
public:
// Just a simple default constructor.
MyVector() : max_elements(4), num_elements(0){ data = new T[4]; }
~MyVector();
const MyVector &operator=(const MyVector &source);
MyVector(const MyVector &source);
T &operator[](int index);
T &at(int index);
T &front();
T &back();
unsigned int capacity();
void reserve(int new_max_elements);
void shrink_to_fit();
void clear();
void push_back(const T &value);
void pop_back();
void insert(ArrayListIterator position, const T &value);
void erase(ArrayListIterator position);
unsigned int size();
int find(const T &value);
void swap(MyVector &other);
ArrayListIterator begin(){ return ArrayListIterator(0); }
ArrayListIterator end(){ return ArrayListIterator(num_elements); }
};
template
std::ostream &operator(std::ostream &out, MyVector &my_list){
out "[";
for (int i =0; i my_list.size(); i++){
out my_list.at(i)",";
}
out "]";
return out;
}
#include "MyVector.hpp"
#endif
In one of the attached photo, theres the MyVector.hpp, but my insert, copy, operator= and erase functions dont work. I included the MyVector.h file to refer to.Can someone fix these functions for me? And also show me how to implement all of this in the main function, I will like if it works!
Following nonfunctional functions from picture below:
template
const MyVector &MyVector::operator=(const MyVector &rhs){
/*
if (this != &rhs){
clear();
reserve(rhs.capacity());
for (int j =0; j rhs.size(); j++){
push_back(rhs[j]);
}
}
// Finish me!
*/
return *this;
}
template MyVector::MyVector(const MyVector &rhs){
/*
reserve(rhs.capacity());
for (int j =0; j rhs.size(); j++){
push_back(rhs[j]);
}
*/
}
template
void MyVector::insert(ArrayListIterator index, const T &value){
/*
int position =*index;
if (position num_elements){
for (int j = num_elements; j > position; j--){
data[j]= data[j -1];
}
}
data[position]= value;
num_elements = num_elements +1;
if (num_elements == max_elements){
reserve(max_elements *2);
}
return;
*/
}
template void MyVector::erase(ArrayListIterator index){
/*
int position =*index;
if (position num_elements){
for (int j = position; j num_elements -1; j++){
data[j]= data[j +1];
}
num_elements = num_elements -1;
}
*/
}
DONT EDIT HEADER #ifndef MYVECTOR _ H #define

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