# Thread: ok need help with circle program

1. ## ok need help with circle program

been doing good in the class until now..can someone lend me a hand and help me out here..i had to finally break down and just ask someone.

here is what im facing...

1. Define and implement a class named Circle. Its partial declaration is given below:

class Circle

{

private:

Point C; //center of circle, an object of Point class

public:

//constructors

Circle(); //radius = 0, center = (0, 0)

Circle(float r); //radius = r, center = (0, 0)

Circle(Point P, float r); // radius = r, center = P

//input, output

(Implement >> and << here as free functions. Operation << should plot(draw) the circle.)

//scale – multiply a float number into the radius

(Implement * here as a member function.)

//move – move circle to another location

(Implement moveTo(Point) and moveBy(Point) functions here as member functions.)

//compare – decide if two circle are overlapping or not. When two are overlapping, decide further if one is completely contained in the other.

(Implement ==, !=, < operators here as free functions, where C1==C2 is true if C1 and C2 overlap, C1!=C2 is true if they don’t, and C1<C2 is true if C1 is contained in C2.)

2. Plot a circle

3. Scale a circle

4. Move a circle

5. Compare two circles //read 2 circles and compare them.

6. Exit

help would be very much appreciated. thanks a lot guys!!!

2. i wasnt expecting someone to do it all..just needed some help sorry about that...just started on this project and needed some help with plotting, (Implement ==, !=, < operators here as free functions, where C1==C2 is true if C1 and C2 overlap, C1!=C2 is true if they don’t, and C1<C2 is true if C1 is contained in C2.), parts im sorry..i was in a hurry at the time...anyone have suggestions?

3. Originally Posted by southeastkyguy1
...anyone have suggestions?
Post an attempt?

4. Use code tags if you post code examples. Good start would be to draft your idea before you actually begin coding it. It is easier to throw a blue print than a 1000 line program

5. So deal with them one at a time, and post your best effort on the one you're stuck on.

"plot" where?
Which OS / Compiler / Graphics library are you planning to use?

6. thanks for the fast replys...i have a decent start on it...ill post my program later..then tell you what all im having problems with...one thing is its hard to find out how im going to display the circle..he wants us to use * to display the circle.

7. You could use nested for loops

8. > he wants us to use * to display the circle.
Ah, simple 80x25 character display - that should be easy enough.

9. Isn't there an algorithm to draw a circle from points? Bresenham or something. I think there's a pseudocode in a Graphics Programming book. So if you've understood the algorithm, making it into a code is piece of cake. Or maybe what you're having a trouble with is not the algorithm but rather the OOP?

10. ok here is what i have

Code:
```
#include <iostream>
#include <cmath>
using namespace std;
class Point
{
private:
int x;
int y;
friend class Circle;
public:
//constructor
Point(int xval = 0, int yval = 0)
{
x = xval;
y = yval;
}
//input
friend istream & operator >>(istream &in, Point &P)
{
cout << "Enter x value: ";
cin >> P.x;
cout << "Enter y value: ";
cin >> P.y;
return in;
}
};
class Circle //Circle class
{
private:
Point C;
public:
//constructors
Circle() //radius = 0, center = (0,0)
{
}
Circle(float r) //radius = r, center = (0,0)
{
}
Circle(Point P, float r) //radius = r, center = P
{
C.x = P.x;
C.y = P.y;
}
int getX()
{
return C.x;
}
int getY()
{
return C.y;
}
//input, output
friend istream & operator >>(istream &in, Circle &CC)
{
cin >> CC.C;
return in;
}
friend ostream & operator >>(ostream &out, Circle &CC) //needs 2D array
//scale
void operator * (float a)
{
}
//move
void moveTo(Point P)
{
C.x = P.x;
C.y = P.y;
}
void moveBy(Point P)
{
C.x = C.x+P.x;
C.y = C.y+P.y;
}
//compare
friend bool operator == (Circle C1, Circle C2)
{
cout << "Enter values for first circle: " << endl;
cin >> C1;
cout << endl;
cout << "Enter values for second circle: " << endl;
cin >> C2;
double distance = sqrt(pow((C2.getX()-C1.getX())/1.0,2)+pow((C2.getY()-C1.getY())/1.0,2)); //distance between centers
{
return true;
}
else
{
return false;
}
}
friend bool operator != (Circle C1, Circle C2)
{
cout << "Enter values for first circle: " << endl;
cin >> C1;
cout << endl;
cout << "Enter values for second circle: " << endl;
cin >> C2;
double distance = sqrt(pow((C2.getX()-C1.getX())/1.0,2)+pow((C2.getY()-C1.getY())/1.0,2)); //distance between centers
{
return false;
}
else
{
return true;
}
}
friend bool operator < (Circle C1, Circle C2)
};```

i still need the *'s to print the circle

11. Fixing the syntax errors first would be good.

12. >>i still need the *'s to print the circle

That's what I've said. You need to find a good graphics programming book somewhere. There's algorithms to plot lines, circles, eclipse, curves, etc with a series of dots there.

13. well sorta running low on time and cant on this project