# Thread: need help with program...

Ok, I'm getting closer. This program should take input from user - x,y points of center of two circles, and the radius. The program determines the relationship of the circles - either Intersection, Separation or Coverage. I have a few errors and think my problems lies with my variable names. Also, one error is "pow" does not take one parameter (haven't used the power much). Please help!!

#include <iostream.h>
#include <math.h>

class circle{

public:
double x1, y1, r1, x2, y2, r2;
void initial();
int distance (int x, int y);
double relation (double r1, double r2);
};

void circle::initial ()
{
cout << "Enter circle 1: " << endl;
cin >> x1 >> y1 >>r1;
cout << "Enter circle 2: " << endl;
cin >> x2 >> y2 >>r2 ;
}

double relation(double r1, double r2)
{
if (fabs(r1-r2) <= (d) <= (r1+r2))
cout << "Intersection" << endl;
else if
( d > (r1 + r2))
cout << "Separation " << endl;
else
cout << "Coverage" << endl;
}

int circle::distance ( int x, int y)
{
double d;
x= pow(x1 - x2);
y= pow(y1 - y2);
d = sqrt (x+y);
}

int main()
{
circle c1, c2;
c1.initial() ;
c2.initial() ;
cout<<"The relations of c1 and c2 is " << relation(c1,c2)<<endl;
return 0;
}

2. double relation(double r1, double r2)
{
if (fabs(r1-r2) <= (d) <= (r1+r2)) //1
cout << "Intersection" << endl;
else if
( d > (r1 + r2)) //2
cout << "Separation " << endl;
else
cout << "Coverage" << endl;
}

int circle::distance ( int x, int y)
{
double d; //3
x= pow(x1 - x2);
y= pow(y1 - y2);
d = sqrt (x+y); //4
}

there are problems with these 2 funtions.
1) Try this
if( (fabs(r1-r2) <= d) && (d <= (r1+r2)) )
1 and 2) the variable d needs to be declared in the class definition, with the other vars, so it can be accesed.
3) move this line, as mentioned above
4) this fuctions returns an int, well it should. try return d at the end

Make the initial function call distance() after the user inputs the data, so that when relation is called, d contains valid data.

3. thanks rpimatty for your help. I'm still having problems, and since I've been at this for about 6 hours and it's 2am, I think I'll call it a night and try again tomorrow. Anyone else have any ideas in the meantime, please reply. Here's what I have now:

class circle{
public:
double x1, y1, r1, x2, y2, r2, d;
void initial();
distance (c1, c2);
double relation (double c1, double c2);
};

void circle::initial ()
{
cout << "Enter circle 1: " << endl;
cin >> x1 >> y1 >>r1;
cout << "Enter circle 2: " << endl;
cin >> x2 >> y2 >>r2 ;
}

double relation(double c1, double c2)
{
if ( (fabs(r1-r2) <= d) && (d <= (r1+r2)) )
cout << "Intersection" << endl;
else if
( d > (r1 + r2))
cout << "Separation " << endl;
else
cout << "Coverage" << endl;
}

int distance ( circle c1, circle c2)
{

x= pow(x1 - x2);
y= pow(y1 - y2);
d = sqrt (x+y);
return d;
}

int main()
{
circle c1, c2;
c1.initial() ;
c2.initial() ;
cout<<"The relations of c1 and c2 is " << relation(c1,c2)<<endl;
return 0;
}

4. > double x1, y1, r1, x2, y2, r2, d;
This is two circles, not one
double x, y, r;

> void circle::initial ()
{
cout << "Enter circle 1: " << endl;
cin >> x1 >> y1 >>r1;
cout << "Enter circle 2: " << endl;
cin >> x2 >> y2 >>r2 ;
}

And this inputs both circles (twice)
Code:
```void circle::initial ()  {
cout << "Enter circle: " << endl;
cin >> x >> y >>r;
}```
In the class
> distance (c1, c2);
> double relation (double c1, double c2);
distance doesn't have any types, and I'm pretty sure that relation needs to have two circles as input parameters

> x= pow(x1 - x2);
Read the manual - pow takes 2 arguments

Finally, relation() should call distance() before doing any comparisons on d

5. ## let's try again

Ok, I'm doing this step by step. It compiles ok, but when running I'm getting an error "unresolved external symbol "public: class circle _ thisclass circle::initial(void)".

#include <iostream.h>
#include <math.h>

class circle{

public:
int x, y, r;
circle initial();
};

circle initial()
{
circle c1, c2;
cout << "Enter first circle x point: " ;
cin >> c1.x;
cout << "Enter first circle y point:" ;
cin >> c1.y;
cout << "Enter first circle radius: ";
cin >> c1.r;
cout << "Enter second circle x point: " ;
cin >> c2.x;
cout << "Enter second y point:" ;
cin >> c2.y;
cout << "Enter second radius: ";
cin >> c2.r;
return (c1, c2);
}

