#include <vector>
#include <iostream>
#include <cmath>
#include <complex>
usingnamespace std;
vector <double> values (4);
class parabola
{
double A,B,C,x;
public:
parabola ();
parabola (vector<double>values);
void solve_y()
{
cout << A*(x*x)+B*x+C;
}
double solve_y(vector<double>values)
{
return (A*(x*x)+B*x+C);
}
double discriminant()
{ return (pow(B,2)-(4*A*C));}
void count_roots();
double roots1(vector<double>values);
double roots2(vector<double>values);
}test,trial(values);
parabola::parabola ()
{
A=1;
B=1;
C=1;
x=1;
}
parabola::parabola (vector<double>values)
{
A=values[0];
B=values[1];
C=values[2];
x=values[3];
}
int main ()
{
cout << "This program is meant to solve for the value of y in the formula: " << endl;
parabola test;
cout << endl << "The result of y when all values are 1 is: " ;
test.solve_y();
cout << endl;
cout << "y = Ax^2 + Bx + C (parabola)" << endl;
cout << "Enter the value of A:" << endl;
cin >> values[0];
cout << "Enter the value of B:"<< endl;
cin >> values[1];
cout << "Enter the value of C:" << endl;
cin >> values[2];
cout << "Enter the value of x:" << endl;
cin >> values[3];
parabola trial(values);
cout << "The result of y is: " << trial.solve_y(values) << endl;
trial.count_roots();
cout << endl;
system ("pause");
return 0;
}
double parabola::roots1(vector<double>values)
{
return ((-B+sqrt(trial.discriminant()))/(2*A));
}
double parabola::roots2(vector<double>values)
{
return ((-B+sqrt(trial.discriminant()))/(2*A));
}
void parabola::count_roots()
{
if (discriminant() > 0)
{
cout << "The number of real roots are: 2" << endl;
cout << "The roots are: " << trial.roots1(values)<< "and " << trial.roots2(values) << endl;
}
elseif (discriminant()==0)
{
cout << "The number of real roots are: 1" << endl;
cout << "The roots are: " << trial.roots1(values);
}
else
{
cout << "The number of real roots are: zero" << endl;
}
}
One thing I notice not related to your problem is that the formulas for roots1 and roots2 are the same.
-1.#ind may be returned if you try to take the square root of a negative number. Of course 505 isn't negative so there might be an error in your formula.