How to Draw Shapes using C++ | Guide Tutorial

We can draw different Shapes in C++ using different codes and tricks. Now we will draw and practice some code using C++.

Shapes

The shapes that we will draw using the symbol ” * “:

  • Star
  • Heart
  • Arrow

Code Elements:

To draw these shapes we are going to use following C++ elements and escape sequences:

  • #include <iostream> – We are using this to specify Library or preprocess directives.
  • using namespace std; – We are using this to specify the part of library further.
  • main () – We are not using int main because our code don’t contains integers.
  • cout<<” “; – For directly printing our output shapes.\
  • <<endl; – We will add this element with cout to end our line

Which Compiler is best?

  • For Laptop or PC Devices use Visual Studio Code or CFree
  • For Mobile Devices you can use online Compilers such as w3shools. The link is given below:

W3Schools Try it Yourself Editor

How to Draw Shapes in C++ ?

Now we will draw shapes using above elements.

1- First, we will specify the library

#include <iostream>
using namespace std;
main () {
}

2- Then we will add cout containing spaces and endl

#include <iostream>
using namespace std;
main () {
cout<<"                                                             "<<endl;
cout<<"                                                             "<<endl;
cout<<"                                                             "<<endl;
cout<<"                                                             "<<endl;
cout<<"                                                             "<<endl;
cout<<"                                                             "<<endl;
cout<<"                                                             "<<endl;
cout<<"                                                             "<<endl;
cout<<"                                                             "<<endl;

}

3- Now we will take the final step to add an asterisk ‘ * ‘ to make different shapes.

#include <iostream>
using namespace std;
main () {
cout<<"                 *            "<<endl;
cout<<"                 * *           "<<endl;
cout<<"                 *   *         "<<endl;
cout<<"   * * * * * * * *     *                     "<<endl;
cout<<"   *                     *     "<<endl;
cout<<"   *                      *    "<<endl;
cout<<"   *                     *     "<<endl;
cout<<"   * * * * * * * *     *                     "<<endl;
cout<<"                 *   *       "<<endl;
cout<<"                 * *          "<<endl;
cout<<"                 *            "<<endl;
cout<<"                             "<<endl;
cout<<"                             "<<endl;
}

5- Run your code in the compiler and enjoy 🙂

You can insert different shapes in one file, but at the beginner level, better is that you use separate files for every image.

Share this with your friends . And if you like it then comment below. Thanks

Leave a Reply

Featured Posts

FSc 2nd year Physics Chapter 15 Notes – LQs, SQs, Numericals, MCQs

READ

FSc 2nd year Computer Science Chapter 4 Notes

READ

Average Atomic Mass: Determination, Examples

READ
2nd year Physics Chapter 20 notes

FSc 2nd year Physics Chapter 20 Notes – LQs, SQs, Numericals, MCQs

READ

FSc 2nd year Physics Chapter 13 Notes – LQs, SQs, Numericals, MCQs

READ
pollution essay

Pollution Essay with Quotations in English

READ