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.
|
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
- 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
- Methods
- 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
Get step-by-step solutions from verified subject matter experts
