Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The input file The input file contains the size of the square matrix N (N-by-N) in the first line. The subsequent lines each hold

imageimageimage

The input file The input file contains the size of the square matrix N (N-by-N) in the first line. The subsequent lines each hold one matrix element. For example for the following matrix: 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 the data is stored in the input file as follows: 3 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 You may assume only valid input files are passed to your program. Three test input files are supplied with your homework assignment. You may use them for reference. You only need to submit your source file that contains the main function along with all other functions defined. You should use the format in the frame.txt file. For every function, the required information is provided as comments. The function declaration is also provided in the frame.txt file. The resulting matrix should be written to the output file in the format just like the input file. Memory Leak Detection Since you will use dynamic memory allocation, it is important not to have any memory leaks. You can do this check in the final steps of your homework. Type the following command when you want to execute your program and Valgrind checks your executable to find any memory leaks. You should have 0 memory leaks to pass this check. You should not have any memory leaks if you properly free the memory you allocated during your program. prompt $ valgrind --leak-check-full ./ The students that use an Apple computer as their local machine, can use the leaks command in their terminal. More information is provided here. On submitty, we use valgrind to grade their homeworks. Homework Specifications In this homework, you will write a program to perform 2-D square matrix multiplication. For the first operand (matrix), your program reads a matrix of doubles from a file. The name of the file is provided on the command line (i.e. argv[1]). For the second operand (matrix), your program should generate the swapped version of the first matrix. The swap matrix operation is implemented as follows: the ith column is exchanged/swapped with the contents of the i+2 column. So, column 0 is swapped with column 2 and column 1 is swapped with column 3 and so on until all columns are swapped up to column N - 1 for an N-by-N matrix. The following figure shows one example input and its swapped version. The Input Matrix: /******** START of 2-D Matrix **** 1.000000 5.000000 9.000000 2.000000 6.000000 10.000000 14.000000 3.000000 7.000000 11.000000 15.000000 13.000000 /******** END of 2-D Matrix ******** Output of Swap Matrix /******** START of 2-D Matrix ***** 3.000000 4.000000 7.000000 8.000000 11.000000 12.000000 15.000000 16.000000 /******** END of 2-D Matrix ****** 1.000000 5.000000 9.000000 13.000000 4.000000 8.000000 12.000000 16.000000 2.000000 6.000000 10.000000 14.000000 *** ******

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Algorithms questions