Programming C

Tasks studies - laboratory


Project maintained by dawidolko Hosted on GitHub Pages — Theme by dawidolko

Exam 2

Choose one of the following tasks. Name the files with solutions depending on the selected task, respectively:

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:

In the main() method:

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
# Effect EK_03: ## DST: The student is able to correctly prepare programs of 20-50 lines of code that solve simple problems, using some of the learned data structures and programming constructs available in the C language for this purpose. ## DB: The student is able to correctly prepare programs of 20-50 lines of code that solve intermediate problems, using all of the learned data structures and programming constructs available in the C language for this purpose. ## BDB: The student is able to correctly prepare programs of 50-100 lines of code, solving intermediate problems, using the capabilities of standard programming libraries available in the C language, including those that the student learned independently