Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need this question done in C program And plz give me complete working code. Also provide me screenshot of the output there is no
I need this question done in C program
And plz give me complete working code.
Also provide me screenshot of the output
there is no way for me to provide code with text format becuase file doesnot change and my i cant even copy and paste it
Below is the mf-generate code and you can study that
Below is the mf-transpose code where you have edit it
Exercise 2. (50 points) Matrix ADT To handle matrices of any size in C, we can define an abstract data type (ADT) by #define typedef struct Matrix I TElement int unsigned nt nrow; unsigned nt ncol; TElement *data TMatrix; where nrow and ncol are numerical attributes representing the numbers of rows and columns of the matrix and data is a pointer to an array of row pointers. Each ow pointer points to an array of elements of TElement type. TElen s defined as int. One can design an API that has a number of C functions to operate on the ADT. For example, the following API functions can create a new matrix, read a matrix from a file, free a matrix, transpose a matrix, and write a matrix to a file: TMatrix newMatrix (unsigned int nrow, unsigned int nco TMatrix readMatrix (char filename) void TMatrix transposeMatrix (TMatrix m): void freeMatrix (TMatrixm) writeMatrix (TMatrix char .filename) Perhaps unsurprisingly, the ADT has overtones of object oriented programming. Indeed, ne Matrix) and readMatrix) look like constructors (they create a TMatrix!) while freeMatrix) feels like a destruc- tor /finalizer. The other two functions that transpose a matrix and write a matrix to a file both take a THatrix value as argument and therefore look and feel like methods. When reading a matrix from or writing a matrix to a file, the file has the following format: 1. An unsigned integer nrows indicating the number of rows. It has 4 bytes. 2. An unsigned integer ncols indicating the number of columns. It has 4 bytes. 3. Rows, starting from row 0 to row nrows-1. Each row has ns integers. Each integer has 4 bytes. A program nf-generate is provided to generate matrices. Study the source code. It helps you understand the format of the matrix data file. It also serves as an example of writing integers to a file. In this exercise, you must implement the above API functions for the matrix ADT. The functions are in nf-transpose.c. The main function calls API functions to read a matrix from a file, transpose it and write the transpose to a new file. It should not be modified. All your changes should be done to the functions manipulating the matrix ADT. Read the comments in the template carefully The following session shows how a matrix is generated, transposed, and transposed again. mf-generate generates matrix.out. mf-transpose transposes matrix.out to matrix.out.out. Then mf-transpose transposes matrix.out.out to matrix.out.out.out, which should be the same as matrix.out. This is confirmed below by the matching md5sun hash codes of the matrix.out and matrix.out.out.out files. . /mt-generate 5000 300 s /mf-transpose matrix.out s Imf-transpose matrix.out.out $ md5sum matrix.out* 85d2b8a7563192bf 1142afbd6d7e2efd matrix.out e823612e9e677b08647ade892fdc17c3 matrix.out.out 85d2b8a7563192bf 1142afbd6d7e2efd matrix.out.out.out Exercise 2. (50 points) Matrix ADT To handle matrices of any size in C, we can define an abstract data type (ADT) by #define typedef struct Matrix I TElement int unsigned nt nrow; unsigned nt ncol; TElement *data TMatrix; where nrow and ncol are numerical attributes representing the numbers of rows and columns of the matrix and data is a pointer to an array of row pointers. Each ow pointer points to an array of elements of TElement type. TElen s defined as int. One can design an API that has a number of C functions to operate on the ADT. For example, the following API functions can create a new matrix, read a matrix from a file, free a matrix, transpose a matrix, and write a matrix to a file: TMatrix newMatrix (unsigned int nrow, unsigned int nco TMatrix readMatrix (char filename) void TMatrix transposeMatrix (TMatrix m): void freeMatrix (TMatrixm) writeMatrix (TMatrix char .filename) Perhaps unsurprisingly, the ADT has overtones of object oriented programming. Indeed, ne Matrix) and readMatrix) look like constructors (they create a TMatrix!) while freeMatrix) feels like a destruc- tor /finalizer. The other two functions that transpose a matrix and write a matrix to a file both take a THatrix value as argument and therefore look and feel like methods. When reading a matrix from or writing a matrix to a file, the file has the following format: 1. An unsigned integer nrows indicating the number of rows. It has 4 bytes. 2. An unsigned integer ncols indicating the number of columns. It has 4 bytes. 3. Rows, starting from row 0 to row nrows-1. Each row has ns integers. Each integer has 4 bytes. A program nf-generate is provided to generate matrices. Study the source code. It helps you understand the format of the matrix data file. It also serves as an example of writing integers to a file. In this exercise, you must implement the above API functions for the matrix ADT. The functions are in nf-transpose.c. The main function calls API functions to read a matrix from a file, transpose it and write the transpose to a new file. It should not be modified. All your changes should be done to the functions manipulating the matrix ADT. Read the comments in the template carefully The following session shows how a matrix is generated, transposed, and transposed again. mf-generate generates matrix.out. mf-transpose transposes matrix.out to matrix.out.out. Then mf-transpose transposes matrix.out.out to matrix.out.out.out, which should be the same as matrix.out. This is confirmed below by the matching md5sun hash codes of the matrix.out and matrix.out.out.out files. . /mt-generate 5000 300 s /mf-transpose matrix.out s Imf-transpose matrix.out.out $ md5sum matrix.out* 85d2b8a7563192bf 1142afbd6d7e2efd matrix.out e823612e9e677b08647ade892fdc17c3 matrix.out.out 85d2b8a7563192bf 1142afbd6d7e2efd matrix.out.out.out
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started