Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help debugging this program. I need the constructors and methods after ma

ID: 3535837 • Letter: I

Question

I need help debugging this program. I need the constructors and methods after main(). Also in the prgram where I need to display the root values when I print them I am getting garbage values. root 1 (&a) and root 2 (&b). These are the two variables giving me garbage.

I placed all of the methods and constructors after main() but it wont compile..



#include <iostream>

#include <iomanip>

#include <cmath>


using namespace std;


class Parabola{


private:

double Coeff,

aCoeff,

bCoeff,

cCoeff;

public:

Parabola(double a, double b, double c){

if(a==0)

Coeff = 1;

else

aCoeff = a;

bCoeff = b;

cCoeff = c;

}



int main()

{

Parabola p1(1, 4, -5);

Parabola p2(0, 0, 25);

Parabola p3(-1, 2, -1);

Parabola p4(-12, -2, 3);

Parabola p5(12, 2, 3);


cout << "The first parabola:" << endl;

p1.print();


cout << "The second parabola:" << endl;

p2.print();


cout << "The third parabola:" << endl;

p3.print();


cout << "The fourth parabola:" << endl;

p4.print();


cout << "The fifth parabola:" << endl;

p5.print();

return 0;

}





double calcDiscrim()

{

return( (bCoeff * bCoeff) - (4 * aCoeff * cCoeff) );


}


double calcRoots(double &root1, double &root2)

{

if(calcDiscrim()==0)

{

root1 = -bCoeff / (2 * aCoeff);

return 1;

}

else if(calcDiscrim()>0){

root1 = (-bCoeff + sqrt(calcDiscrim())) / (2 * aCoeff);

root2 = (-bCoeff + sqrt(calcDiscrim())) / (2 * aCoeff);

return 2;

}

else if(calcDiscrim()<0)

return 0;


}


double calcX(){

return (-bCoeff / (2 * aCoeff));

}


double calcY(){

return ((aCoeff * calcX()) + (bCoeff * calcX()) + cCoeff);

}


void printEquation(){


cout << aCoeff << "x^2 + " << bCoeff << "x + " << cCoeff << endl;

}


void printVertex(){


cout << "Vertex Coordinates: ("<< calcX() << "," << calcY() <<")" << endl;

}


void printRoots(){

double number;

double root1, root2;

double &a = root1;

double &b = root2;

number = calcRoots(a, b);


if(number==0)

cout << "There are NO real roots" << endl;


if(number==1)

cout << "There is one real root with X-Coordinate root 1 value " << fixed << setprecision(3) << &a << endl;


if(number==2)

cout << "There are two real roots with X-Coordinate root 1 value " << fixed << setprecision(3) << &a << " and root 2 value " << fixed << setprecision(3) << &b << endl;

}


void printConcavity(){

if(aCoeff < 0)

cout << "The parabola opens Downward" << endl;

else

cout << "The parabola opens Upward" << endl;

}


void print(){

printEquation();

printVertex();

printConcavity();

printRoots();

}

};


Explanation / Answer

#include #include #include using namespace std; class Parabola{ private: double Coeff, aCoeff, bCoeff, cCoeff; public: Parabola(double a, double b, double c){ if(a==0) Coeff = 1; else aCoeff = a; bCoeff = b; cCoeff = c; } void print(); void printConcavity(); void printRoots(); void printVertex(); void printEquation(); double calcY(); double calcX(); double calcRoots(double &root1, double &root2); double calcDiscrim(); } int main() { Parabola p1(1, 4, -5); Parabola p2(0, 0, 25); Parabola p3(-1, 2, -1); Parabola p4(-12, -2, 3); Parabola p5(12, 2, 3); cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote