Get Instant Help From 5000+ Experts For
question

Writing: Get your essay and assignment written from scratch by PhD expert

Rewriting: Paraphrase or rewrite your friend's essay with similar meaning at reduced cost

Editing:Proofread your work by experts and improve grade at Lowest cost

And Improve Your Grades
myassignmenthelp.com
loader
Phone no. Missing!

Enter phone no. to receive critical updates and urgent messages !

Attach file

Error goes here

Files Missing!

Please upload all relevant files for quick & complete assistance.

Guaranteed Higher Grade!
Free Quote
wave
How to Create and Use an Array2Int Class in C++

Private Member Functions of Array2Int Class

Your class will also have the following private member function:void copy (const Array2Int& to_copy); bool invariant () const;Perform the following steps:

1. Create the Array2Int class with the appropriate variables. For each member function, writean interface specification.2. Add a default constructor that creates an array with 0 rows and 0 columns. There will be noelements in the array, so they do not need to be initialized.

3. Add a constructor that creates an array with the number of rows and columns specified as tothe parameters. Do not initialize the elements in the array. In Part B, we will convert this classto a template class and the array elements will be initialized when the default constructor isautomatically invoked.

4. Add a constructor that creates an array with the number of rows and columns specified as tothe parameters. Set all the elements in the array the specified starting value.

5. Add a copy function that copies the values from another Array2Int. Dynamically allocate anew array, copy in the array values, and copy the values of any other member variables.

6. Add a destructor, copy constructor, and assignment operator. Perform deletions and copying asappropriate.

Remember: You must use delete[] (with the []) when deleting an array.

Remember: The assignment operator must check for self-assignment and return

*this.

7. Add an isEmpty function that returns whether the array contains exactly 0 elements.

8. Add getRowCount and getColumnCount functions that return the dimensions of the array.

9. Add the non-const version of the at function that returns an element of the array by nonconst reference. Use asserts to ensure that the specified element is inside the array.Note: Returning a value by non-const reference means that it can be changed by clientcode and the change will change the value in the array. For example:Array2Int my_array(2, 3);my_array.at(1, 1) = 4; // changes my_arraycout << my_array(1, 1); // prints 4

Note: Operator overloading would allow us to access the array using [][] notation, butit is harder. For an explanation, see Part E below.10. Add a const version of the at function. The logic should be the same as the non-const version, but the value returned should be const.

Note: The compiler will automatically invoke the const version of the function for

const Array2Int instances and the non-const version for non-const instances.

Creating the Array2Int Class

The result is that it will be possible to edit the elements in a non-const array but not in

a const array, which is the behaviour we want.

11. Add a class invariant and an invariant function to check it. The class invariant requires that

the array/pointer is not nullptr (or NULL). Check the invariant in the appropriate places.

12. Test your Array2Int class with the Main6A.cpp file on the course website.Part B: The Array2<> Template Class [3 / 50 marks for code, 3 / 50 marks for output]

In Part B, you will convert a copy of the Array2Int class to a template class named Array2.

Your class will have the following public member functions:

Array2 (); Array2 (unsigned int rows1, unsigned int columns1); Array2 (unsigned int rows1, unsigned int columns1, const ItemnType& starting_value); Array2 (const Array2& to_copy); ~Array2 (); Array2& operator= (const Array2& to_copy); bool isEmpty () const; unsigned int getRowCount () const; unsigned int getColumnCount () const; const ItemType& at (unsigned int row, unsigned int column) const; ItemType& at (unsigned int row, unsigned int column);

Your class will also have the following private member function:

void copy (const Array2& to_copy); bool invariant () const;

Perform the following steps:

1. Create a copy of the Array2Int class named Array2. Do not just change the Array2 class;you must hand in both classes.

2. Convert the Array2 class to be a template class. Instead of storing elements of type int, itshould store array elements of any single type. Call your template parameter ItemType. Donot change the unsigned ints that represent the dimensions of the array.

3. Adjust your program so that the Array2 type will compile correctly. There are at least 2 waysto do this and you may use either:

Explicitly list the specialization types for Array2 in Array2.cpp, as shown in thelabs. You will need to declare Array2 variables for the int, double, and float types.

Change the file extension on Array2.cpp to .inl to indicate to the compiler that itshould not be compiled. If you are using Visual Studio, you may need to remove the filefrom the project (right click on file name, Exclude From Project) and re-add it (Project ->Add Existing Item…) before the Visual Studio stops trying to compile it.Add an #include for your source file at the bottom of your Array2.h file, after theclass definition:

#include "Array2.inl" Also add #pragma once to the top of the Array2.inl file, just l

support
close