I've written a c++ program that contains the following classes: class Shape, Circle, Ellipse, Rectangle, Triangle. All the classes are a subclass of class Shape. They syntax of their definition is fine, I see no visible errors. This is the code:
#include "graphics.h"
//#include <iostream>
usingnamespace std;
constfloat Pi = 3.141;
float distance (int x1, int y1, int x2, int y2) {
int x = x2 - x1;
int y = y2 - y1;
x = x * x;
y = y * y;
float total = x + y;
float length = sqrt(total);
return length;
}
class Shape {
public:
float area;
virtualvoid Area () = 0;
};
class Rectangle : public Shape {
public:
int length, width;
virtualvoid Area () {
area = length * width;
}
};
class Triangle : public Shape {
public:
float a, b, c;
virtualvoid Area () {
float s = ((a + b + c) / 2);
area = sqrt(s * (s - a) * (s - b) * (s - c));
}
};
class Ellipse : public Shape {
public:
int x, y;
float a, b;
virtualvoid Area () {
area = Pi * a * b;
}
};
class Circle : public Shape {
public:
int x, y;
float radius;
virtualvoid Area () {
area = Pi * radius * radius;
}
};
class Line { //implement zigzag within Line
public:
int x, y; //last point of line segment
};
Now when I declare a variable of each subclass in the main, I get an error on two of the classes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
int main ()
{
Circle a;
Rectangle b;
Ellipse d;
Triangle c;
int x1, y1;
float length;
paintInterface ();
int xcoord, ycoord;
bool flag = true;
while (flag) {
while(!ismouseclick(WM_LBUTTONDOWN)) {}
getmouseclick(WM_LBUTTONDOWN, xcoord, ycoord);
if (((xcoord >= 0) && (xcoord <= 35)) && ((ycoord >= 5) && (ycoord <= 20))) {
paintInterface ();
}
}
...And there's a bunch of similar if conditions.
My compiler gives an error under b and d, i.e. the Rectangle object and the Ellipse object. The error is, "Expected a ';'" . I have quadruple checked every inch of my code and as far as I can tell, there are no missing semicolons. Where this ";" belongs is beyond me, any help will be appreciated.
It would be helpful if you posted the error verbatim as well as pointing us to the line of code it's complaining about. You don't seriously expect someone to compile your code for you, do you?