Question: For this computer assignment, you are to write and implement a C++ program to implement the matrix multiplication on randomly generated integers stored in data

For this computer assignment, you are to write and implement a C++ program to implement the matrix multiplication on randomly generated integers stored in data files.

Put the implementations of your subroutines (described below) in your source file sub02.cc. NOTE: You will need to create this file, you will need to do a git add sub02.cc, once you create it in your local repository and it will then be added to your GitHub repostority after you do a git commit and git push. NOTE: The repository as is will not compile to an executable at the start due to missing functions.

  • void open_files(ifstream &is1, ifstream &is2): Opens two data files for reading and creates the input streams is1 and is2. If either file fails to open, it prints an error message on stderr and aborts the program with a non-zero exit value. The names of the input files are assignment02a.dat and assignment02b.dat, whose full path names are defined as FILE1 and FILE2 in the header file assignment02.h all included within starter repository.

  • void read_data(ifstream &is, vector> &m): Reads the input values from the input stream is and stores them in matrix m, which is defined as a two-dimensional vector of integers. The number of rows and columns of m are the pair of values given at the beginning of the corresponding data file and they are captured in the source file assignment02.cc (driver program) that is in the same directory with assignment02.h.

  • void print_data(const vector> &m): Prints the contents of on stdout by allocating ITEM_W spaces for each integer value, which is defined in the header file assignment02.h. The number of values printed in a single line equals to the number of columns of m and the number of lines on stdout equals to the number of rows of m.

  • void gen_data(const vector> &A, const vector> &B, vector> &C): It multiples the values in the matrices A and B and stores the results in the matrix C.

    • If C(i, j) is the value of C in row i and j of C, then C(i, j) += A(i, k) * B(k, j) for all index values of k, where A(i, k) is the value of A in row i and column k of A, and B(k, j) is the value of B in row k and column j of B.
    • For a vector container use C[i][j] for C(i, j), where i = 0, 1, ..., size(C) 1 and j = 0, 1, ..., C[i].size() 1, and its the same for A and B.

Programming Notes:

  • Do not change existing implementation in assignment02.cc, but you need to include any necessary headers and add necessary global constants.

  • The header file assignment02.h is provided. To include the header file in your program, insert the statement: #include assignment02.h at the top of your source file sub02.cc.

  • Correct output is found in results02.out based the matrix values in data files assignment02a.dat and assignment02b.dat, these are just example. They can be changed, so do not design your program for the specific values in the data files. Your program is supposed to work for any matrix values in those files.

  • You are not allowed to use any I/O functions from the C library, such as scanf or printf. Instead, use the I/O functions from the C++ library, such as cin or cout.

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!