LAB 08A - TRANSPOSE IT
Concepts
If you've taken linear algebra, then you know what the transpose of a matrix is. If not, that's OK, as the concept is pretty simple. Basically the transpose of a matrix is a new matrix where the rows become the columns and the columns become the rows (a reflection). See Wikipedia for more details.
Get Started
Changing the size of an array is easier to do when the numbers of rows and columns are specified as symbolic constants; otherwise the change requires modifications to several statements. Thus, to get started, create two global constants NROWS and NCOLS which are assigned the values 8 and 4, respectively.
Then, in your main()
function, declare a 2D array
that is of size
NROWS and NCOLS.
Transpose It!
In this lab, create the following four functions. Three of the four functions
should have one parameter, a 2D array of size NROWSxNCOLS; the
transpose
function also needs a 2nd 2D array parameter, of size
NCOLSxNROWS.
- A function that reads values into a 2D array from a file. Read the values from this file.
- A function that prints the values in a 2D array. Output a tab between elements in each row.
- A function that transposes the values in a 2D array, assigning the new matrix to the 2nd parameter passed to the function.
- A function that writes values from a 2D array into an output file. Place
the values into a file called
dataOut.txt
.
In summary, your main function should:
- call the read 2D array from file function
- call the print the 2D array function with the matrix read in
- call the transpose function with both the matrix read in and the matrix that will hold the transposed elements
- call the write 2D array to a file function with the transposed matrix