Pagini recente » Cod sursa (job #617375) | Cod sursa (job #1650612) | Cod sursa (job #2032845) | Cod sursa (job #866678) | Cod sursa (job #2038133)
#include <iostream>
#include <stdexcept>
#include <string>
#include "Complex_Number.h"
void Eq(complex, complex, complex);
int main()
{
std::string s;
complex a, b, c;
do
{
std::cout << "To continue type 'yes'!Type any other text to pass!\n";
getline(std::cin, s);
if (s == "yes")
{
a.Read();
b.Read();
c.Read();
Eq(a, b, c);
std::cout << '\n';
}
else break;
} while (1);
return 0;
}
void Eq(complex a, complex b, complex c)
{
if (a == 0)
{
if (b == 0)
{
if (c == 0)
std::cout << "The equation has infinite solutions!\n";
else
std::cout << "The equation has no solutions!\n";
}
else
std::cout << "Solution of the ecuation is x=", (-c / b).Write();
}
else
{
complex delta((b ^ 2) - (4 * a*c));
if (delta == 0)
{
std::cout << "The ecuation admits a double solution x1=x2=";
(-b / (2 * a)).Write();
}
else
{
complex r(sqrt(delta));
std::cout << "Solutions of the ecuation are x1=";
((-b + r) / (2 * a)).Write();
std::cout << " x2=";
((-b - r) / (2 * a)).Write();
}
}
}