Using Class to solve the quadratic equation.

I am getting an error and am not sure what I need to change.

#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
using namespace std;
//******************************************************************
// class Quadratic declaration
//******************************************************************
class Quadratic
{
private:
double a, b, c;

public:
Quadratic();
void set(double cdblA, double cdblB, double cdblC);
const double get_a() const;
const double get_b() const;
const double get_c() const;
const double evaluate(double x);
const double real_root ();
const double larger_root ();
const double smaller_root ();
void display(const string strPrompt);
const double Quadratic operator+(const Quadratic & q1, const Quadratic & q2)const;
const double Quadratic operator*(const double r, const Quadratic & q )const;
};
//******************************************************************
// class Quadratic implementation
//******************************************************************
Quadratic::Quadratic() : a(0), b(0), c(0) {}
//******************************************************************
// Function: Quadratic set
//******************************************************************
void Quadratic::set(double cdblA, double cdblB, double cdblC)
{
a = cdblA;
b = cdblB;
c = cdblC;
}
//***************************************************************
// Function: Quadratic::Get A
//***************************************************************
const double Quadratic::get_a() const
{
return a;
}
//***************************************************************
// Function: Quadratic::Get B
//***************************************************************
const double Quadratic::get_b() const
{
return b;
}
//***************************************************************
// Function: Quadratic::Get C
//***************************************************************
const double Quadratic::get_c() const
{
return c;
}
//***************************************************************
// Function: Quadratic::evaluate x
//***************************************************************
const double Quadratic::evaluate(double x)
{
return (a * x * x) + (b * x) + c;
}
//***************************************************************
// Function: Quadratic operator+
//***************************************************************
Quadratic operator+(const Quadratic & q1, const Quadratic & q2)
{
double a = q1.get_a() + q2.get_a();
double b = q1.get_b() + q2.get_b();
double c = q1.get_c() + q2.get_c();
Quadratic q;
q.set(a, b, c);
return q;
}
//***************************************************************
// Function: Quadratic operator*
//***************************************************************
Quadratic operator*(const double r, const Quadratic & q )
{
double a = r * q.get_a();
double b = r * q.get_b();
double c = r * q.get_c();
Quadratic q1;
q1.set(a, b, c);
return q1;
}
//***************************************************************
// Function: Quadratic::display
//***************************************************************
void Quadratic::display(const string strPrompt)
{
cout << endl;
cout << strPrompt << " " <<
setw(8) << setprecision(2) << fixed << a << " X^2 + " <<
setw(4) << setprecision(2) << fixed << b << " X + " <<
setw(4) << setprecision(2) << fixed << c << endl;
}
//***************************************************************
// Function: Real Roots
//***************************************************************
const double Quadratic::real_root ()
{
double x1 = 0.0;
double x2 = 0.0;
int real_root;

//If a, b and c are all zero, then every value of x is a real root.
if(a == 0 && b == 0 && c == 0)
{
real_root = 3;
}
//If a and b are zero and c is non-zero, then there are no real roots.
if(a == 0 && b == 0 && c != 0)
{
real_root = 0;
}
//If a is zero and b is non-zero, then the only real root is x = -c/b.
if(a == 0 && b != 0)
{
real_root = 1;
}
//If a is non-zero and b^2 < 4ac, then there are no real roots.
if(a != 0 && b*b < (4*a*c))
{
real_root = 0;
}
//If a is non-zero and b^2 = 4ac, then there is one real root x = -b/2a.
if(a != 0 && b*b == (4*a*c))
{
real_root = 1;
}
//If a is non-zero and b2 > 4ac, then there are two real roots.
if(a != 0 && b*b > (4*a*c))
{
real_root = 2;
}

cout << "The number of real roots is: " << real_root << endl;

return real_root;
}
//***************************************************************
// Function: Larger Root
//***************************************************************
const double Quadratic::larger_root ()
{
double x1 = 0;
double x2 = 0;
double larger;

//If a, b and c are all zero, then every value of x is a real root.
if(a == 0 && b == 0 && c == 0)
{
x1 = 0;
x2 = 0;

cout << "The real roots are:" "\n";
cout << "x1 = " << x1 << endl;
cout << "x2 = " << x2 << "\n";
}
//If a and b are zero and c is non-zero, then there are no real roots.
if(a == 0 && b == 0 && c != 0)
{
cout << "There are no real roots" "\n";
cout << "x1 = " << x1 << endl;
cout << "x2 = " << x2 << "\n";
}
//If a is zero and b is non-zero, then the only real root is x = -c/b.
if(a == 0 && b != 0)
{
x1 = -c/b;
x2 = 0.0;
cout << "The only real root is" "\n";
cout << "x1 = " << x1 << endl;
cout << "x2 = " << x2 << "\n";
}
//If a is non-zero and b^2 < 4ac, then there are no real roots.
if(a != 0 && b*b < (4*a*c))
{
cout << "There are no real roots" "\n";
cout << "x1 = " << x1 << endl;
cout << "x2 = " << x2 << "\n";
}
//If a is non-zero and b^2 = 4ac, then there is one real root x = -b/2a.
if(a != 0 && b*b == (4*a*c))
{
x1 = -b/2*a;
x2 = 0.0;
cout << "There is one real root:" "\n";
cout << "x1 = " << x1 << endl;
cout << "x2 = " << x2 << "\n";
}
//If a is non-zero and b2 > 4ac, then there are two real roots.
if(a != 0 && b*b > (4*a*c))
{
x1 = (-b + (sqrt(pow(b,2)-(4*a*c))))/(2*a);
x2 = (-b - (sqrt(pow(b,2)-(4*a*c))))/(2*a);
cout << "The real roots are:" "\n";
cout << "x1 = " << x1 << endl;
cout << "x2 = " << x2 << "\n";
}

if (x1 > x2)
larger = x1;
else
larger = x2;

cout << "Larger Root = " << larger << endl;

return larger;
}
//***************************************************************
// Function: Smaller Root
//***************************************************************
const double Quadratic::smaller_root ()
{
double x1;
double x2;
double smaller;

if (x1 < x2)
smaller = x1;
else
smaller = x2;

cout << "Smaller Root = " << smaller << endl;;

return smaller;
}
//***************************************************************
// Function: main
//***************************************************************
int main()
{
Quadratic s, t, u, v,p,r;

cout << "This Program Finds the Roots of a Quadratic Equation" << endl;
cout << endl;
cout << " ax^2 + bx + c = 0" << endl;
cout << endl;

s.set(1, -3, 1);
s.display("Q1 ");
s.real_root ();
s.larger_root();
s.smaller_root();
cout << endl;

t.set(2, 2, 2);
t.display("Q2 ");
t.real_root();
t.larger_root();
t.smaller_root();
cout << endl;

u = s + t;
u.display("The Sum of Q1 + Q2 ");
u.real_root();
u.larger_root();
u.smaller_root();
cout << endl;

v = 5.0 * t;
v.display("The total of R * Q ");
v.real_root();
v.larger_root();
v.smaller_root();
cout << endl;

p.set(1, 4, 4);
p.display(" P ");
p.real_root();
p.larger_root();
p.smaller_root();

system("PAUSE");
return 0;
}

What is the error message?
One immediately obvious problem is you can't do this :
1
2
const double Quadratic operator+(const Quadratic & q1, const Quadratic & q2)const;
const double Quadratic operator*(const double r, const Quadratic & q )const;


Are you trying to return a Quadratic or a double?
for both lines:

expected `;' before "operator"

trying to return the quadratic.
then get rid of the double.
You can have:
double operator*()
or:
Quadratic operator*()
not both:
double Quadratic operator*()
Thank you for your help.
Topic archived. No new replies allowed.