Thread: How to make circle in C++?

  1. #16
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Well I guess that's the way nowadays with the internet. Instead of getting a book and learning people just ask questions on forums.
    The point is, why are you providing "complete solutions" to someone that you may have to work with some day?

    By the way I do like that you posted a "complete solution" that any instructor in the world would know was not written by the OP.

  2. #17
    Registered User
    Join Date
    Jun 2017
    Posts
    157
    The point is, why are you providing "complete solutions" to someone that you may have to work with some day?
    I am not good at explaining things so I think some code might be easier to understand.
    When I learned programming 25+ ago I learned a lot from examples that came with the good old Turbo C++ and Turbo Pascal compilers - more than in school.

  3. #18
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    I am not good at explaining things so I think some code might be easier to understand.
    I understand, but it is even harder to explain things when the OP doesn't show any effort.

  4. #19
    Registered User
    Join Date
    Oct 2017
    Posts
    37
    hello
    how to make circle using c++
    code are not working in software

  5. #20
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by OldGuy2 View Post
    Well I guess that's the way nowadays with the internet. Instead of getting a book and learning people just ask questions on forums.
    On that NOTE:
    One might be surprised at what they do find on the internet if they'd only look.
    Use following code you'll get circle in star patters.

    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
        float r;
        cout << "Enter the Radius"<<endl;
        cin>> r;
        
        float pr = 2; // pr is the aspected pixel ratio which is almost equal to 2
        
        for (int i = -r; i <= r; i++) // loop for horizontal movement
        {
        for (int j = -r; j <= r; j++) // loop for vertical movement
        {
        float d = ((i*pr)/r)*((i*pr)/r) + (j/r)*(j/r); //multiplying the i variable with pr to equalize pixel-width with the height
        if (d >0.95 && d<1.08) // approximation
        {
        cout<< "*";
        }
        else
        {
        cout<<" ";
        }
        }
        cout << endl;
        }
        return 0;
    }
    Code:
    userx@slackwhere:~/bin
    $ ./circle
    Enter the Radius
    5
               
               
               
      *     *  
               
    *         *
               
      *     *
    Last edited by userxbw; 11-04-2017 at 09:45 AM.

  6. #21
    Registered User
    Join Date
    Oct 2017
    Posts
    37
    HI
    SIR IT IS WORKING
    how to make square ?

  7. #22
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    You need to learn how to program!

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  8. #23
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Quote Originally Posted by stahta01 View Post
    You need to learn how to program!

    Tim S.
    An excellent first step indeed

  9. #24
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by RITESHKAKKAR View Post
    HI
    SIR IT IS WORKING
    how to make square ?
    you already have a working model to work with. Modify it until you figure it out. It is not like you are going to lose it because it is kept safe here. so if you mess it too much just come back here get it then start again.

  10. #25
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Hold the horses! Wait! Take stock! Take a step back! What's going on? The challenge is to make a square circle?

  11. #26
    Banned
    Join Date
    Aug 2017
    Posts
    861
    I've seen stranger

  12. #27
    Registered User
    Join Date
    Oct 2017
    Posts
    37
    HELLO
    i build square also..
    how to make circle with graphic library


    How to make circle in C++?-1200px-circle-withsegments-svg-jpg
    Attached Images Attached Images How to make circle in C++?-untitled-jpg 

  13. #28
    Banned
    Join Date
    Aug 2017
    Posts
    861
    if you are using a gui api to do this then read the docs on the function calls. if you are using the two loop trick then take that one in here and figure it out. How is it getting the top 'point' the right side point, and left side point, and bottom, because it still applies.

    what graphics lib are you using? a standard one, or an auxiliary one?
    What exactly are you working with here?


    Code:
    // Drawing Functions
    void arc( int x, int y, int stangle, int endangle, int radius );
    void bar( int left, int top, int right, int bottom );
    void bar3d( int left, int top, int right, int bottom, int depth, int topflag );
    void circle( int x, int y, int radius );
    void cleardevice( );
    void clearviewport( );
    void drawpoly(int n_points, int* points);
    void ellipse( int x, int y, int stangle, int endangle, int xradius, int yradius );
    void fillellipse( int x, int y, int xradius, int yradius );
    void fillpoly(int n_points, int* points);
    void floodfill( int x, int y, int border );
    void line( int x1, int y1, int x2, int y2 );
    void linerel( int dx, int dy );
    void lineto( int x, int y );
    void pieslice( int x, int y, int stangle, int endangle, int radius );
    void putpixel( int x, int y, int color );
    void rectangle( int left, int top, int right, int bottom );
    void sector( int x, int y, int stangle, int endangle, int xradius, int yradius );
    everything you need should already be there.


    Using the WinBGIm Graphics Library with Dev-C++

  14. #29
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Quote Originally Posted by userxbw View Post
    if you are using a gui api to do this then read the docs on the function calls. if you are using the two loop trick then take that one in here and figure it out. How is it getting the top 'point' the right side point, and left side point, and bottom, because it still applies.

    what graphics lib are you using? a standard one, or an auxiliary one?
    What exactly are you working with here?


    Code:
    // Drawing Functions
    void arc( int x, int y, int stangle, int endangle, int radius );
    void bar( int left, int top, int right, int bottom );
    void bar3d( int left, int top, int right, int bottom, int depth, int topflag );
    void circle( int x, int y, int radius );
    void cleardevice( );
    void clearviewport( );
    void drawpoly(int n_points, int* points);
    void ellipse( int x, int y, int stangle, int endangle, int xradius, int yradius );
    void fillellipse( int x, int y, int xradius, int yradius );
    void fillpoly(int n_points, int* points);
    void floodfill( int x, int y, int border );
    void line( int x1, int y1, int x2, int y2 );
    void linerel( int dx, int dy );
    void lineto( int x, int y );
    void pieslice( int x, int y, int stangle, int endangle, int radius );
    void putpixel( int x, int y, int color );
    void rectangle( int left, int top, int right, int bottom );
    void sector( int x, int y, int stangle, int endangle, int xradius, int yradius );
    everything you need should already be there.
    There is your homework, userbxw: I would like you to write a "graphics" library that uses text mode and implement as many of those functions as you can.

  15. #30
    Registered User
    Join Date
    Oct 2017
    Posts
    37
    hello,
    Sir
    if you are using a gui api to do this then read the docs on the function calls. if you are using the two loop trick then take that one in here and figure it out. How is it getting the top 'point' the right side point, and left side point, and bottom, because it still applies.

    what graphics lib are you using? a standard one, or an auxiliary one?
    What exactly are you working with here?

    i have no idea how to use graphics library please tell how to this?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 08-09-2009, 02:39 PM
  2. Replies: 2
    Last Post: 07-08-2006, 04:42 PM
  3. Circle
    By rifatgunduz in forum C++ Programming
    Replies: 1
    Last Post: 01-26-2005, 03:56 PM
  4. Best way to draw circle!!??
    By OneStiffRod in forum Game Programming
    Replies: 12
    Last Post: 04-28-2003, 07:57 AM
  5. Circle in C
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 11-06-2001, 09:00 AM

Tags for this Thread