ok need help with circle program

This is a discussion on ok need help with circle program within the C++ Programming forums, part of the General Programming Boards category; been doing good in the class until now..can someone lend me a hand and help me out here..i had to ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    5

    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

    float radius;

    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.)

    Your main function must display the following menu repeatedly:

    1. Read a circle

    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. #2
    Drunken Progammer CaptainMorgan's Avatar
    Join Date
    Feb 2006
    Location
    On The Rocks
    Posts
    45
    Last edited by CaptainMorgan; 11-07-2006 at 09:31 PM.

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    5
    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?

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by southeastkyguy1
    ...anyone have suggestions?
    Post an attempt?
    Google FAQs?
    Read your book?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    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
    I'm just trying to be a better person - My Name Is Earl

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    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?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User
    Join Date
    Nov 2006
    Posts
    5
    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.

  8. #8
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    You could use nested for loops
    I'm just trying to be a better person - My Name Is Earl

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    > he wants us to use * to display the circle.
    Ah, simple 80x25 character display - that should be easy enough.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  10. #10
    In the Land of Diddly-Doo g4j31a5's Avatar
    Join Date
    Jul 2006
    Posts
    476
    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?

  11. #11
    Registered User
    Join Date
    Nov 2006
    Posts
    5
    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;
    	float radius;
    public:
    	//constructors
    	Circle() //radius = 0, center = (0,0)
    	{
    		radius = 0;
    	}
    	Circle(float r) //radius = r, center = (0,0)
    	{
    		radius = r;
    	}
    	Circle(Point P, float r) //radius = r, center = P
    	{
    		radius = r;
    		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;
    		cout << "Enter radius: ";
    		cin >> CC.radius;
    		return in;
    	}
    	friend ostream & operator >>(ostream &out, Circle &CC) //needs 2D array
    	//scale
    	void operator * (float a)
    	{
    		radius = radius*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
    		float radtotal = C1.radius+C2.radius; //sum of radii
    		if(radtotal > distance)
    		{
    			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
    		float radtotal = C1.radius+C2.radius; //sum of radii
    		if(radtotal > distance)
    		{
    			return false;
    		}
    		else
    		{
    			return true;
    		}
    	}
    	friend bool operator < (Circle C1, Circle C2)
    };

    i still need the *'s to print the circle

  12. #12
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Fixing the syntax errors first would be good.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  13. #13
    In the Land of Diddly-Doo g4j31a5's Avatar
    Join Date
    Jul 2006
    Posts
    476
    >>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.

  14. #14
    Registered User
    Join Date
    Nov 2006
    Posts
    5
    well sorta running low on time and cant on this project

  15. #15
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    On an 80x25 display, you could start with
    char display[25][80];

    Fill it with spaces.

    Use the parametric form of
    x = cx + r * cos(theta)
    y = cy + r * sin(theta)

    You don't need many angles to get a complete circle on such a small display.

    When you're done, just loop and print the array.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  2. circle problem
    By gunghomiller in forum C++ Programming
    Replies: 10
    Last Post: 07-14-2007, 06:40 PM
  3. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21