Advertisement
AntonioVillanueva

Cuadratica

Jun 4th, 2016
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include<iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. class cuadratica{
  7.     public:
  8.     cuadratica( double a,double b,double c);
  9.     double raiz (bool signo);
  10.  
  11.     private:
  12.     double discriminante();
  13.     double a,b,c;
  14. };
  15. cuadratica::cuadratica (double a,double b,double c): a(a),b(b),c(c) {};
  16. double cuadratica::raiz(bool signo){return (-b+ sqrt (discriminante()) *(signo ? 1: -1))/ (2*a) ;}
  17. double cuadratica::discriminante (){return ( b*b-4*a*c);}
  18.  
  19. //sobrecarga operador << para la clase cuadratica
  20. ostream& operator<<(ostream& os,cuadratica c){
  21.     os<<"Raices = "<< c.raiz(true)<<" , "<<c.raiz(false);
  22.     return os;
  23. };
  24.  
  25.  
  26. int main(int argc, char** argv) {
  27.    
  28.     cuadratica eqA(1,2,-8);//x^2+2x-8 raices 2 y -4 discriminante 36
  29.     cuadratica eqB(1.1,2.2,-8.3);//1.1x^2+2.2x-8.3 raices 1.92326 , -3.92326
  30.  
  31.     cout << eqA<<endl;
  32.     cout << eqB<<endl;
  33.     return 0;
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement