CLASE EJECUTORA
using System;
namespace Enunciado_5
{
class Program
{
static void Main(string[] args)
{
double coefA = 0, coefB = 0, coefC = 0;
bool control = true;
while (control == true)
{
Console.Clear();
Console.WriteLine("RESOLVER ECUACIONES DE SEGUNDO GRADO");
Console.WriteLine("ECUACIONES DEL TIPO: Ax^2 + Bx + C = 0");
bool rep = true;
while (rep == true)
{
try
{
Console.WriteLine("\nINTRODUCIR EL VALOR PARA A:");
coefA = Double.Parse(Console.ReadLine());
Console.ForegroundColor=ConsoleColor.Cyan;
Console.WriteLine("\nINTRODUCIR EL VALOR PARA B:");
coefB = Double.Parse(Console.ReadLine());
Console.ForegroundColor=ConsoleColor.Magenta;
Console.WriteLine("\nINTRODUCIR EL VALOR PARA C:");
coefC = Double.Parse(Console.ReadLine());
rep = false;
}
catch (FormatException)
{
Console.Clear();
Console.WriteLine("¡ERROR!. INTRODUCIR SOLO VALORES NUMERICOS");
rep = true;
}
}
double Bcuadrado = coefB * coefB;
double cuatroAC = 4 * coefA * coefC;
if (Bcuadrado < cuatroAC && coefA > 0 && coefC > 0)
{
Console.Clear();
Console.WriteLine("LA ECUACION NO TIENE SOLUCION." +
"\nEL RESULTADO DE LA RAIZ CUADRADA ES NEGATIVA.");
}
else
{
Ecuacion ecu = new Ecuacion(coefA, coefB, coefC);
Console.WriteLine("\nVALOR 1 = {0}",ecu.raizpositiva());
Console.WriteLine("VALOR 2 = {0}",ecu.raiznegativa());
}
Console.WriteLine("\n¿DESEA SEGUIR INGRESANDO? (Y/N)");
bool repSwitch = true;
while (repSwitch == true)
{
string SioNO = Console.ReadLine();
switch (SioNO)
{
case "y": case "Y":
control = true;
repSwitch = false;
break;
case "n": case "N":
control = false;
repSwitch = false;
break;
default:
Console.WriteLine(
"\nLA ENTRADA NO ES LA CORRECTA. PULSE \"Y\" o \"N\".");
repSwitch = true;
break;
}
}
}
}
}
}
CLASE CONVENCIONAL
using System;
namespace Enunciado_5
{
public class Ecuacion
{
private double X, Y, Z;
public Ecuacion(double x, double y, double z)
{
X = x;
Y = y;
Z = z;
}
public double raizpositiva()
{
double result = ((-Y + System.Math.Sqrt (Y * Y - 4 * X * Z)) / (2 * X));
return result;
}
public double raiznegativa()
{
double result = ((-Y - System.Math.Sqrt(Y * Y - 4 * X * Z)) / (2 * X));
return result;
}
}
}
No hay comentarios:
Publicar un comentario