classes and semi-colons giving me troubles

Hey guys, I've got some troubles in this code declaring classes and having the program run due to some errors that all have to do with semicolons. I'm really not that good at C++ so if its something obvious or if i'm just way off, please make the explanation in kind of a layman's terms. Here's my program.

The program is supposed to design a class that can be used that can represent a parabola.

I'll bold what the code is yelling at me for.

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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#include <iostream>
#include <iomanip>
#include <cmath> 
#include <fstream>
#include <cstdlib>
#include <cstring>

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;
};

int main()
{
double Coeff, aCoeff, bCoeff, cCoeff, a, b, c ;
string Parabola( double, double, double );


if(a==0)
{
    Coeff = 1;

        aCoeff = a;
    	bCoeff = b;
        cCoeff = c;
	
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;
cout << Parabola p1;

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

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

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

cout << "The fifth parabola:" << endl;
cout << Parabola p5;
};
else (a !=0);
{
cout << "error";
}
return 0;
}











double calcDiscrim()
{
	double Coeff, aCoeff, bCoeff, cCoeff;
return( (bCoeff * bCoeff) - (4 * aCoeff * cCoeff) );
}


double calcRoots( double &root1, double &root2)
{
	double Coeff, aCoeff, bCoeff, cCoeff;	
if( calcDiscrim() == 0 )
{
root1 = -bCoeff / ( 2 * aCoeff );

return 1; 
}

if(calcDiscrim()>0)
{
root1 = ( -bCoeff + sqrt( calcDiscrim() ) ) / ( 2 * aCoeff );

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

if(calcDiscrim()<0)

return 0;

}


 
double calcX()
{
	double Coeff, aCoeff, bCoeff, cCoeff;
return ( -bCoeff / ( 2 * aCoeff ) );
}



double calcY()
{
	double Coeff, aCoeff, bCoeff, cCoeff;
return ( ( aCoeff * calcX() ) + ( bCoeff * calcX() ) + cCoeff );
}


void printEquation()
{
	double Coeff, aCoeff, bCoeff, cCoeff;
cout << aCoeff << "x^2 + " << bCoeff << "x + " << cCoeff << endl;
}


void printVertex()
{
	double Coeff, aCoeff, bCoeff, cCoeff;
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()
{
double Coeff, aCoeff, bCoeff, cCoeff;	
if(aCoeff < 0)
cout << "The parabola opens Downward" << endl;

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





void print()
{
printEquation();

printVertex();

printConcavity();

printRoots();
}

Last edited on
1
2
3
4
5
6
7
8
9
cout << "The fifth parabola:" << endl;
cout << Parabola p5;
};
else (a !=0);
{
cout << "error";
}
return 0;
}


the ';' before else denotes the end of a class definition so everything after that is not a part of anything. Also you have a ';' after an else statement which should not be there.
Last edited on
First you should delete semicolon at the end of bold area. It creates a dangling else.
Second: All class methods should be defined as
1
2
double Parabola::calcDiscrim()
{
And so on...
When defining functions outside of the class or namespace scope, you need to qualify the scope that function you are defining is in like doing what MiiNiPaa stated.
Topic archived. No new replies allowed.