CSc 10300 Assignment 3 Arrays/Vectors, User-defined Functions solution

$29.99

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (3 votes)

We want to write a C++ program that performs a couple of procedures on
two-dimensional (N by N) arrays. To this end:
(a) Define an integer variable named N that shows the size of the input matrix.
This is the variant of your program and you as a programmer can change
it to use matrices of different sizes in different runs of your program.
(b) Declare 2 two-dimensional double arrays A and B of size N*N and fill
them with user-input values.
(c) Define a print() function that takes a matrix as input and print it in a
form of a matrix using tabs.
(d) Define function areEqual() that checks corresponding elements of two
given matrices and returns true if they were all equal. (False otherwise)
(e) Define function isIdentity() that takes a matrix as input and return true
if the matrix is an identity matrix. (False otherwise)
(f) Define evenAndOdd() function that takes a matrix as an input, computes
and returns the number of odd numbers and number of even numbers as
two integer values. You should define a separate function(s) for checking
if a number is even or odd.
(g) Define sumOfColumns() function that takes a matrix as input and returns
a vector of sum of columns of matrix. The first element of the vector would
be the sum of the first column of the matrix, the second element would
be the sum of the second column, and so on.
(h) Define sumOfRows() function that takes a matrix as input and returns a
pointer to an array of the sum of columns of the matrix. The first element
of the array would be the sum of the first row of the matrix, the second
element would be the sum of the second row, and so on.
(i) Define sortByRowAndColumn() function that takes a matrix and sort its
values first by row and then by column in-place. This function does not
1
return any values.


9 1 2
5 3 1
4 8 0


Sorting each row
−−−−−−−−−−→


1 2 9
1 3 5
0 4 8


Sorting each column
−−−−−−−−−−−−−→


0 2 5
0 3 8
1 4 9


(j) Separate function definitions into separate files (a header file and a source
file @zybook 6.14).
(k) Unit-test all of the functions. In the main function, you should have
different pieces of code, each for testing one of the functions in your code.
Separate them by comments and make sure you specify which function
each part of the code belongs to. Use N=3 for testing parts a to f of the
problem, and N=4 for testing g-j.
Instructions
• You cannot use 2D vectors instead of 2D arrays in this homework.
• We have not covered arrays by pointers yet, so you are not allowed to use
dynamic memory allocations for passing arrays.
• If a parameter can be defined as a constant parameter, define it as a
constant parameter.
• Make sure that your program could be compiled by the command provided
on zybook 6.15.
2