Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Templates and Exceptions Here is the definition for a CheckedArray class and the implementation of one of its constructors and the length function: template class

Templates and Exceptions Here is the definition for a CheckedArray class and the implementation of one of its constructors and the length function: template class CheckedArray { public: CheckedArray(); CheckedArray(int size); ~CheckedArray(); T& operator[](int index) throw (ArrayOutOfRange); int length(); private: T *p; int size; }; template CheckedArray::CheckedArray() : size(10) { p = new T[size]; } template int CheckedArray::length() { return size; } This class behaves like a template version of an array where we set the template type to the data type we would like to store in the array. If ary is a variable of type CheckedArray and i is an illegal index then ary[i] should throw the exception ArrayOutOfRange. Complete the rest of the implementation of CheckedArray. Note that [] is an overloaded member operator of the class, not a friend. It should return the element from p at the index parameter. The destructor should free up the memory allocated in the constructor. Define the ArrayOutOfRange class so it contains the illegal index that caused the exception. Write code in main that tests your CheckedArray class with a test that causes an exception and a test that does not. When an exception occurs, the illegal index should be output from the exception object.

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_2

Step: 3

blur-text-image_3

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

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

Students also viewed these Databases questions

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago