Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I just need help with the following two parts of this code. I will post the DynamicArray.cpp and Main.cpp that runs it. Can you please

I just need help with the following two parts of this code. I will post the DynamicArray.cpp and Main.cpp that runs it. Can you please just help me with these requirements

implement a dynamic array by completing the class called MyDynamicArray. The MyDynamicArray class should manage the storage of an array that can grow and shrink.You should complete the class by writing the add and del methods. When you need to grow the array size, the add method should print out the message Doubling to : followed by the new size of the array. When the del method shrinks the size of the array, print out the message Reducing to : followed by the new size of the array.

--------------------------------------------------------------------------------------------

#include using namespace std; class MyDynamicArray { private: int size, capacity, error, *a; public: MyDynamicArray() { a = new int[capacity = 2]; size = error = 0; } MyDynamicArray(int s) { a = new int[capacity = size = s]; error = 0; } ~MyDynamicArray() { delete[] a; } int& operator[](int i){ if (i>=size || i < 0) {cout << "Out of bounds reference : " << i << endl; return error;} return *(a+i); } void add(int v) { /* Your code goes here */ } void del() { /* Your code goes here */ } int length() { return size;} void clear() { delete a; a = new int[capacity=2]; size = 0; } };

-------------------------------------------------------------------------------------------

#include using namespace std; #include "MyDynamicArray.cpp"

void foo(MyDynamicArray param) { for(int i=0; i

int main() { MyDynamicArray x; for (int i=0; i<130; i++){ x.add(i); } int sum = 0; for (int i=0; i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Larry Ellison Database Genius Of Oracle

Authors: Craig Peters

1st Edition

0766019748, 978-0766019744

More Books

Students also viewed these Databases questions