Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++ Create a class called Array that functions as an enhanced array. Following are the properties of Array. It will not allow an index

In C++

Create a class called Array that functions as an enhanced array. Following are the properties of Array. It will not allow an index outside of the array boundary. An exception will be thrown if it does. Indexing is accomplished by overloading the [] operator. Click HERE for help. Array is templated to allow any type. Remember, templated code must be compiled into the code that uses it. It allows the user to specify the range of int indices. Examples of array declarations (throw an exception if the last index is less than the first): Array array1; // default size 0, i.e. no array locations Array array2(20); // size of 20, indices 0 to 19 Array array3(-3,2); //size of 6, indices -3 -2 -1 0 1 2 Pass by value arguments to functions will create a copy of the Array. Functions can return an Array. Assignment is allowed with an exact copy being made: array1=array2; // array1 will also get the starting index of array2 A Resize method changes the Array size. Throw an exception if the argument is < 0, truncate Array if the new size is less than the original. The starting index remains the same. array1.Resize(20); A Size method returns the size of the array cout << array1.Size(); A getStartIndex method returns the starting index of the array cout << array1.getStartIndex(); A setStartIndex method that changes the starting index of the array with everything else staying the same (obviously the last index would be different). array1.setStartIndex(10); A Reverse method returns an Array with its array contents in the opposite order. The original Array is unchanged. array1 = array2.Reverse(); // array2 is unchanged An Ascending method returns an Array with the contents in ascending order. The original Array is unchanged. array1 = array2.Ascending(); // array2 is unchanged A Descending method returns an Array with the contents in descending order. The original Array is unchanged. array1 = array2.Descending(); // array2 is unchanged Array will be in the ArrayNameSpace namespace. Overload the 6 relational operators for the Array class. For simplicity, you can ignore index type and starting index (all arrays really start with index 0 anyway). For two arrays to be equal, they must be exactly equal in size and content. For comparing less and greater, arrays can be of different sizes. For Array A to be less than Array B (A < student submitted image, transcription available below , start at the beginning of each array and return the result as soon as the ith element differs (be sure to not run off the end of one of the arrays). The other 4 relational operators can be built using == and < with the this pointer. Note: Arrays must be of the same type to be compared (for example both int) or the compiler will flag an error (this is to be expected). Additional Notes You are not allowed to use the STL (Standard Template Library). Exceptions thrown will be the out_of_range standard exception. Use const methods and const arguments where appropriate. Turn in your program with the prog3main.cpp in the class directory as your main.cpp and comment out anything that doesn't work. Repeat... your main program will be in main.cpp. This should NOT be the only testing you do, but this is what you will turn in. Again, comment out anything that you didn't implement or doesn't work. You can also see the program by clicking HERE and the result of the execution by clicking HERE. The class definition and implementation must be in array.h.

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

Building Database Driven Catalogs

Authors: Sherif Danish

1st Edition

0070153078, 978-0070153073

More Books

Students also viewed these Databases questions