WAP- Write A C / C++ program to Generate & Print the MAP OF India on screen

3 comments
/* The following C / C++ program when executed generates the MAP OF India & prints it on screen. */

#include<iostream>
using namespace std;
int main (void) {
    int a=10, b=0, c=10;
    char* bits ="TFy!QJu ROo TNn(ROo)SLq SLq ULo+UHs UJq TNn*RPn/QPbEWS_JSWQAIJO^NBELPeHBFHT}TnALVlBLOFAkHFOuFETpHCStHAUFAgcEAelclcn^r^r\\tZvYxXyT|S~Pn SPm SOn TNn ULo0ULo#ULo-WHq!WFs XDt!";
    a = bits[b];
    while (a != 0) {
        a = bits[b];
        b++;
        while (a > 64) {
            a--;
            if (++c == 'Z') {
                c /= 9;
                putchar(c);
            } else {
                putchar(33 ^ (b & 0x01));
            }
        }
    }
  
system("pause");
}



Output :
WAP- Write A C / C++ program to Generate & Print the MAP OF India on screen
WAP- Write A C / C++ program to Generate & Print the MAP OF India on screen

More details about this code:
Basically, the string is a run-length encoding of the image: Alternating characters in the string say how many times to draw a space, and how many times to draw an exclamation mark consecutively. Here is an analysis of the different elements of this program:

The encoded string

The first 31 characters of this string are ignored. The rest contain instructions for drawing the image. The individual characters determine how many spaces or exclamation marks to draw consecutively.

Outer for loop

This loop goes over the characters in the string. Each iteration increases the value of b by one, and assigns the next character in the string to a.

Inner for loop

This loop draws individual characters, and a newline whenever it reaches the end of line. The number of characters drawn is a - 64. The value of c goes from 10 to 90, and resets to 10 when the end of line is reached.

3 comments:

Unknown said...

This Code To Print Map of India can be Obfuscated even more with the For Loop which is:
for(; x-- > 64 ; )
putchar ( ++z=='Z' ? z = z/ 9:33^y&1);

Source: http://www.codingalpha.com/print-map-of-india-c-program-obfuscated-code/

However, you're program is better to understand though!

Unknown said...

can you modify this code to suit turbo c++?

Vibhutesh said...

Just drop the using namespace and in place of iostream use iostream.h.