#include <cmath>
#include <iostream>
#include <list>
using list_type = std::list<double>;
class QuadraticEquation
{
private:
double m_a{};
double m_b{};
double m_c{};
public:
QuadraticEquation(double a = 1, double b = 1, double c = 1) :
m_a{ a },
m_b{ b },
m_c{ c }
{
}
list_type getSolutions()
{
double discriminant{ (m_b * m_b) - 4 * m_a * m_c };
if (discriminant > 0)
{
return list_type{((-m_b - sqrt(discriminant)) / (2 * m_a)),
((-m_b + sqrt(discriminant)) / (2 * m_a))};
}
else if (discriminant == 0)
{
return list_type{ -m_b / (2 * m_a) };
}
else
{
return list_type{};
}
}
};
double getDouble(const char abc = '-')
{
std::cout << "Enter '" << abc << "' value: ";
double value{};
std::cin >> value;
return static_cast<double>(value);
}
void printSolutions(const list_type &solutions)
{
if (solutions.size() > 0)
{
for (int count{ 1 }; const auto & solution : solutions)
{
std::cout << "Solution #" << count << " is: " << solution << '\n';
++count;
}
}
else
{
std::cout << "This equation does not have a real solution.\n";
}
}
int main()
{
QuadraticEquation equation1{ getDouble('a'), getDouble('b'), getDouble('c') };
auto solutions{ equation1.getSolutions() };
printSolutions(solutions);
return 0;
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}