Design a class named QuadraticEquation for a quadratic equation ax^2+bx+x=0. The class contains: **private data fields a, b, and c that represents three coefficients. **a constructor for the arguments for a, b, and c. **three get methods for a, b, and c. **a method named getDiscriminant() that returns the discriminant, which is b2-4ac **the methods named getRoot1() and getRoot2() for returning two roots of the equation, or returning 0 if the discriminant is negative.[/color]

Respuesta :

Answer:

C++

///////////////////////////////////////////////////////////////////////////////////////////

#include <iostream>

using namespace std;

//////////////////////////////////////////////////////////////////

class QuadraticEquation {

   int a, b, c;

   

public:

   QuadraticEquation(int a, int b, int c) {

       this->a = a;

       this->b = b;

       this->c = c;

   }

   ////////////////////////////////////////

   int getA() {

       return a;

   }

   

   int getB() {

       return b;

   }

   

   int getC() {

       return c;

   }

   ////////////////////////////////////////

   // returns the discriminant, which is b2-4ac

   int getDiscriminant() {

       return (b*2)-(4*a*c);

   }

   

   int getRoot1() {

       if (getDiscriminant() < 0)

           return 0;

       else {

           // Please specify how to calculate the two roots.

           return 1;

       }

   }

   

   int getRoot2() {

       if (getDiscriminant() < 0)

           return 0;

       else {

           // Please specify how to calculate the two roots.

           return -1;

       }

   }

};

//////////////////////////////////////////////////////////////////

int main() {

   return 0;

}

ACCESS MORE
EDU ACCESS
Universidad de Mexico