Shapes in C++ using symbols & Characters

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

Code Elements:

To draw these shapes we are going to use the 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:

How to Draw Shapes in C++ ?

Now we will draw shapes using the 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<<"          ccc         "<<endl;
cout<<"         c            "<<endl;
cout<<"        c            "<<endl;
cout<<"         c            "<<endl;
cout<<"          ccc           "<<endl;
cout<<"                     "<<endl;
cout<<"                     "<<endl;


}

Final Code:

Now we will add others symbols to make new shapes

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


}

Output of Code:

Following is the output of the previous code.

Leave a Reply

Featured Posts

places to visit in dubai

Top 5 Most Beautiful Places to Visit in DUBAI

READ

Area of Triangle using C++ code of Hero’s Formula

READ

FSc 2nd year Computer Science Notes Complete of All Chapters

READ

FSc 2nd year Computer Science Chapter 9 Notes

READ

FSc 2nd year Pak Studies Notes Complete of All Chapters

READ
2nd year Chemistry Chapter 1 notes

FSc 2nd year Chemistry Chapter 1 Notes – Eiman.pk

READ