Question: I need help on exercise 1 on building my vector, I will provide my code below but can anyone help me improve my code based

 I need help on exercise 1 on building my vector, I

I need help on exercise 1 on building my vector, I will provide my code below but can anyone help me improve my code based on exercise 1?

#ifndef VECTOR_H_INCLUDED #define VECTOR_H_INCLUDED

#include #include #include #include

template

class Vector

{ public: explicit Vector(int initSize = 0): theSize{init Size}, theCapacity{initSize + SPARE_CAPACITY} { data = newdata[theCapacity]; }

Vector( const Vector & rhs) : theSize{rhs.theSize}, theCapacity{rhs.theCapacity}, data{nullptr} { data = new data [theCapacity]; for (int k = 0; k

Vector & operator= (const Vector & rhs) { Vector copy = rhs; std::swap(*this, copy); return *this; }

~Vector() { delete[ ] data; }

Vector(Vector && rhs) : theSize{rhs.theSize}, theCapacity{rhs.theCapacity}, data{rhs.data} { rhs.data= nullptr; rhs.theSize= 0; rhs.theCapacity= 0; }

Vector & operator= (Vector && rhs) { std::swap( theSize, rhs.theSize); std::swap( theCapacity, rhs.theCapacity); std::swap(data, rhs.data);

return *this; }

void resize(int newSize) { if(newSize > theCapacity) reserve(newSize * 2); theSize= newSize; }

void reserve( int newCapacity) { if(newCapacity

data *newArray = new Object[newCapacity]; for (int k = 0; k

theCapacity = newCapacity; std::swap(objects, newArray); delete[] newArray;

}

data & operator[](int index) { return size() == 0; } const data & operator [](int index) const { return data[index]; }

bool empty() const { return size() == 0; }

int size() const { return theSize; }

int capacity() const { return theCapacity; }

void push_back(const data & x) { if(theSize == theCapacity) reserve(2 * theCapacity + 1); data[ theSize++ ]= x; }

void push_back(data && x) { if(theSize == theCapacity) reserve(2 * theCapacity + 1); data[theSize++] = std::move(x); }

void pop_back() { --theSize; }

const data & back () const { return data[theSize -1]; }

typedef data * iterator; typedef const data * const_iterator;

iterator begin() { return &objects [0]; }

const_interator begin() const { return &data[0]; }

iterator end() { return &data[size()]; } const_interator end() const { return &data[size()]; }

static const int SPARE_CAPACITY = 16;

private: int theSize; int theCapacity; T*data;

};

CSE 2020 LABORATORY -- Week 2 - Spring 2021 Instructor: Kerstin Voigt This lab will have you do the hard labor of reproducing a C++ implementation of the Vector ADT. The implementation closely follows the one in Chapter 2 of Weiss, Data Structures and Algorithm Analysis in C++. However, the instructor made a few modifications: Vector anothervec (myvec): for (int i = 0; i STL o We will write ' instead of ''. The private data member 'object' is renamed to 'data'. Vector yetanother = anothervec; for (int i = 0; i #include "Vector.h" using namespace std; return 0 ) void print_vector (const Vector int>& v) cout Exercise 2: Test your Vector implementation with an Application. Download from Blackboard the MaxSubSumMain.cpp program. Compile and run it. The sample input to be used by all for uniform testing is in file lab2ex2_input.txt. Place this file in the same directory as program. CSE 2020 LABORATORY -- Week 2 - Spring 2021 Instructor: Kerstin Voigt This lab will have you do the hard labor of reproducing a C++ implementation of the Vector ADT. The implementation closely follows the one in Chapter 2 of Weiss, Data Structures and Algorithm Analysis in C++. However, the instructor made a few modifications: Vector anothervec (myvec): for (int i = 0; i STL o We will write ' instead of ''. The private data member 'object' is renamed to 'data'. Vector yetanother = anothervec; for (int i = 0; i #include "Vector.h" using namespace std; return 0 ) void print_vector (const Vector int>& v) cout Exercise 2: Test your Vector implementation with an Application. Download from Blackboard the MaxSubSumMain.cpp program. Compile and run it. The sample input to be used by all for uniform testing is in file lab2ex2_input.txt. Place this file in the same directory as program

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!