Question: Write a class that will convert a matrix row/column coordinate to an index and vice versa. Definition An n x m matrix is a matrix

Write a class that will convert a matrix row/column coordinate to an index and vice versa.

Definition An n x m matrix is a matrix with n columns and m rows.

1 x 1 Matrix 2 x 1 Matrix 1 x 2 Matrix 2 x 2 Matrix 3 x 2 Matrix 2 x 3 Matrix 3 x 3 Matrix . . . n x m Matrix
0
0 0
0 1
0 0 1
0
0 0
1 1
0 1
0 0 1
1 2 3
0 1 2
0 0 1 2
1 3 4 5
0 1
0 0 1
1 2 3
2 4 5
0 1 2
0 0 1 2
1 3 4 5
2 6 7 8

Problem Each row/column element can be assigned an index like the matrices in the examples above. We want to be able to access any element by a row/column coordinate or by an index. Sometimes we need to convert a row/column coordinate to an index or convert an index to a row/column coordinate.

Solution

  1. Write a matrix coordinate/index converter class with the methods below.
    • Methods
      • Constructor - Accepts a number of rows and a number of columns to initialize the dimensions of the matrix
      • indexToColumn - Converts an index to its corresponding column
      • indexToRow - Converts an index to its corresponding row
      • rowColumnToIndex - Converts a row/column coordinate to its corresponding index
  2. Write a program using your class to test that the converter works for any n x m matrix.

Notes

Do NOT create the matrix. This should only convert an index to a row and column and convert a row and column to an index.

I have been working on this for well over 12 hours. I have the program to write the matrix/array. However, it is in my main folder, and not in a 'constructor'. I have no idea how to find an element in the array (the indexToColumn etc.).

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!