Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Description: Dual - Scripted Array Class in C + + . I have one header file. now I have to make another file in which

Description: Dual-Scripted Array Class in C++. I have one header file. now I have to make another file in which I have to Satisfy all the requirements of the question. In the third file which contains main function which is the test drive file in which I have to test all the functionality of the program.
I want to make a running program which satisfy all the requirements in C++.
1. Create class DSArray (Dual-Scripted Array). Please name the class DSArray for consistency. 2. The underlying (abstracted) memory management for DSArray should be implemented as a sparse list. That is to say, array elements are only created when accessed for the first time. When the initial DSArray object is created, the input parameters (i.e. constructor parameters) are only used to determine the maximum size of the array, but no memory is actually allocated for any array elements. 3. A DSArray object can be of any arbitrary size, in 2 dimensions. During development and testing, it is highly recommended that you keep it small (say,10x10)4. Abstraction and Encapsulation are implemented by how you represent your underlying data structure to contain only elements of the array that have been accessed. You can use ANY data structure, but keep in mind that the data structure you use needs to be dynamically adjustable; if new indexes are accessed (written), increase memory usage, if array is made smaller, decrease memory usage. 5. At construction time, the DSArray class should be able to create an array of any number of elements in each of the dimensions (i.e. number of rows and columns)(i.e. initialization constructor), or provide a default size (i.e. default constructor).6. The DSArray class should supply operator() to perform index operations. For example, in a MxN DSArray called myArray, the user could write a myArray(10,5) to access the element at row 10, column 5. NOTE: the element myArray(0,0) does not exist, and should return 0. The first element will be myArray(1,1).7. Provide public accessors in the form of the following overloaded operators. Please note that for Java and python you should overload the equivalent operators or methods a.==(equality - always return FALSE for different-sized arrays) b.!=(inequality - always return TRUE for different-sized arrays) c.=(assignment)- The assignment operator will dynamically re-size the lvalue array to the size of the rvalue array, and assign all the values of the lvalue elements to the rvalue values. d.<<(ostream - for outputting the array in row and column format) e.()(for accessing individual elements of the array. Note that you cannot overload the square brackets[] for this class, because operator[] allows only one parameter, whereas operator() allows any number of parameters ). For example, in a MxN DSArray called myArray, the user could write a myArray(1,2) to access the element at row 1, column 2. Generally, any access to a subscript out of range should throw and exception, and should be caught by the client and handled. For an MxN array, valid indexes are 1-M and 1-N; 8. You must implement a ChangeSize() method. This will dynamically change the size of the array in any or all dimensions. When the array is made larger in any dimension, existing elements will not be affected; only the valid index references (array size) will change. When the array is made smaller in any dimension, existing elements will be truncated (pruned) in that dimension. 9. Implement a proper copy constructor so that it may be passed by value to/from a function. 10. You must implement a test driver to demonstrate that your DSArray class is working. Therefore, the test driver must have explicit output indicating proper operation. You must test ALL overloaded operators, the ChangeSize() method, and the copy constructor.
I have a header file DSArray.h :
#ifndef _TS_INT_ARRAY
#define _TS_INT_ARRAY
#include
#include
using std::ostream;
using std::istream;
using std::cout;
using std::endl;
using std::cin;
class DSArray {
friend ostream &operator<<( ostream&, DSArray & );
public:
DSArray(int rows=5, int cols=5);
DSArray(const DSArray &);
~DSArray();
void changeSize(unsigned int rows, unsigned int cols);
int numElements();
int &operator()(unsigned int row, unsigned int col);
DSArray &operator=(DSArray &c);
bool operator==(const DSArray &c);
bool operator!=(const DSArray &c);
private:
unsigned int numRows;
unsigned int numColumns;
};
#endif _TS_INT_ARRAY

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

Privacy In Statistical Databases International Conference Psd 2022 Paris France September 21 23 2022 Proceedings Lncs 13463

Authors: Josep Domingo-Ferrer ,Maryline Laurent

1st Edition

3031139445, 978-3031139444

More Books

Students also viewed these Databases questions

Question

Discuss all branches of science

Answered: 1 week ago

Question

Understanding Group Leadership Culture and Group Leadership

Answered: 1 week ago