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);
- double raiz (bool signo);
- private:
- double discriminante();
- double a,b,c;
- };
- cuadratica::cuadratica (double a,double b,double c): a(a),b(b),c(c) {};
- double cuadratica::raiz(bool signo){return (-b+ sqrt (discriminante()) *(signo ? 1: -1))/ (2*a) ;}
- double cuadratica::discriminante (){return ( b*b-4*a*c);}
- //sobrecarga operador << para la clase cuadratica
- ostream& operator<<(ostream& os,cuadratica c){
- os<<"Raices = "<< c.raiz(true)<<" , "<<c.raiz(false);
- return os;
- };
- int main(int argc, char** argv) {
- cuadratica eqA(1,2,-8);//x^2+2x-8 raices 2 y -4 discriminante 36
- cuadratica eqB(1.1,2.2,-8.3);//1.1x^2+2.2x-8.3 raices 1.92326 , -3.92326
- cout << eqA<<endl;
- cout << eqB<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement