Name: ________________________________

Honor Code Acknowledgment: ___________________


Random Quiz # 5

CPS 100E, Fall 1996

Due: September 26


Problem 1: Michael's array order (at the beach) (2 pts)

Write the function KthColumnSum whose header is given below. The function returns the sum of the values in column k of two-dimensional array mat.

int KthColumnSum(const Matrix<int> & mat, int k, int numRows) // precondition: 0 <= k < mat.Cols() // numRows = # of rows in the matrix mat // postcondition: returns sum of all values in column k of mat { }

Problem 2: This pie is occupewed (4 points)

A matrix is transposed if the rows become columns and the columns become rows, e.g., the matrix is rotated 90 degrees. The matrix on the left below is transposed into the matrix on the right.
    1  2  3  4          1  5  9
    5  6  7  8          2  6 10
    9 10 11 12          3  7 11
                        4  8 12
Write the function Transpose whose header is shown below. You'll need to use Matrix member functions Rows(), Cols(), and SetSize(). void Transpose(const Matrix<double> & a, Matrix<double> & b) // postcondition: b is the transpose of a { }

Problem 3 : MadMax II (3 points)

Write the function MaxIndices that returns the row and column at which the largest value in the matrix a is stored. If the maximal element is not unique, set row and col to the lowest possible values that index one of the maximal elements. int MaxIndices(const Matrix < int > & a, int & row, int & col) // precondition: a contains a.Rows() rows and a.Cols() columns // postcondition: row = row index of largest element in a, col = // column index of largest element of a { }