A creative C++ program to Zoom digits of an integer - GeeksforGeeks

29 May, 2017
Write a C (or C++) program to ZOOM (magnify) the digits of an integer. It should take an integer from the user and display each digit of the integer in magnified form using some pattern.
Examples:
Input : 123
Output : 

  @
 @@
  @
  @
@@@@@
-------------------------------

@@@@
@  @
  @
 @
@@@@
-------------------------------


@@@@@
    @
@@@@@
    @
@@@@@
-------------------------------


This creative program takes an integer from the user and print each and every digit of that integer after zooming it.
The given number is first converted to string using stringstream. After that, each character (digit) is accessed and put to switch-case structure which ZOOMED each digit and printed in the form of pattern.
Below is C++ implementation
// C++ program to zoon digits of an integer#include <bits/stdc++.h>using namespace std;  void zoomDigits(int number){    // Converting number to string    stringstream ss;    ss << number;    string str = ss.str();      for (int k=0; k<str.length(); k++)    {        switch(str[k]-'0')        {        case 0:            for (int i=0; i<5; i++)            {                for (int j=0; j<5; j++)                {                    if (i==0 || i==4)                        cout << '@';                    else if (j==0 || j==4)                        cout << '@';                    else                        cout << " ";                  }                cout << endl;            }            cout << "-------------------------------\n\n";            continue;          case 1:            for (int i=0; i<5; i++)            {                for (int j=0; j<5; j++)                {                    if (j==2)                        cout << '@';                    else if ((i==1 && j==1))                        cout << '@';                    else if (i==4)                        cout << '@';                    else                        cout << " ";                  }                cout << endl;            }            cout << "-------------------------------\n\n";            continue;          case 2:            for (int i=0; i<5; i++)            {                for (int j=0; j<4; j++)                {                    if (i==0 && j==4)                        cout << " ";                    else if (i==0 || i==4)                        cout << '@';                    else if (i==1 && j==0)                        cout << '@';                    else if (i==(4-j))                        cout << '@';                    else                        cout << " ";                }                cout << endl;            }            cout << "-------------------------------\n\n";            continue;          case 3:            for (int i=0; i<5; i++)            {                for (int j=0; j<5; j++)                {                    if (i==0 || i==2 || i==4)                        cout << '@';                    else if (j==4)                        cout << '@';                    else                        cout << " ";                }                cout << endl;            }            cout << "-------------------------------\n\n";            continue;          case 4:            for (int i=0; i<5; i++)            {                for (int j=0; j<5; j++)                {                    if (j==4)                        cout << '@';                    else if (i==2)                        cout << '@';                    else if (j==0 && (i==0 || i==1))                        cout << '@';                    else                        cout << " ";                }                cout << endl;            }            cout << "-------------------------------\n\n";            continue;          case 5:            for (int i=0; i<5; i++)            {                for (int j=0; j<5; j++)                {                    if (i==0 || i==2 || i==4)                        cout << '@';                    else if ((j==0 && i==1) ||                             (j==4 && i==3))                        cout << '@';                    else                        cout << " ";                }                cout << endl;            }            cout << "-------------------------------\n\n";            continue;          case 6:            for (int i=0; i<5; i++)            {                for (int j=0; j<5; j++)                {                    if (i==0 || i==2 || i==4)                        cout << '@';                    else if ((j==0 && (i==1 || i==3)) ||                                       (j==4 && i==3))                        cout << '@';                    else                        cout << " ";                }                cout << endl;            }            cout << "-------------------------------\n\n";            continue;          case 7:            for (int i=0 ; i<5; i++)            {                for (int j=0 ; j<5; j++)                {                    if (i==0 && (j!=4))                        cout << '@';                    else if (i==2 && (j==2 || j==4))                        cout << '@';                    else if (j==3)                        cout << '@';                    else                        cout << " ";                }                cout << endl;            }            cout << "-------------------------------\n\n";            continue;          case 8:            for (int i=0; i<5; i++)            {                for (int j=0; j<5; j++)                {                    if (i==0 || i==2 || i==4)                        cout << '@';                    else if ((j==0 && (i==1 || i==3) ||                            (j==4 && (i==1 || i==3))))                        cout << '@';                    else                        cout << " ";                }                cout << endl;            }            cout << "-------------------------------\n\n";            continue;          case 9:            for (int i=0; i<5; i++)            {                for (int j=0; j<5; j++)                {                    if ( i==0 || i==2 || j==4)                        cout << '@';                    else if (i==1 && j==0)                        cout << '@';                    else                        cout << " ";                }                cout << endl;            }            cout << "-------------------------------\n\n";            continue;        }    }}  // Driver codeint main(){    long long number = 12305;    zoomDigits(number);    return 0;}
Output:

  @
 @@
  @
  @
@@@@@
-------------------------------

@@@@
@  @
  @
 @
@@@@
-------------------------------

@@@@@
    @
@@@@@
    @
@@@@@
-------------------------------

@@@@@
@   @
@   @
@   @
@@@@@
-------------------------------

@@@@@
@
@@@@@
    @
@@@@@
-------------------------------

This article is contributed by MAZHAR IMAM KHAN. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
cpp-puzzle
C++
CPP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Inheritance in C++
Map in C++ Standard Template Library (STL)
C++ Classes and Objects
Operator Overloading in C++
Socket Programming in C/C++
Bitwise Operators in C/C++
Multidimensional Arrays in C / C++
Virtual Function in C++
Constructors in C++
Templates in C++ with Examples