Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

using c++ language We all know that the regular array has weaknesses, such as the size has to be known when declaring it (constant), the

using c++ language

image text in transcribed

image text in transcribed

We all know that the regular array has weaknesses, 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 SafeArray, to overcome these weaknesses. Even better we want SafeArray be a class template that stores an array 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 catArray is an array of cats. SafeArray is a parameterized template that provides you with the ability to create a general array 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, i.e. freestore. And the size of array is determined during the run time. The index of elements 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 error 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 SAP private: // pointer of T type int lIdx; // low index int hIdx; // high index public: // the following nine member funtions go here T* PT; }; 1. SA( ) - will allocate a ID T array in freestore with default size of 10 and which can be indexed between 0 and 9. [default constructor] 2. SA( int n ) - will allocate a ID T array in freestore with size of n and which can be indexed between 0 and n - 1. [1 parameter constructor] 3. SA( int 1, int h ) - will allocate a ID T array in freestore with size of (h - 1+1) and which can be indexed between 1 and h. [2 parameter constructor] 4. SA( const SA& arr ) - will make a separate copy of SafeArray a with the same size and indexing as arr. [copy constructor] 5. operator=( const SA& rhs ) - assignment operator. 6. -SA( ) - will release the memory space allocated for the 1D T array from dynamic memory freestore. [destructor) 7. operator[ ] ( int offset ) - will allow user to treat SA names as if they were regular array names. You will need two version of it, one for read, the other for write. 8. getSize() member function will return the number of elements in SA. 9. operator arr (100); to declare a SA array of 100 floats, that may look some awkward. In order to practice the SA template with user definced types, you will need to have a Cat class defined and implemented. This will allow user to define a SafeArray of Cats. You will also need to write a driver (main) function with at least three different types of SafeArray (say SA intArr, SA dArt, and SA catArr ) to test all of these class member functions, overloaded operators

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

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

More Books

Students also viewed these Databases questions