need help on a function
I'm getting a error on my
Circle::Circle(double radiusValue) |
constructor. My instructions is 'Add a constructor that accepts one argument and uses it to set the radius.'
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
|
#include <iostream>
#include <cmath>
using namespace std;
class Circle
{
private:
double x;
double y;
double radius;
public:
Circle();
Circle(double);
Circle(double, double, double);
void setRadius(double);
void setX(double);
void setY(double);
double getRadius();
double getX();
double getY();
double getArea();
bool containsPoint(double, double);
};
Circle::Circle()
{
x=0;
y=0;
radius =1;
}
Circle::Circle(double radiusValue)
{
radius = radiusValue;
}
Circle::Circle(double xValue, double yValue, double radiusValue)
{
x = xValue;
y = yValue;
radius = radiusValue;
}
void Circle::setRadius(double r)
{
radius = r;
}
void Circle::setX(double xCord)
{
x = xCord;
}
void Circle::setY(double yCord)
{
y = yCord;
}
double Circle::getRadius()
{
return radius;
}
double Circle::getX()
{
return x;
}
double Circle::getY()
{
return y;
}
double Circle::getArea()
{
return 3.14*radius*radius;
}
bool Circle::containsPoint(double xValue, double yValue)
{
bool status;
double d;
d = sqrt(pow((xValue - x), 2.0) + pow((yValue - y), 2.0));
if (d <= radius)
status = true;
else
status = false;
return status;
}
int main()
{
int i;
double circX;
double circY;
double circRadius;
double ptX;
double ptY;
cout << "You will enter data for 3 circles.\n";
for (i=0; i<3; i++)
{
Circle c;
cout << "x: " << c.getX() << endl;
cout << "y: " << c.getY() << endl;
cout << "radius: " << c.getRadius() << endl;
cout << "Enter the x coordinate of the center of your circle" << (i+1) << ": ";
cin >> circX;
cout << "Enter the y coordinate of the center of your circle" << (i+1) << ": ";
cin >> circY;
cout << "Enter the radius of your circle" << (i+1) << ": ";
cin >> circRadius;
c.setX(circX);
c.setY(circY);
c.setRadius(circRadius);
cout << "Enter a x coordinate to test circle" << (i+1) << ": ";
cin >> ptX;
cout << "Enter a y coordinate to test circle" << (i+1) << ": ";
cin >> ptY;
cout << "The area of your circle" << (i+1) << " is: " << c.getArea() << endl;
if (c.containsPoint(ptX, ptY))
cout << "Circle" << (i+1) << " contains the point (" << ptX << ", " << ptY << ")"<< endl;
else
cout << "Circle" << (i+1) << " does not contain the point (" << ptX << ", " << ptY << ")"<< endl;
}
}
| |
why are you writing constructor..
1 2
|
Circle(double);
Circle(double, double, double);
| |
you are not using them please remove them...
Compiles fine, what the error is?
What error? We can't read your mind.
Topic archived. No new replies allowed.