Tasks studies - laboratory
Choose one of the following tasks. Name the files with solutions depending on the selected task, respectively:
dst_gr1.c
and dst.exe
for grade 3db_gr1.c
and db.exe
. for grade 4bdb_gr1.c
and bdb.exe
for grade 5
After completing the colloquium, pack the files into a .zip archive and submit using the form.Create an Array
structure that stores the matrix. The structure should also contain the data necessary to read the values of the matrix cells.
Create a function initArray()
that returns an instance of the Array
structure. The function creates a new instance of the Array
structure and stores a matrix with a specified number of rows and columns passed as parameters to the function.
Create a printArray()
function that takes an Array
structure as a parameter.
The function prints the contents of the array from the passed structure in the following format:
2.00 2.00 2.00
2.00 2.00 2.00
12.00 12.00 12.00
Create a fillArray()
function that takes an instance of the Array
class and asks the user to fill in the contents of the array.
Example session:
Array[0][0] = 2.0
Array[0][1] = 4.42
Array[1][0] = 5.2
Array[1][1] = 6.0
Array[2][0] = 9
Array[2][1] = 22.4
Create a function multiplyArrays()
that accepts two instances of the Array
structure. In the body of the function, implement matrix multiplication. Consider the following aspects:
Array
structure (two matrices can be multiplied only if the number of columns of matrix A is equal to the number of rows of matrix B).In the main()
method:
Array
.initArray()
function to create 3x2 and 2x3 matricesfillArray()
function to fill the matrices with valuesmultiplyArrays()
function passing the created matricesprintArray()
function)Save the result of matrix multiplication in the text file wyników.txt
in the form:
1.00 2.00 3.00
4.00 5.00 2.00
X
1.00 4.00
3.00 1.00
5.00 4.00
=
22.00 18.00
29.00 29.00
Write a function print_matrix()
that prints the contents of a matrix (the matrix should be allocated dynamically using appropriate functions) of floating-point numbers in the following form:
| 0.00 | 0.10 |
| 1.00 | 1.10 |
| 2.00 | 2.10 |
Write a function free_matrix()
that frees dynamically allocated memory to store the matrix.
Write a function duplicate_row()
that duplicates the selected row n
times and replaces the matrix with a new one - larger, e.g. duplicating row 2 twice we get:
| 0.00 | 0.10 |
| 1.00 | 1.10 |
| 2.00 | 2.10 |
| 0.00 | 0.10 |
| 1.00 | 1.10 |
| 1.00 | 1.10 |
| 2.00 | 2.10 |
Write a main function that tests the functionality of previously implemented functions and saves the results in the file wyniki.txt
Write a function print_matrix()
that prints the contents of a floating-point matrix in the console in the following form:
| 0.00 | 0.10 |
| 1.00 | 1.10 |
| 2.00 | 2.10 |
The function can print the contents of a matrix of any size.
| 0.00 | 0.10 | 0.50 |
| 1.00 | 1.10 | 1.40 |
| 2.00 | 2.10 | 2.10 |
| 2.00 | 2.10 | 2.10 |
| 1.00 | 1.10 | 1.40 |
Write a function matrix_mean()
that returns the mean value of the matrix elements.
Test the function on the following matrices:
| 0.00 | 0.10 |
| 1.00 | 1.10 |
| 2.00 | 2.10 |
| 2.00 | 2.10 |
| 1.00 | 3.00 |
| 2.00 | 5.00 |
| 1.00 | 3.00 | 10.00 |
| 2.00 | 5.00 | 9.00 |
Write a program that saves a matrix in the file wyników.txt
and under it the average value from this matrix for all tested cases, e.g.:
| 1.00 | 3.00 | 10.00 |
| 2.00 | 5.00 | 9.00 |
mean: 10.00