So i'm in a pickle, i'm trying out how to use my preset values that I used for the two circles? I have listed the values in main. I have a function called getD but how do I pull, Circle c2(1, 2, 4); Circle c3(2, 2, 3);, values to where it goes through my if else statements correctly. Here is my provided code...
#include<iostream>
#include <cmath>
#include<fstream>
using namespace std;
class Circle
{
private:
double radius;
double xcoord;
double ycoord;
public:
//Deconstructor
~Circle(){
cout << "Deconstructor for class Circle is called" << endl;
}
//Constructor
//Do i need to add separte variables for the two sets???
Circle(double r = -1, double x = 0, double y = 1){
radius = r;
xcoord = x;
ycoord = y;
}
void printData1(){
cout << "The Circle's are touching" << endl;
}
void printData2(){
cout << "The Circle's are Overlapping" << endl;
}
void printData3(){
cout << "The Circle's are not touching" << endl;
}
};
void getD(double x2, double x1, double y2, double y1)
{
double d;
d = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
}
int main()
{
//int r, x, y
Circle c1;
Circle c2(1, 2, 4);
Circle c3(2, 2, 3);
/*c2.printData1();
cout << endl;*/
//how do you put equation in?
if (getD == c2.getRadius + c3.getRadius )
{
cout << "The Circle's are touching" << endl;
}
else if (getD < c2.getRadius + c3.getRadius)
{
cout << "The Circle's are Overlapping" << endl;
}
else if (getD > c2.getRadius + c3.getRadius)
{
cout << "The Circle's are not touching" << endl;
}
getRadius() is a method (a function belonging to a class). You must include the empty argument list — the parentheses — after the name to invoke it.
(Otherwise you are just getting the method's address, which is a very fancy kind of pointer, useless for arithmetic.)
Make sure to crank up your compiler's warning level and read what it says when it doesn't compile. In this case it should complain about adding pointers or something similar. Compiler warnings aren't always the easiest to read. Often enough you can just read them as "not doing what it is supposed to be doing because I typed something wrong". It will tell you the file and line number of the error so that you can go look at it.
Equality is problematic for doubles, what you need is a function to see if values are "nearly equal" , that is the absolute value of the difference is less than some precision value you specify.
The reason is that floating point numbers are not exact, if they differ in the 15th decimal place then the equality test fails.
Good Luck !!
Edit: Please use code tags. Select your code, press the <> button on the format menu on the right.