Sample test 1
Sample test 1
Programs that do not compile (contain errors) will not be graded.
Cheating will be penalized, all works will be checked for plagiarism. During solving of the test use only code of your authorship.
You have 1.5 h for solving the test, the assignment with close at the appointed deadline. Only solution uploaded to the designated eKursy assignment will be checked, no other means of providing the code will be accepted.
Task 0
Create a menu for selecting which task will be executed - a “while” loop that will allow selection of a task to run (by task number). The loop should end, and the program should exit, when the user enters “0”.
The goal of every task is to create a function. If the task requires input (std::cin
) or output (std::cout
), handle it outside the function. The functions should only perform specific job. All data has to be provided as function parameter. Adhere to function naming and format specified by the task and example calls.
Task 1
Write a function that will convert all non-alphanumeric characters (a-z, A-Z, 0-9) into underscores (_).
Example call:
char text[] = "Text#with@weird^signs@()-";
change_to_undersores(text);std::cout << text << std::endl
Output:
Text_with_weird_signs____
Task 2
Write a function calculate_trig_from_series
that will calculate approximation of sine and cosine of a given value x
, with given precision of n
. Return the values by reference and print them.
Use the following formulas:
Example call:
double sin_val, cos_val;
0.52, 9, sin_val, cos_val);
calculate_trig_from_series(// Print the results of sin_val and cos_val
Task 3
Write polynomial
function which calculates the value of a polynomial. The parameters should consist of an array of coefficients values, their number, and value of the argument x for which the value of the polynomial has to be calculated.
Example call:
// f(x) = -3x^3 + 2x^2 – 3x + 5 // f(2) = - 17
double coefs[4] = {-3, 2, -3, 5}; int n = 4
double x = 2;
double result = polynomial(coefs, n, x);
Task 4
Create an array of 100 random integer values from the range <50; 150>. Write mean
function that will return the mean of numbers in the array. Print the result.
int arr[100];
// Assign random values
double mean_val = mean(arr, 100);
// Print the results
Authors: Jakub Tomczyński, Tomasz Mańkowski