Tasks studies - laboratory
Choose one of the tasks below.
After completing the colloquium, pack the files into a .zip archive and send them using the form.
Create the program dst_quadraticfunction
.
Create the function printRoots()
which accepts the coefficients a, b, c of a quadratic function. The coefficients can be decimal numbers or negative. The function should calculate the zeros of the quadratic function.
The function should print information in the console in the following form:
Example when the function arguments are -2, 3, 1
f(x) = (-2.00)x^2 + (3.00)x + (1.00)
Delta: 17.00
x1 = -0.28
x2 = 1.78
Example when the function arguments are 2, 4, 2
f(x) = (2.00)x^2 + (4.00)x + (2.00)
Delta: 0.00
x = -1.00
Example when the function arguments are 3, 4, 2
f(x) = (3.00)x^2 + (4.00)x + (2.00)
Delta: -8.00
The function has no zeros.
In the main()
method, test the function in the following cases:
a = -2, b = 3, c = 1
a = 2, b = 4, c = 2
a = 3, b = 4, c = 2
Later in the main()
method, write a code fragment that will ask the user for the coefficients a, b, c. After the user enters the coefficients, information about the zeros will be displayed. Sample session:
Enter coefficient a: 2
Enter coefficient b: 4
Enter coefficient c: 2
f(x) = (2.00)x^2 + (4.00)x + (2.00)
Delta: 0.00
x = -1.00
Useful formulas:
\[ax^2+bx+c=0\] \[\Delta =b^2-4ac\] \[x_1=\frac{-b-\sqrt{\Delta }}{2a}\] \[x_2=\frac{-b+\sqrt{\Delta }}{2a}\]If:
\[\Delta>0 - \text{quadratic equation has two solutions}\] \[\Delta=0 - \text{quadratic equation has one solution}\] \[\Delta<0 -\text{quadratic equation has no solutions}\]Create the program db_sortowanie_rowsz
.
Create the function allocate_2d_array()
which dynamically allocates space in memory for a matrix of floating-point numbers of the size passed as the function parameters. The function returns a pointer to this matrix.
Create the function free_2d_array()
which frees space in memory for the matrix passed as the function parameter.
In the comment, describe what the function parameters are responsible for if their name does not suggest it.
Create a function print_matrix()
that prints the matrix content to the console in the following form:
0.0000 0.1000
1.0000 41.1005
2.0000 42.1000
Create a function sort_by_row()
that sorts the array passed as the function argument ascending by the value in the indicated row. The row by which the sorting is to take place should be passed as the function argument. e.g.
before sorting
1.0000 3.0000 5.0000
3.0000 4.0000 3.0000
4.0000 7.0000 1.0000
3.0000 1.0000 3.0000
after sorting with 2 row selection
1.0000 5.0000 3.0000 3.0000 3.0000 4.0000 4.0000 1.0000 7.0000 3.0000 3.0000 1.0000
after sorting with 1 row selection
1.0000 3.0000 5.0000
3.0000 4.0000 3.0000
4.0000 7.0000 1.0000
3.0000 1.0000 3.0000
Create a 4x4 matrix using allocate_2d_array()
and then fill it with random values between 1 and 10.
Preview the test matrix.
Test the sort_by_column() function on the following cases: