Answered step by step
Verified Expert Solution
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
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 templateStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started