Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include <cmath>
- using namespace std;
- class cuadratica{
- public:
- cuadratica( double a,double b,double c);
- void raiz ()const;
- private:
- double discriminante()const ;
- float a,b,c;
- };
- cuadratica::cuadratica (double a,double b,double c): a(a),b(b),c(c) {};
- void cuadratica::raiz()const{
- if (discriminante()<0){//Raices complejas
- cout <<-b/(2*a) <<"+"<<sqrt(abs(discriminante()))/(2*a)<<"i ,"
- <<-b/(2*a) <<"-"<<sqrt(abs(discriminante()))/(2*a)<<"i "<<endl;
- }else {//Raices reales
- cout <<-(b+sqrt(discriminante()))/(2*a)<<","
- <<-(b-sqrt(discriminante()))/(2*a)<<endl;
- }
- }
- double cuadratica::discriminante ()const{return ( b*b-4*a*c);}
- int main() {
- cuadratica eqReal(1,2,-8);//x^2+2x-8 raices 2 y -4 discriminante 36
- cuadratica eqImaginaria(1,-2,2);//imaginaria 1+1i , 1-1i
- cuadratica eqImaginaria2(1.5,-2.2,2.3);//imaginaria 0.733333+0.997775i ,0.733333-0.997775i
- eqReal.raiz();
- eqImaginaria.raiz();
- eqImaginaria2.raiz();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement