/* Program to run the quadratic formula through */ #include #include using namespace std; void standard_quadratic(double a, double b, double c, double *root1, double *root2) { *root1=-(b+sqrt(b*b-4.0*a*c))/(2.0*a); *root2=-(b-sqrt(b*b-4.0*a*c))/(2.0*a); return; } double parabola(double a,double b,double c,double x) { double y; y=a*x*x+b*x+c; return y; } void viete_formula(double a, double b, double c, double *root1, double *root2) { /* We have two relations: x_1+x_2 = -b/a, and x_1*x_2=c/a */ /* Let's find the first good root */ if (b>=0) { *root1=-(b+sqrt(b*b-4.0*a*c))/(2.0*a); *root2=c/(a*(*root1)); } else { *root1=-(b-sqrt(b*b-4.0*a*c))/(2.0*a); *root2=c/(a*(*root1)); } return; } main() { double a,b,c,y; double root1,root2; cout << "Enter a,b,c for the parabola.\n"; cin >> a >> b >> c; cout << "a,b,c" << a<<" "<< b << " "<< c << " " << endl; standard_quadratic(a,b,c,&root1,&root2); cout << "For the standard quadratic, the roots are: " << root1 << " " << root2 << endl; cout << "For the roots times 10^5 are:" << 1.0e5*root1 << " " << 1.0e5*root2 << endl; y=parabola(a,b,c,root1); cout << "Putting first value back in gives " << y << endl; y=parabola(a,b,c,root2); cout <<"Putting second value back in gives " << y << endl; viete_formula(a,b,c,&root1,&root2); cout <<"For the standard quadratic, the roots are: "<< root1 << " " << root2 << endl; cout << "For the roots times 10^5 are: " << (1.0e5*root1) << " " << 1.0e5*root2 << endl; y=parabola(a,b,c,root1); cout << "Putting first value back in gives " << y << endl; y=parabola(a,b,c,root2); cout <<"Putting second value back in gives " << y << endl; }