Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++ For this assignment you will implement a dynamic array. You are to build a class called MyDynamicArray. Your dynamic array class should manage

In C++

For this assignment you will implement a dynamic array. You are to build a class called MyDynamicArray. Your dynamic array class should manage the storage of an array that can grow and shrink. The public methods of your class should be the following: MyDynamicArray(); Default Constructor. The array should be of size 2. MyDynamicArray(int s); For this constructor the array should be of size s. ~MyDynamicArray(); Destructor for the class. int& operator[](int i); Traditional [] operator. Should print a message if i is out of bounds and return a reference to a zero value. void add(int v); increases the size of the array by 1 and stores v there. void del(); reduces the size of the array by 1. int length(); returns the length of the array. int clear(); Frees any space currently used and starts over with an array of size 2.

The output should be:

Doubling to : 4 Doubling to : 8 Doubling to : 16 Doubling to : 32 Doubling to : 64 Doubling to : 128 The sum is : 4950 Reducing to : 64 Reducing to : 32 Reducing to : 16 Out of bounds reference : 60 Doubling to : 20 Doubling to : 40 Doubling to : 80 Doubling to : 160 Doubling to : 320 The sum is : 20185 Reducing to : 160 Reducing to : 80 Reducing to : 40 Out of bounds reference : 60 Doubling to : 80 Doubling to : 160 Doubling to : 320 The sum is : 20195

This is the sample main file:

#include using namespace std; #include "MyDynamicArray.cpp" int main() { MyDynamicArray x; for (int i=0; i<100; 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

The Database Relational Model A Retrospective Review And Analysis

Authors: C. J. Date

1st Edition

0201612941, 978-0201612943

More Books

Students also viewed these Databases questions