66 lines
1.5 KiB
C++
66 lines
1.5 KiB
C++
/// @file
|
|
/// @brief Task3: implementation
|
|
|
|
#include "task3.hpp" // add|mul|frac|mean|squared|cubed|eval
|
|
|
|
/// @todo Include standard library headers as needed
|
|
|
|
/// @brief Calculates the sum of three values
|
|
/// @param x 1st value
|
|
/// @param y 2nd value
|
|
/// @param z 3rd value
|
|
/// @return Sum of the three values
|
|
double add(double x, double y, double z) {
|
|
return x+y+z;
|
|
}
|
|
|
|
/// @brief Calculates the product of three values
|
|
/// @param x 1st value
|
|
/// @param y 2nd value
|
|
/// @param z 3rd value
|
|
/// @return Product of the three values
|
|
double mul(double x, double y, double z) {
|
|
return x*y*z;
|
|
}
|
|
|
|
/// @brief Calculates the fraction of two values
|
|
/// @param x 1st value
|
|
/// @param y 2nd value
|
|
/// @return Fraction of x divided by y
|
|
double frac(double x, double y) {
|
|
return x/y;
|
|
}
|
|
|
|
/// @brief Calculates the average (arithmetic mean) of three values
|
|
/// @param x 1st value
|
|
/// @param y 2nd value
|
|
/// @param z 3rd value
|
|
/// @return Average of the three values
|
|
double mean(double x, double y, double z) {
|
|
return (x+y+z)/3;
|
|
}
|
|
|
|
/// @brief Calculates the square of a value
|
|
/// @param x Value
|
|
/// @return Square of x
|
|
double squared(double x) {
|
|
return x*x;
|
|
}
|
|
|
|
/// @brief Calculates the third power of a value
|
|
/// @param x Value
|
|
/// @return Cube of x
|
|
double cubed(double x) {
|
|
return x*x*x;
|
|
}
|
|
|
|
/// @brief Evaluates a polynomial 'f(x) = a*x^2 + b*x + c'
|
|
/// @param x Variable
|
|
/// @param a Coefficient
|
|
/// @param b Coefficient
|
|
/// @param c Coefficient
|
|
/// @return Value of the polynomial at x
|
|
double eval(double x, double a, double b, double c) {
|
|
return a*x*x + b*x + c;
|
|
}
|