Question: EDIT: What's being requested is an updated code and screenshot for each task ( except for task 1 ) . I ' m sorry, but
EDIT: What's being requested is an updated code and screenshot for each task except for task Im sorry, but that's all the information given. When I say terminal, I mean the terminal that is used for code, you can use another compiler. The parts of the code that tell you to insert in refer to changes you have to make in tasks. Sorry if it's confusing.
Not hard but my terminal isn't working for me Part which is the last part so don't be worried might require some thinking
The following is VectorMain.cpp and Vectorh
VectorMain.cpp
#include
#include
#include "Vectorh
using namespace std;
printing values in a Vector object
void printVectorVector;
int main
Vector myvec;
for int i ; i ; i
myvec.pushbacki ; entering values into myvec;
printVectormyvec; showing contents of myvec
asking for target index and how many times an erase is to happen
at this index;
UNCOMMENT FOR TASK
int target;
int howmany;
cout "Enter index of element to erase myvec.size: ;
cin target;
cout endl;
cout "Erase at this index how many times myvec.size target
: ;
cin howmany;
cout endl;
for int i ; i howmany; i
myvec.erasetarget;
printVectormyvec;
cout endl;
cout endl;
asking for a target index and how many times value is
to be inserted at this index
UNCOMMENT FOR TASK
cout "Enter index of element to insert myvec.size
: ;
cin target;
cout endl;
cout "Insert at this index how many times myvec.size
: ;
cin howmany;
cout endl;
for int i ; i howmany; i
myvec.inserttarget;
printVectormyvec;
cout endl;
return ;
void printVectorVector vec
for int i ; i vec.size; i
cout veci;
cout endl
endl;
Vectorh
#ifndef VECTORH
#define VECTORH
#include
#include
using namespace std;
template
class Vector
public:
Vector
: theSize theCapacity
data new TtheCapacity;
Vectorconst Vector &rhs
: theSizerhstheSize theCapacityrhstheCapacity datanullptr
data new TtheCapacity;
for int k ; k theSize; k
datak rhsdatak;
Vector &operatorconst Vector &rhs
for int k ; k theSize; k
datak rhsdatak;
return this;
~Vector
delete data;
bool empty const
return theSize ;
int size const
return theSize;
int capacity const
return theCapacity;
T &operatorint index
assertindex && index theSize;
return dataindex;
T &back const
return datatheSize ;
T &front const
return data;
void pushbackconst T &x
if theSize theCapacity
cout "within capacity endl;
datatheSize x;
theSize;
else
cout "EXPAND capacity endl;
T moredata new TtheCapacity ;
for int i ; i theSize; i
moredatai std::movedatai;
std::swapdata moredata;
delete moredata;
theCapacity theCapacity ;
datatheSize x;
theSize;
void popback
theSize;
to be added in by you
copy it in
void eraseint index
to be filled by you
return;
to be added in by you
to be written by you
void insertint index, int value
to be filled in a task
return;
private:
int theSize;
int theCapacity;
T data;
;
#endif
Your tasks are as follows:
Task :
Compile and run in a terminal using:
go lab VectorMain.cpp
lab
Task :
Insert the following erase function
void erase int index
assert index && index theSize;
if index theSize
popback;
return;
for int i index ; i theSize; i
datai data i;
popback;
return;
Test it with VectorMain.cpp and MAKE SURE you uncommented the part that says uncomment for task After that, recompile and run again.
Task :
Here is an insert function:
void insertiterator itrs, int value
if itz endl
pushbackvalue;
return;
assertitr begin && itr endl;
pushbackback;
iterator itr end;
iterator itr end;
while itr itr
itritr;
itr;
itr;
itr value;
return;
Add to the class Vector an insert function. Given an index
target and a new value x the insert function is to insert the stated
value at the stated index. The one shown is just for you to get an idea on what to do You will develop this on your own, as you must:
Add a copy of the vector's last back element using
pushback
Beginning at index theSize and ending at the target index,
copy each element to the next index
Place the new value x at the target index.
Test your insert function with the provided VectorMain.cpp file
after uncommenting the relevant portion marked with "UNCOMMENT
FOR TASK
Recompile and run
I sincerely appreciate your assistance.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
