I'm still learning classes in C++ and I don't understand this error that I'm getting from `#include QuadraticEquation`. Here's my code:
#include <iostream>
#include <cmath>
#include "QuadraticEquation"
using namespace std;
class QuadraticEquation{
private:
double a = 0, b = 0, c = 0;
public:
QuadraticEquation(double a, double b, double c)
{
this-> a = a;
this-> b = b;
this-> c = c;
}
double getA(){
return a;
}
double getB(){
return b;
}
double getC(){
return c;
}
double getDiscriminant(){
return (pow(b, 2) - 4 * a * c);
}
double getRoot1(){
return ((-b + sqrt(pow(b, 2) - 4 * a * c)) / (2 * a));
}
double getRoot2(){
return ((-b - sqrt(pow(b, 2) - 4 * a * c)) / (2 * a));
}
};
int main()
{
double a = 0, b = 0, c = 0;
//User enters values for a, b, and c.
cout << "Enter the values for a, b, and c: ";
cin >> a >> b >> c;
//Object created.
QuadraticEquation q1 (a, b, c);
if (q1.getDiscriminant() > 0){
cout << "Root 1: " << q1.getRoot1() << ", Root 2: " << q1.getRoot2() << endl;
//Two Roots
}else if (q1.getDiscriminant() == 0){
//One root
cout << "Root 1: " << q1.getRoot1() << endl;
}else{
//No roots
cout << "The equation has no real roots." << endl;
}
}