Question: Change CArray as follows Replace the fixed size array with a dynamic array Add a constructor that passes the size of the array as a

Change CArray as follows

Replace the fixed size array with a dynamic array

Add a constructor that passes the size of the array as a parameter

Add a function that copies a dynamic array into this array.

Add a copy constructor to CArray

Add a function that displays the array to a arbitrary stream

Derive CSortedArray from CArray

Add functions that enter elements into the array in sorted order

Override any base class functions that insert elements out of order.

*Note: I need help to write out this problem in C++ while using Visual Studio 2017 and need a main.cpp

//CArray.h

#pragma once template class CArray { public: //constructors CArray(); //destructors ~CArray();

//predicates bool isFull(); bool isEmpty();

//accessors int getPopulation(); int getCapacity();

//custom methods void fill(const Type& value); int find(const Type& value); bool insertAt(const Type& new_item, int new_position); void show(); private: int population; int capacity; Type elts[16]; }; template CArray::CArray() { population = 0; capacity = 16; } template CArray::~CArray() { population = 0; } template void CArray::fill(const Type& value) { for (int i = 0; i < population; ++i) elts[i] = value; } template int CArray::find(const Type& value) { int i = 0; for (i = 0; i < population && elts[i] != value; ++i) ; if (i == population) i = -1; return i; } template int CArray::getCapacity() { return capacity; } template int CArray::getPopulation() { return population; } template bool CArray::insertAt(const Type& new_elt, int new_position) { if (capacity <= population) return false; if (new_position < 0 || population < new_position) return false;

//move the elements from new position to population - 1 down one position for (int i = population - 1; i >= new_position; --i) elts[i + 1] = elts[i]; elts[new_position] = new_elt; population++; return true; } template bool CArray::isEmpty() { return population <= 0; } template bool CArray::isFull() { return capacity <= population; } template void CArray::show() { for (int i = 0; i < population; ++i) cout << elts[i] << ' '; }

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!