#include <iostream>
#include "Ecuacion.h"
using namespace std;
int main(void)
{
float v1,v2,v3;
Ecuacion *obj = new Ecuacion();
cout << "====ECUACION DE SEGUNDO GRADO===" << endl << endl;
cout << "Digite el valor de A" << endl;
cout << ">> ";
cin >> v1;
obj->setA(v1);
cout << endl;
cout << "Digite el valor de B" << endl;
cout << ">> ";
cin >> v2;
obj->setB(v2);
cout << endl;
cout << "Digite el valor de C" << endl;
cout << ">> ";
cin >> v3;
obj->setC(v3);
cout << endl;
cout<< "Solucion 1: " << obj->resultadoUno() << endl;
cout<< "Solucion 2: " << obj->resultadoDos() << endl;
}
#ifndef ECUACION_H
#define ECUACION_H
class Ecuacion
{
public:
Ecuacion();
virtual ~Ecuacion();
void setA(float val);
float getA();
void setB(float val);
float getB();
void setC(float val);
float getC();
float resultadoUno();
float resultadoDos();
protected:
private:
float a;
float b;
float c;
};
#endif
#include "Ecuacion.h"
#include "math.h"
Ecuacion::Ecuacion()
{
a = 0;
b = 0;
c = 0;
}
Ecuacion::~Ecuacion()
{
}
void Ecuacion::setA(float val)
{
a = val;
}
float Ecuacion::getA()
{
return a;
}
void Ecuacion::setB(float val)
{
b = val;
}
float Ecuacion::getB()
{
return b;
}
void Ecuacion::setC(float val)
{
c = val;
}
float Ecuacion::getC()
{
return c;
}
float Ecuacion::resultadoUno()
{
float res=0;
res = (-getB() + (sqrt(pow(getB(),2)-(4 *getA()*getC()) ))) / (2*getA());
return res;
}
float Ecuacion::resultadoDos()
{
float res=0;
res = (-getB() - (sqrt(pow(getB(),2)-(4 * getA() * getC())))) / (2*getA());
return res;
}