Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

We all low that the regular array has wealnesses, such as the size has to be known when declaring it (constant), the indices have to

image text in transcribed

image text in transcribed

We all low that the regular array has wealnesses, such as the size has to be known when declaring it (constant), the indices have to start with zero, there is no boundary checking. Now we would like you to design a customized array type, called Safe Array, to overcome these wealnesses. Even better we want Safe Array be a class template that stores an aray of any type of thing it works on, rather than creating a set of type-specific arrays-an intArray is an array of integers; a floatArray is an array of floats; a catAray is an array of cats. SafeArray is a parameterized template that provides you with the ability to create a general aray class and pass types as parameters to that class to build specific instances. We use the class name SA, short for SafeArray. The SA template class has following features: The memory for array elements is always allocated from dynamic memory area, ie freestore. And the size of array is determined during the run time The index of element s in this array does not have to start with zero. Using wrong index (out of bounds) when accessing array elements will not cause any serious consequences, instead just pop up proper enror messages if the index goes out of bounds. The skeleton of the SA template is as follows, but you need to add and implement the additional member functions listed below it. const int dSize = 10; // default size template class SA I private // pointer of T type int lldx: / low index int hIdx: / high index public: // the following nine member funtions go here SA ( indexed between 0 and 9. [default constructor] )-will allocate a l D T array in freestore with default size of 10 and which can be 1. 2. SA int n -will allocate a 1D T aray in freestore with size of n and which can be 3. 4. SA const SA& arr-will make a separate copy of SafeArray a with the same size 5, indexed between 0 and n1. [1 parameter constructor] SA ( int 1, int h )-will allocate a 1D T array in teestore with size of (h-l+ 1) and which can be indexed between I and h. [2 parameter constructor] and indexing as arr. [copy constructor] operator=( const SAs rhs )-assignment operator -SA ( )-will release the memory space allocated for te ID T array from dynamic memory freestore. [destructor] 6

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

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

Students also viewed these Databases questions

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago