mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-07-04 21:03:15 +02:00
- Add +x to Python scripts with shebangs (3 files) - Remove -x from non-script files like .cpp, .txt, makefile (23 files) - Move shebang to first line in C/imageViewer/lint.sh
49 lines
982 B
C++
49 lines
982 B
C++
#include <iostream>
|
|
#include <string>
|
|
#include <math.h>
|
|
|
|
const std::string ENTER = "Enter quadratic equation constants: ";
|
|
const std::string WHAT_TO_INPUT = "a, b, c as in: ax^2 + bx + c = 0";
|
|
const std::string START = ENTER + WHAT_TO_INPUT;
|
|
|
|
void print(const std::string s) { std::cout << s << std::endl; }
|
|
|
|
float getDelta(float a, float b, float c)
|
|
{
|
|
return b*b - 4*a*c;
|
|
}
|
|
|
|
float calculateFirstTerm(float a, float b, float delta)
|
|
{
|
|
return (-b - sqrt(delta))/(2*a);
|
|
}
|
|
|
|
float calculateSecondTerm(float a, float b, float delta)
|
|
{
|
|
return (-b + sqrt(delta))/(2*a);
|
|
}
|
|
|
|
int main()
|
|
{
|
|
print(START);
|
|
float a, b, c;
|
|
std::cin >> a;
|
|
std::cin >> b;
|
|
std::cin >> c;
|
|
float delta = getDelta(a, b, c);
|
|
if(delta < 0)
|
|
{
|
|
print("delta smaller than 0");
|
|
return -1;
|
|
}
|
|
|
|
float x_1 = calculateFirstTerm(a, b, delta);
|
|
float x_2 = calculateSecondTerm(a, b, delta);
|
|
print("Solutions:");
|
|
std::cout << "x_1 = " << x_1 << std::endl;
|
|
std::cout << "x_2 = " << x_2 << std::endl;
|
|
return 0;
|
|
|
|
|
|
}
|