Hey i am currently really stuck on a school assignment. No rush i have plenty of time, but without a little help i am pretty much lost.
The question is as fallows.
Design a class named QuadraticEquation for a quadratic equation ax2 + bx + c = 0. (The book has an error in the quadratic expression.)

The class contains:
Attributes a, b, and c that represent three coefficients.
A constructor for the arguments a, b, and c.
Three get functions for a, b, and c.
A method names getDiscriminant() that returns the discriminant, which is b2 - 4ac.
Methods names getRoot1() and getRoot2() for returning two roots of the equation: (see book for the complete mathematical formula)
The roots of a quadratic are undefined (in the real number system) if the discriminant is negative. If the discriminant is negative, let getRoot1() and getRoot2() return the value zero (0).

(We will eventually see a better way to handle the zero discriminant problem in C++.)

Draw the UML diagram for the class. Implement the class. Write a test program that prompts the user to enter values for a, b, and c, then displays the roots based on the discriminant. If the discriminant is positive, display the two roots. If the discriminant is zero (0) display the one root. If the discriminant is negative, display "The equation has no real roots."

I was told i have everything to my disposal for research, so i assume your allowed to help me.

Question, the class is only the header file right, so i am pretty sure i don't have to implement this, further than than simple testing to make sure it all works, i also don't have to write my main.cpp file if im not mistake.

What i have so far:

Quadradicequation.h

#ifndef QUADRADICEQUATION_H
#define QUADRADICEQUATION_H

class Quadradicequation
      public:
              void getcoefficients()
              {
              int get.a(a);
              int get.b(c);
              int get.c(c);
              void get.discrim(discrim); 
              void get.root1(root1);
              void get.root2(root2);
              
              }
      private:
              void coefficients()
              {
              int a, b, c;
              double result;
              
              result = sqrt(b^2 - (4*a*c));
              int set.a(a);
              int set.b(b);
              int set.c(c);
              void set.descrim(b^2-(4*a*c);
              void set.root1((-b+result)/(2*a));
              void set.root2((-b-result)/(2*a));
              }

Quadradicequation.cpp

#include "Quadradicequation.h"

using namespace std;

void getcoefficients();
{
     cout << "Enter Values for a b and c: ";
     int a, b, c;
     cin >> a >> b >> c;
     
     Quadradicequation::get.discrim(discrim);
     
     if (discrim = 0)
     get.root1(root1);
     
     else if (discrim > 0)
     get.root1(root1);
     get.root2(root2);
     
     else
     cout << "The equation has no real roots." << endl;

Other than that i am not going to lie. Anyone have any literature that doesn't suck as much as my text book?

Any help is great
Thanks,
~E

I'm no expert like the others
but to my understanding
a .cpp file has the same title as the .h is actually a definition for .h's function
what you had put in the .cpp is actually the main()
so in the main .cpp you only need to call .h

also that I think you forgot to declare "discrim"

int get.a(a);

is not correct, and shouldn't be associated with the getcoefficients() method.

The period indicates a member variable and shouldn't be used in a method name like that, just make it int get_a or geta etc. Also, your notation is incorrect (it looks a bit like initializer notation, but this is not the right context for that.

It's sufficient enough to have:

int get_a() {return a;}

as a public member function.

Otherwise, just put int get_a(); and put the other portion in the implementation file.

Go back and look at your text for examples of classes. I think you're got a bit of the idea, but the way certain specifics are handled is important.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.