Question: Edit: Please write this in C++. Edit: Ignore the figures mentioned in the question. They are not actually needed. (Overloading the Parentheses Operator) One nice

Edit: Please write this in C++.

Edit: Ignore the figures mentioned in the question. They are not actually needed.

(Overloading the Parentheses Operator) One nice example of overloading the function call operator () is to allow another form of double-array subscripting popular in some programming languages. Instead of saying

 chessBoard[ row ][ column ] 

for an array of objects, overload the function call operator to allow the alternate form

 chessBoard( row, column ) 

Create a class DoubleSubscriptedArray that has similar features to class Array in Figs. 10.10 10.11. At construction time, the class should be able to create a DoubleSubscriptedArray of any number of rows and columns. The class should supply operator() to perform double-subscripting operations. For example, in a 3-by-5 DoubleSubscriptedArray called chessBoard, the user could write chessBoard(1, 3) to access the element at row 1 and column 3. Remember that operator() can receive any number of arguments. The underlying representation of the DoubleSubscriptedArray could be a single-subscripted array of integers with rows * columns number of elements. Function operator() should perform the proper pointer arithmetic to access each element of the underlying array. There should be two versions of operator()one that returns int & (so that an element of a DoubleSubscriptedArray can be used as an lvalue) and one that returns int. The class should also provide the following operators: ==, !=, =, << (for outputting the DoubleSubscriptedArray in row and column format) and >> (for inputting the entire DoubleSubscriptedArray contents).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!