Tasks studies - laboratory
Project maintained by dawidolko Hosted on GitHub Pages — Theme by dawidolko
Exam 2 Group 1
Exam 2
Choose one of the following tasks. Name the files with solutions depending on the selected task, respectively:
dst_gr1.canddst.exefor grade 3db_gr1.canddb.exe. for grade 4bdb_gr1.candbdb.exefor grade 5 After completing the colloquium, pack the files into a .zip archive and submit using the form.
Very good
EK_3
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:
- when it is possible to multiply a matrix by a matrix, if multiplication is not possible print an appropriate message and return empty fields of the
Arraystructure (two matrices can be multiplied only if the number of columns of matrix A is equal to the number of rows of matrix B). - the function should return a new matrix that is the result of multiplying these matrices
In the main() method:
- Create two variables of type
Array. - Use the
initArray()function to create 3x2 and 2x3 matrices - Call the
fillArray()function to fill the matrices with values - Call the
multiplyArrays()function passing the created matrices - Print the result of matrix multiplication in the console (
printArray()function)
EK_4
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
Good
EK_3
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 |
EK_4
Write a main function that tests the functionality of previously implemented functions and saves the results in the file wyniki.txt
Dostawczny
EK_3
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.
EK_4
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