Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CSC326- Fall 2017, Prof. X. Zhang Homework #01 SafeArray Template Credit: 10 pts, DUE: 9/12/17 We all know that the regular array has weaknesses, such

image text in transcribed

image text in transcribed

CSC326- Fall 2017, Prof. X. Zhang Homework #01 SafeArray Template Credit: 10 pts, DUE: 9/12/17 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, ie. 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 SA f private: // pointer of T type T* pT: int 1Idx; / low index int hIdx; // high index public: the following nine member funtions go here 1. )-will allocate a l D T array in freestore with default size of 10 and which can be SA ( indexed between 0 and 9. [default constructor] SA ( int n) - will allocate a ID T array in freestore with size of n and which can be indexed between O and n - 1. [1 parameter constructor] 2. Il allocate a which can be indexed between / and h. [2 parameter constructor] SA ( const SA & arr )-will make a separate copy of SafeArray a with the same size and indexing as arr. [copy constructor] 4, 5. operator-( const SA& rhs) - assignment operator. 6. -SA ( )-will release the memory space allocated for the ID T array from dynamic memory freestore. [destructor)

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

DB2 11 The Database For Big Data And Analytics

Authors: Cristian Molaro, Surekha Parekh, Terry Purcell, Julian Stuhler

1st Edition

ISBN: 1583473858, 978-1583473856

More Books

Students also viewed these Databases questions

Question

Who receives the income from the production of goods and services?

Answered: 1 week ago

Question

Likes confrontation or avoids it?

Answered: 1 week ago

Question

Describe the menstrual cycle in a woman.

Answered: 1 week ago

Question

Explain methods of metal extraction with examples.

Answered: 1 week ago