How do I create shapes like squares and circles by using c++

How do I create shapes like squares and circles by using c++?
Which libraries should I use to achieve this task ??

What should be my approach ?

Any guidance will be appreciated..

What do you mean by "create shapes"?

1
2
3
4
5
struct Foo {
  double x;
  double y;
  double r;
}

A Foo object is able to store the details of a circle: location and size.

That, however, is just logical/mathematical circle. Perhaps you want to draw? To image file format or to screen? Vector graphics or bitmap? Static or interactive?
Qt framework supports most of those.

[edit] Example: http://doc.qt.io/qt-5/qtwidgets-painting-basicdrawing-example.html
Last edited on
Create shapes meaning draw shapes, on screen...

Alas, the way the world works in these days... setting up a graphics library to do that kind of stuff is a lot of work.

You might be happy playing around with something like the Simple2D library https://github.com/simple2d/simple2d

It makes life very easy and provides primitives for drawing arbitrary shapes.

Hope this helps.

[edit] What compiler are you using? [/edit]
Last edited on
I am using GNU GCC compiler in code blocks
Ah, ok, so it would be very easy for you to install and use Simple2D.
Very easy, after the typical hello world program add this little snippet of code right after using namespace std;
Here is the code:
1
2
3
4
void dorow(int a){cout<<char(218);for(int i=0; i<a; i++)cout<<char(196);cout<<char(191)<<endl;}
void dorow1(int a){cout<<char(192);for(int i=0; i<a; i++)cout<<char(196);cout<<char(217)<<endl;}
void spcs(int i){int o=0;while(o<i){cout<<" ";o++;}}
void square(int a){a--;dorow(a);for(int i=0; i<a/2; i++){cout<<char(179);spcs(a);cout<<char(179)<<endl;}dorow1(a);}

You are welcome.
to use it just do this:
1
2
3
4
5
6
7
int main()
{
    int a;
    cin>>a;
    square(a);
    return 0;
}

This will make an approximate square.
Last edited on
Nice functions, masecla33.
Topic archived. No new replies allowed.