Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

here is dynamicarray.h: ****************************************** #include #include #includeDynamicArray.h DynamicArray::DynamicArray(int size) { if (size > 0) { _size = size; _array = new int[size]; std::cout } else

here is dynamicarray.h:

******************************************

#include

#include

#include"DynamicArray.h"

DynamicArray::DynamicArray(int size)

{

if (size > 0)

{

_size = size;

_array = new int[size];

std::cout

}

else

_array = nullptr;

}

DynamicArray::~DynamicArray()

{

delete [] _array;

std::cout

}

int& DynamicArray::at(int i)

{

if(i = _size)

{

throw std::out_of_range{"Array index out of range."};

}

return _array[i];

}

***********************************************

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

An "Elastic" Array In lab, you created a DynamicArray class that allows an array of any size to be created at runtime. The class used the concept of RAll by utilizing a destructor to ensure that the dynamically-allocated internal storage array was properly deleted when it left memory In this exercise, you will create an ElasticArray that will be able to grow or shrink on demand (much like std: :vector), and then explore how iterators are designed by wrapping an observing pointer to the ElasticArray 's internal storage. Create ElasticArray Start by copying the DynamicArray code you created for the in-lab assignment into a new header and implementation file pair (ElasticArray.h and ElasticArray.cpp). Change all references to DynamicArray to ElasticArray by careful use of find-and-replace. Your class interface should now look like this class ElasticArrayf public: ElasticArray (int size) int size() const f return size; ) int& at(int i) BlasticArray) private: int*-array nullptr; int size0; Create a new, empty main testing program for this project. Add the code necessary to verity that the ElastieArray class works the same as the DynamieArray class from the lab. (Here, you are just verifying that no mistakes were introduced during the re-naming procedure.) ElasticArray Description When you are finished, the ElasticArray class will be able to do these things that the DynamicArray class could not do: ElasticArray will be default-constructable ElasticArray will be copy-constructable. ElasticArray will be copy-assignable and will exhibit correct 'by-value" semantics. ElasticArray will implement: a push back method that will allow new items to be added at the end of the array. front ) and back ) methods that will allow the items at the front and back (respectively) of the array to be accessed a pop back ) method that will return the value of the item at the back of the array and then remove that item from the array. a shrink_to fit() method that will reduce the internal storage of the object to exactly match the current logical array size Now we will look at some details about how to make each of these features a reality. Notice that we will not necessarily implement them in the order they are listed. Sometimes it is better to choose an order of implementation that will allow you more freedom to test and debug incrementally as you go along

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What has been your desire for leadership in CVS Health?

Answered: 1 week ago

Question

Question 5) Let n = N and Y Answered: 1 week ago

Answered: 1 week ago