design a class that can be used to represent a parabola, any help is greatly appreciated

First off thank you for taking out time on even thinking of helping me.

So i've been up for way too long and having massive brain farts. The goal of this program is to have output like this:

The first parabola:

1.0x^2 + 4.0x + -5.0

Vertex Coordinates: (-2.000, -9.000)
The parabola opens UPWARD
There are two real roots with X-Coordinates 1.000 and -5.000


The numbers for the parabola need to be entered in main, calcRoots (it just needs to be squared somewhere) my void Parabola:: print() section needs help as well. I'm not sure how to go about either.
Heres what I have so far. the first is my header file i called hw9.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>			//getting info from various libraries
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <fstream>

using namespace std;

class Parabola
{
public:
  Parabola( double, double, double );

  double calcDiscrim();
  double calcRoots( double &, double & );
  double calcX();
  double calcY();

  void printEquation();
  void printVertex();
  void printRoots();
  void printConcavity();
  void print();

private:
  double aCoeff, bCoeff, cCoeff;
}; 



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
 #include "hw9.h"


Parabola::Parabola(double a, double b, double c)
{
       aCoeff = a, bCoeff = b, cCoeff = c;
       if(a == 0)
               aCoeff = 1;
       if(b == 1)
               bCoeff = 2;
       if(c == 2)
               cCoeff = 3;    
}



double Parabola::calcDiscrim()
{
return (bCoeff * bCoeff - 4 * aCoeff * cCoeff);
}

 
 
int Parabola::calcRoots( double &root1, double &root2 )		//needs work. what does multiplicity 2 means squared?
{
int numRoots=0;
double discriminant=calcDiscrim();



else if (discriminant ==0)
{
root1 = ( (-1*bCoeff) + sqrt( discriminant )) / ( 2 * aCoeff );
numRoots=1;
}



else if(discriminant > 0))
{
root1 = ( (-1*bCoeff) + sqrt( discriminant )) / ( 2 * aCoeff );
root2 = ( (-1*bCoeff) - sqrt( discriminant )) / ( 2 * aCoeff );
numRoots=2;	
}

return numRoots;
}



double Parabola::calcX()
{
return(-1*bCoeff / ( 2 * aCoeff));
}




double Parabola::calcY()
{
double Xcord=calcX();
return(( aCoeff * (Xcord*Xcord) ) + ( bCoeff * Xcord ) + cCoeff);
}



void Parabola::printEquation()
{
cout<<setprecision(2)<<aCoeff<<"x^2 + "<<bCoeff<<"x + "<<cCoeff <<endl;	
}



void Parabola::printVertex()
{
cout << "Vertex coordinates: "<< setprecision(3)<< calcX()<<","<< calcY();
}



void Parabola::printRoots()
{
  if(a == 0)
  {
  	cout<< " There are NO real roots";
  }
  if(b == 1)
  {
  	cout<< "There is one real root with X-Coordinate "<< root1;
  }
  if(c == 2)
  	{
    cout << "There are two real roots with X-Coordinates "<< root1<< " and " << root2;			
	}
}


void Parabola::printConcavity()
{
if (aCoeff>0)
cout<<"The parabola opens UPWARD";

else  
cout<<"The parabola opens DOWNWARD";
	
}



void Parabola:: print()
{

}
Last edited on
Topic archived. No new replies allowed.