COMP 322 Assignment 1: Exploring arrays and pointers.

$30.00

Category: Tags: , , , , , , , You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (2 votes)

Question 1 (5 pts)
Can a function in C++ return an array? If yes please explain how, and if no please explain
why.
Question 2 (10 pts)
Write a function that will fill a 5×5 matrix by randomly generated numbers. You can use
rand() and srand() functions provided by library to generate random numbers.
The signature of the function is:
void fillMatrix(int matrix[rows][cols]);
rows and cols are global constants defined as follow:
const int rows = 5;
const int cols = 5;
2
Question 3 (10 pts)
Write a function that given a 5×5 matrix as parameter, will print each row of the matrix to
the screen line by line.
The signature of the function is:
void PrintMatrix(int matrix[rows][cols]);
You can test your function by feeding it a randomly generated matrix from question 2.
Question 4 (15 pts)
In algebra, a transpose of a matrix is a matrix whose rows are the columns of the original.
Write a function that will take a 5×5 matrix as parameter and then transpose it in-place
which means without the use of an extra or a temporary matrix while transposing.
The signature of the function is:
void transposeMatrix(int matrix[rows][cols]);
You can test your function by feeding it a randomly generated matrix from question 2.
Question 5 (15 pts)
Write an iterative function that given two 5×5 matrices as parameters, will return a third
5×5 matrix holding the result of the product of the 2 matrices.
You can test your function by feeding it two randomly generated matrices from question 2.
Question 6 (15 pts)
Rewrite the same function from question 5 but using recursion.
3
Question 7 (15 pts)
Rewrite the same functions from question 2, question 3 and question 4 (fillMatrix,
printMatrix and transposeMatrix) using the pointer notation instead of the array notation.
Note that you should be using double pointers to allocate the needed 2-dimensional
arrays.
Question 8 (15 pts)
Is it possible to use a 1-dimensional array instead of 2-dimensional array to implement a
matrix? If yes rewrite the functions from question 2 and question 3 (fillMatrix and
printMatrix) using 1-dimensional array. If no, please explain why.
4