Question: Dynamic array - C++ I need help implementing these functions please. The Main has already been filled out and I am just struggling to complete

Dynamic array - C++ I need help implementing these functions please. The Main has already been filled out and I am just struggling to complete these functions. The comments in each function specify exactly how the function should work. Try using the iostream library to complete the functions. Thank you. Code: Dynamic array - C++ I need help implementing these functions please. The

Main has already been filled out and I am just struggling to

complete these functions. The comments in each function specify exactly how the

function should work. Try using the iostream library to complete the functions.

#include using namespace std; 1 2 3 4 5 6 7 8 const int DEFAULT_CAPACITY = 10; //Default capacity of the dynamic array 10 11 class DynamicArray ( private: int capacity; int _size; int* elements; // Defines the maximum number of elements that this DynamicArray can hold //Keeps track of the current number of elements inserted into this DynamicArray //Pointer to the array where the elements are inserted. public: * Default constructor */ DynamicArray(); //Initialize 'capacity' to DEFAULT_CAPACITY //Allocate memeory for DEFAULT_CAPACITY number of integers and point the allocated memory by 'elements 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 * Regular constructor DynamicArray (const int capacity); * Copy constructor DynamicArray (const DynamicArray); * Move constructor. DynamicArray (DynamicArray&&); TH Copy assignment of the dynamic array. 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 DynamicArrays operator (const DynamicArray); * Move assignment. DynamicArray& operator = (DynamicArray&&); * Destructor --DynamicArray(); bool empty(); //Return true, if the array does not contain any element. 61 62 63 64 int size() const; // Return the number of elements that have been inserted into the array. 65 int capacity() const; // Return the capacity of the dynamic array. 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 void insert (const int element); //Check whether the array is full or not. //If array is full, create a new array with double capacity. 11 Copy the elements from the old array to the new array. Release memory from the old array. Assign new array pointer to the old array pointer. //Insert the new element at the end of the array and increment the size. 82 83 84 85 86 87 88 89 90 int search(int element); //Loop through the elements of the dynamic array. // Compare each element of the array with 'element'. //If an element matches with the element return the index of the element in the array. //If no such element is found, return -1. si si si o si o int elementAt (const int index) const; // Return the element from the array at the 'index' // Return -1, if the 'index' is out of boud. 95 96 97 98 99 void erase (const int element); // Search the element to be erased. //If found move all other elements that are on the right of this element to one position left. //Decrease the size. void clear(); //Remove all the elements from the array but keep the memory allocated to the array intact. 100 101 102 103 104 105 106 107 108 109 110 lll 112 113 114 void show(); // Print all the elements of the array in a line separated by space. }

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!