Cod sursa(job #2038133)

Utilizator Consti.001FMI Dranca Constantin Consti.001 Data 13 octombrie 2017 11:37:41
Problema A+B Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.12 kb
#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();
		}
	}
}