int main()
{
circle c1, c2;
c1.initial();
c2.initial();

cout << c1.x << endl;
cout << c1.y << endl;
cout << c1.r << endl;
cout << c2.x << endl;
cout << c2.y << endl;
cout << c2.r << endl;
return 0;
}

It works ok if I do initial(c1,c2) in main, but I want to do with c1.initial(); c2.initial();

Pls help.
Thanks

6. You want to make initial a member function of circle than returns nothing.

Code:
```class circle {
// data
public:
void initial();
};

// concentrate here.  initial is a member function of circle that returns nothing..
// should be able to understand that from how the following line looks
void circle::initial() {

}```

7. thanks. I've made those changes, now it is asking me to initialize each circle two times, and it's output is the address of the data, not the data. Any ideas?

8. initial will be responsible for getting input for a single circle.

So, say you implement Salem's version of initial. Then, in main, you will create two instances of circle, and each of them will be initialed.

Code:
```int main() {
circle a, b;

a.initial();  // make a iniatilize itself
b.initial();  // make b initialize itself

// more stuff

return 0;
}```

9. Thanks Silenstrike. I finally got that figured out. Now I have to work on the other functions, yikes!!

10. Ok, this is what I have now. I'm getting errors that r1, r2 and d in the relation function are not defined, and my distance output is gargabe. Please help!

#include <iostream.h>
#include <math.h>

class circle{
public:
double x, y, r, d;
void initial();
void distance(circle& c1, circle& c2);
friend circle relation(circle& c1, circle& c2);
};

void circle::initial()
{
cout << "Enter the (x,y) coordinates of the circle center, and the radius: " ;
cin >> x >> y >> r;
}

void circle::distance(circle& c1, circle& c2)
{
c1.d = pow((c1.x - c2.x),2);
c2.d = pow((c1.y - c2.y),2);
cout << c1.d << c2.d;
}

circle relation (circle& c1, circle& c2)
{
if( (fabs(r1-r2) <= d) && (d <= (r1 + r2)) )
cout << "Intersection" << endl;
else if
(d > (r1 + r2))
cout << "Separation" << endl;
else
cout << "Coverage" << endl;
}
int main()
{
circle c1, c2;

c1.initial();
c2.initial();

// cout << "The relations of c1 and c2 is " << relation (c1,c2)<<endl;
return 0;
}

11. New version -- now getting "d" undeclared identified in relation, and no operator defined which takes right hand operand of type class circle in main function.

class circle{
public:
double x, y, r, d;
void initial();
distance(circle& c1, circle& c2);
friend circle relation(circle c1, circle c2);
};

void circle::initial()
{
cout << "Enter the (x,y) coordinates of the circle center, and the radius: " ;
cin >> x >> y >> r;

}

circle::distance(circle& c1, circle& c2)
{
c1.d = pow((c1.x - c2.x),2);
c2.d = pow((c1.y - c2.y),2);
d=sqrt(c1.d = c2.d);
}

circle relation (circle c1, circle c2)
{
if( (fabs(c1.r-c2.r) <= d) && (d <= (c1.r + c2.r)) )
cout << "Intersection" << endl;
else if
(d > (c1.r + c2.r))
cout << "Separation" << endl;
else
cout << "Coverage" << endl;
}
int main()
{
circle c1, c2;

c1.initial();
c2.initial();
cout << "The relations of c1 and c2 is " << relation(c1,c2)<<endl;
return 0;
}

12. Please help Still getting errors "d" undeclared identified in relation, and no operator defined which takes right hand operand of type class circle in main function on the cout line. Also, I know my relation should return strings and not cout statements, but not sure how to do that. The main function cannot be changed. Thanks!!

#include <iostream.h>
#include <math.h>
#include <string>
using namespace std;

class circle{
public:
double x, y, r, d;
void initial();
distance(circle& c1, circle& c2);
void print();
friend circle relation(circle& c1, circle& c2);
};

void circle::initial()
{
cout << "Enter the (x,y) coordinates of the circle center, and the radius: " ;
cin >> x >> y >> r;
}

circle::distance(circle& c1, circle& c2)
{
x = pow((c1.x - c2.x),2);
y = pow((c1.y - c2.y),2);
d=sqrt(x+y);
}

circle relation (circle& c1, circle& c2)
{

if( (fabs(c1.r-c2.r) <= d) && (d <= (c1.r + c2.r)) )
cout << "Intersection"<< endl;
else if
(d > (c1.r + c2.r))
cout << "Separation" << endl;
else
cout << "Coverage" << endl;

}
int main()
{
circle c1, c2;
c1.initial();
c2.initial();
cout << "The relations of c1 and c2 is " << relation(c1,c2)<<endl;
return 0;
}