C++ gurus and learners, we program ourselves :P all work is CC licensed

Sunday, December 22

C++ geometry [for game projects and similar]

15:17 By

Hi.
 Let's just call it a graphics function blog thoe i just know 2 or 3 of them but they'll be enough for simple drawing.

 This will require gotoxy function which is mentioned in a blog from Umair Sajid. The recap is as follow:
________________________________________________________________
#include <iostream>
#include <windows.h>

void gotoxy ( int , int );       //prototype
{main function and stuff}
void gotoxy(int x,int y)       //header. with x and y as coordinates to where cursor goes
{
     HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
                                         //output handle to be defined for function
     COORD coordinates;
                                         //COORD is a data type of windows.h header to store 2D graphic position's                                                  coordinates.
     coordinates.X = x;
                                         //save x coordinate value into the COORD structure's data type
     coordinates.Y = y;
                                         //similarly for y axis coordinate
     SetConsoleCursorPosition( hOut , coordinates );
                                         //finaly the function which set's the position of the cursor that you
                                           gave
}
define it and then you are good to go for the graphics functions
=======================================================================
  1. Simple lines:
     To understand this, just look up to coordinates of a simple line:
They change in a simple manner:
x,y
x+1,y
x+2,y
x+3,y
x+4,y
x+5,y
Here is a more understandable form:
x,y
++x,y
++x,y
++x,y
++x,y
++x,y
so here is the functions:
________________________________________________________________________
1. Horizontal line:
void horizontal_line(int , int , int);
void horizontal_line(int x, int y, int size)
{
      for(int i=0;i<size;i++)
      {
            gotoxy(x,y);
            cout<<char(219);
            x++;
      }
}
2. Vertical line:
void vertical_line(int , int , int);
void vertical_line(int x, int y, int size)
{
      for(int i=0;i<size;i++)
      {
            gotoxy(x,y);
            cout<<char(219);

            y++;
      }
}
=======================================================================
 2. Simple squares:
void square(int , int , int , int);
void square( int x, int y, int width, int length )
{
       int t_x;
       for(int i=0;i<length;i++)
       {
              t_x=x;
              for(int j=0;j<width;j++)
             {
                     gotoxy(t_x,y);
                     cout<<char(219);
                     t_x++;
             }
              y++;
        }
}
=======================================================================
You can also use colours for making it better.
Errors in code are possible as i did'nt made it on compiler so don't think that it won't work. In case of any problem you can email me.
That's all. I hope this'll help ya with simple interfaces. I'll give other methods for circle, hollow square ( completely hollow ) when obviously i need to make them and use them :)
Asslam-o-Alalikum.

Saturday, December 14

Use of ascii characters to print table in console


A post on using ascii chart for printing a table in console
#include <iostream>
using namespace std;

int main() {
 char topLeftCorner = (char)201, bottomLeft = (char)200, topRight= (char)187;
 char bottomRight = (char)188, horizontal = (char)205, vertical = (char)186;

 cout<<topLeftCorner;

 for(int i=0; i<10;i++)
  cout<<horizontal;

 cout<<topRight<<endl;

 cout<<vertical;

 for(int i=0;i<10;i++)cout<<' ';

 cout<<vertical;
 cout<<endl<<bottomLeft;

 for(int i=0; i<10;i++)
  cout<<horizontal;

 cout<<bottomRight;

 //or you can use ascii character 219 for all of the purposes, it is very easy to use
 return 0;
}

Wednesday, December 11

sorting of character arrays based on first character only

18:50 By

A code for Sir Saeed

/**
 * code by http://CppQA.blogspot.com
 * sorting of character arrays based on first character only
 * C++
*/
#include <iostream>
#include <string.h>
using namespace std;

int main() {
 char countries[5][15] = {"Pakistan","India","Afghanistan","Iran","China"};
 for(int i=0;i<5;i++)
 {
  for(int j=0;j<5-1;j++)
  {
   if(countries[i][0] < countries[j][0])
   {//swaping
    char temp[15];
    strcpy(temp,countries[i]);
    strcpy(countries[i],countries[j]);
    strcpy(countries[j],temp);
   }
  }
 }
 
 //print
 for(int i=0;i<5;i++)cout<<countries[i]<<endl;
 return 0;
}

Sunday, December 8

Filing in C++

13:37 By

Its very irritating to input again and again and best way to avoid it is FILING and it is pretty simple :)

Code:

 #include<iostream.h>
 #include<conio.h>
 #include<fstream.h>
 void main(){

   char name[15];

//---------------- READING FROM  FILE ---------------

ifstream insertion("contries.txt");

cout<<"\t\tReading data from file contries.txt\n\n"<<endl;

   while(insertion>>name)
   {
    cout<<name<<endl;
   }

insertion.close();

//--------------- WRITING IN FILE ------------------

//to clear the data of "data.txt" so that new content overwrites the file

// if u want to append new data to previous file skip the following two lines

ofstream empty("data.txt");

empty.close();

 //writing new data in "data.txt"

cout<<"\t\tWriting following data in file data.txt\n\n"<<endl;

int copyng[]={1995,1996,1997,1998,1999,2000,0,8,7,6};
ofstream burr("data.txt",ios::app);

int n=sizeof(copyng)/sizeof(copyng[0]);     //to find out the size of array in terms of # of elements

   for(int i=0;i<n;i++)
   {
   cout<<copyng[i]<<endl;
   burr<<" "<<copyng[i]; }
   burr.close();
   cout<<"\n\t\tPress any key to exit"<<endl;
   getche();
   }





Note:
 Your .txt file should be in the same location as that of your .cpp file.

For More Info:

For more details and possible values of parameters visit the link below
http://www.cplusplus.com/doc/tutorial/files/
Include filing in your programs and ENJOY


Regards





Sunday, November 24

Moving Text - SCreen Saver in C++

Moving Text - SCreen Saver in C++

Although it is exam time but i just can't help myself from compiler;; below is just code, nothing much to explain; just copy past and run it is compatible with visual studio as no graphic thing is used; enjoy

  1. #include<iostream>
  2. #include<windows.h>
  3. HANDLE out=GetStdHandle(STD_OUTPUT_HANDLE);
  4. void clr(int y){SetConsoleTextAttribute(out,y);}
  5. void go(int a,int b){COORD cord; cord.X = a; cord.Y = b; SetConsoleCursorPosition(out,cord);}
  6. using namespace std;
  7. void G(int x,int y)
  8. {go(x,y);cout<<char(220)<<char(220)<<char(220)<<char(220)<<char(220)<<endl; y++;
  9. go(x,y);cout<<char(219)<<char(32)<<char(32)<<char(32)<<char(219)<<endl; y++;
  10. go(x,y);cout<<char(219)<<char(32)<<char(32)<<char(32)<<char(32)<<endl; y++;
  11. go(x,y);cout<<char(219)<<char(32)<<char(32)<<char(223)<<char(219)<<endl; y++;
  12. go(x,y);cout<<char(223)<<char(223)<<char(223)<<char(223)<<char(223)<<endl;}
  13. void A(int x,int y)
  14. {go(x,y);cout<<char(220)<<char(220)<<char(220)<<char(220)<<endl; y++;
  15. go(x,y);cout<<char(219)<<char(32)<<char(32)<<char(219)<<endl; y++;
  16. go(x,y);cout<<char(219)<<char(220)<<char(220)<<char(219)<<endl; y++;
  17. go(x,y);cout<<char(219)<<char(32)<<char(32)<<char(219)<<endl; y++;
  18. go(x,y);cout<<char(219)<<char(32)<<char(32)<<char(219)<<endl;}
  19. void M(int x,int y)
  20. {go(x,y);cout<<char(219)<<char(220)<<char(32)<<char(220)<<char(219)<<endl; y++;
  21. go(x,y);cout<<char(219)<<char(32)<<char(287)<<char(32)<<char(219)<<endl; y++;
  22. go(x,y);cout<<char(219)<<char(32)<<char(32)<<char(32)<<char(219)<<endl; y++;
  23. go(x,y);cout<<char(219)<<char(32)<<char(32)<<char(32)<<char(219)<<endl; y++;
  24. go(x,y);cout<<char(219)<<char(32)<<char(32)<<char(32)<<char(219)<<endl;}
  25. void E(int x,int y)
  26. {go(x,y);cout<<char(220)<<char(220)<<char(220)<<char(220)<<char(220)<<endl; y++;
  27. go(x,y);cout<<char(219)<<char(32)<<char(32)<<char(32)<<char(32)<<endl; y++;
  28. go(x,y);cout<<char(219)<<char(205)<<char(205)<<char(32)<<char(32)<<endl; y++;
  29. go(x,y);cout<<char(219)<<char(32)<<char(32)<<char(32)<<char(32)<<endl; y++;
  30. go(x,y);cout<<char(223)<<char(223)<<char(223)<<char(223)<<char(223)<<endl;}
  31. void R(int x,int y)
  32. {go(x,y);cout<<char(220)<<char(220)<<char(220)<<char(220)<<char(220)<<endl; y++;
  33. go(x,y);cout<<char(219)<<char(32)<<char(32)<<char(32)<<char(219)<<endl; y++;
  34. go(x,y);cout<<char(219)<<char(220)<<char(220)<<char(220)<<char(219)<<endl; y++;
  35. go(x,y);cout<<char(219)<<char(32)<<char(32)<<char(219)<<char(32)<<endl; y++;
  36. go(x,y);cout<<char(219)<<char(32)<<char(32)<<char(219)<<char(220)<<endl;}
  37. int main()
  38. {
  39. int X=0,x1,x2,x3,x4,x5,x6,y=5; x1=0; x2=6; x3=12; x4=18; x5=24; x6=30;
  40. for (int i=0;i<1;)
  41. {clr(9);go(x1,y);G(x1,y);if(x1>72){x1=1;}x1++;clr(12);go(x2,y);A(x2,y);if(x2>72){x2=1;}x2++;
  42. clr(6);go(x3,y);M(x3,y);if(x3>72){x3=1;}x3++;clr(9);go(x4,y);M(x4,y);if(x4>72){x4=1;}x4++;
  43. clr(10);go(x5,y);E(x5,y);if(x5>72){x5=1;}x5++;clr(12);go(x6,y);R(x6,y);if(x6>72){x6=1;}x6++;
  44. if(x1==2){y+=3;} if(y>50){y=3;}system("cls");}
  45. return 0;
  46. }
for feedback:



    
    

    Saturday, November 23

    Hollow Square & Hollow diamond & Hollow Triangle

    Hollow Square & Hollow diamond & Hollow Triangle

    It's basically a request from a student as we go further in loops and functions we need to know more tricks and practise more for these things which eventually leads to good programming;
    Basic concept to understand;
    1. Notice if any line of the shape is going to match original filled shape; i.e. in square the first line and last line are filled!
    2. Make sure you know the ration of spaces for hollow part to the number of characters in the corresponding filled space i.e. if your square is of the size of 5x5 so it is going to be 5 characters in a single line; but in hollow shape you are going to print only 2 characters ; the first one and last one no matter how much long line is this; but here in 5 character line the total spaces would be countable as spaces=one side length - 2;
    Prepare for the basic shapes looping that will be joined together to make final shape i.e. to make diamond you place 4 triangles together if you ever made it:

    Hence by mixing these points you can make logic of this king of shapes.

    Basic Hollow looping;
    In this kind of looping you have to make sure that ration of lines is safely described to make appropriate loop
    Square concept:
    1. int main()
    2. {
    3.         int size;            //suppose it is 5
    4.         cin>>size;
    5.         for (int i = 0 ; i < size ; i++ ) //runs 5 times
    6.          {
    7.                  cout  <<  "*" ;          //first char
    8.                  for (int j=2;j<size;j++) //runs 5-2 times
    9.                  {
    10.                      cout<<" ";
    11.                  }
    12.                  cout  <<  "*" ;          //last char
    13.           }
    14.    return 0;
    15. }
    Now here in line 8 you can see that formula which subtracts number of characters from hollow line to make it even to the rest of shape, it could be 5 - 3  or maybe  5-4  required for the program hence the distribution of spaces and loops as well; depending on the shape.
    And for first and last line here is simple method:
    1.  if ( line 1 || last line ) //mean i==1 or i==size-1 according to loop iteration
    2.  {
    3.          for ( int a=0;a<size;a++ )
    4.          {
    5.              cout<< "*" ;
    6.          }
    7.       cout << endl ; continue ;
    8.  }
    Put it in main loop Before the space loop so that if first line is being print it would print it and skip the space printing for first and last line.
    i guess it is enough for the basic concept and you will be able to make assignment ;; I'll give complete codes after exams;; thanks for reading and for feedback or any questions:
    Join the group  on facebook for constant news about new posts..
    
    

    Friday, November 22

    gotoxy() function in c++ by Umair Sajid

    21:49 By

    gotoxy() function :

    The gotoxy function is used to to move the cursor to a specified location on the screen. Its Just Something Other then just Sequential Execution .It moves the cursor with respect to x axis and y axis. It is very useful when the output is to be displayed at a specified location on the screen.

    Working: 

    The Variable x indicates x-axis. Its Value can be from 0 to 79. The Variable y indicates the y-axis. Its Value can be from 0 to 24.

    Program:

    #include               // Header Files 
    #include               // for getch() function 
    #include               
    #include             // Necessary when treating consoles  
    using namespace std;
    void gotoxy (int x, int y)
        {
             COORD coordinates;     // coordinates is declared as COORD
             coordinates.X = x;     // defining x-axis
             coordinates.Y = y;     //defining  y-axis
            SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coordinates);       
        }
    int main()              
    {
        int x;
        int y; 
     
        cout<<"Enter x: ";
        cin>>x;
        cout<<"Enter y: ";
        cin>>y;
            
        gotoxy(x,y);     // function call 
        cout<<"C++ Clan Umair Sajid"<<endl;
        getch();
        return EXIT_SUCCESS;
    }
    

    Tuesday, November 19

    Easy Colouring

    As promissed here is bit easy technique for those colour commands;
    Hope you guys understand it :
    Theme here is to use funcitons to determin command stuff i.e. how much easy would it be if you only have to type 

    color(r); //red colour

    here is the function that will help you to use colours easily
    ______________________________________________________________________

    1. HANDLE Output=GetStdHandle(STD_OUTPUT_HANDLE);
    2. void colour(int x)
    3. {SetTextAttribute(Output,x);}
    ______________________________________________________________________
    here if you remember colour codes integers just use them as follows:

    colour(10);      //green


    and if you want to make it runing upon character values you can place switch in it

    1. HANDLE Output=GetStdHandle(STD_OUTPUT_HANDLE);
    2. void colour(char ch)
    3. {
    4. int x;
    5. switch (ch)
    6. {
    7. case 'r':  x=12; break;                       //red
    8. case 'b': x=9;   break;                        //blue
    9. case 'g': x=10; break;                        //green
    10. case 'a': x=11; break;                        //aqua
    11. case 'v': x=13; break;                         //voilet
    12. case 'y': x=14; break;                         //yellow
    13. case 'w: x=15; break;                         //white
    14. }
    15.  SetTextAttribute(Output,x);
    16. }

    now you can call it as this;
    colour('r');                    //red colour
    end of post;



    
    

    Monday, November 18

    Play Sound in Your CPP Program

    Till now, all of us have coded C++ programs on the black & white console, some know how to color the text on string.
    Lets go a step ahead and introduce sound being played as your program runs.

    Interesting, Right?
             Yes, you'll have a new effect to add in your code :-)

    How to Do?
             The amazing sound feature consists of just two lines,
    1. The PlaySound function call.
    2. The header file that contains this function.

    Code:
               
     #include<iostream.h>
     #include<conio.h>
     #include <string.h>
     #include <windows.h>
     using namespace std;
            
     int main()
     {
                     PlaySound("file_name.wav",NULL,SND_FILENAME|SND_LOOP);
     // PlaySound method is defined in windows.h
     // file_name is the name of your sound file in .wav format
     getche();
     return 0;
     }

    Note:
     Your .wav file should be in the same location as that of ur .cpp file.

    More:


    For details and possible values of parameters in PlaySound function visit the link below
    http://msdn.microsoft.com/en-us/library/windows/desktop/dd743680(v=vs.85).aspx
    Include sound in your programs and have FUN
    Stay Blessed :-)


    Regards

    
    

    Bit Level Manipulation and Programming in C++

    C++ is a classical language and it allows us to manipulate bits in much better ways. for starter we will learn 2 kind of bit operators namely bit shift operators

    Left shift operator: <<
    Right shift operator: >>

    The left shift operator shifts all bits to left and left most bit(MSB) is dropped/deleted
    similarly the right shift operator shifts all bits to right and LSB(right most bit) is dropped

    e.g. binary of 2 will be 00000010 which is when shifted to left becomes 00000100 which in decimal is 4
    so it also means that shifting to left multiplies by 2 and shifting to right divides by 2.

    void main()
    {
    int castles = 2;
    castles = castles<<1; //this will set castles = 4 i.e. 2x2
    castles <<=2; //this will left shift by 2 bits and hence castles is now multiplied by 2 two times so it now becomes 16
    //you can experiment for your self with these tricks
    //PS these are heavily used for masking purposes and files compression as well
    

    Reverse any Integer without strings

    It seems now are a stronger community to write generalized programs for FAST NU as well :)
    I am posting a program below which reverses any number with just 1 while loop.
    See if it works :P
    PS please if you copy this or get inspired from this post for your blog then mention us in the post that will be a great gesture than just being douche 3:)
    //Code by Umar Farooq
    /**
     * follow us at http://CppQA.blogspot.com
     * 
    **/
    #include <iostream>
    using namespace std;
    
    int main() {
     int number = 12345678;
     cout<<"Reverse of number "<<number<<" is ";
     while(number)
     {
      cout<<number%10;
      number/=10;
     }
     
     return 0;
    }
    

    Sunday, November 17

    Loading bar in C++

    Since we are high on special effects these days, so below is the code to make a loading bar in C++.

    #include iostream.h
    #include conio.h
    #include windows.h
    #include dos.h
    
    void main()
    {
     system("color 0a");
     cout<<"\n\n\n\t\t\t\tPlease wait while loading\n\n";
     char a=177, b=219;
     cout<<"\t\t\t\t";
     for (int i=0;i<=15;i++)
     cout<<a;
     cout<<"\r";
     cout<<"\t\t\t\t";
     for (int i=0;i<=15;i++)
     {
      cout<<b;
      for (int j=0;j<=1e8;j++); //You can also use sleep function instead of for loop
     }
    
     clrscr();
     cout<<"\n\n\n\t\t\tHELLO WORLD\n\n\t\t\tShashka made by Ivan :P";
    
     getch();
    }

    Output is :

    Addition of two 2-Dimensional Arrays

    Below is the code that I made to add the elements of a 2-D array.
    The 2-dimensional arrays have been previously discussed, what they are and how to initialize them.
    http://cppqa.blogspot.com/2013/11/two-dimension-pointers-c.html

    For those (like me) who are still confused, think of it like this,
    An 1-dimensional array can hold element like this:
    [ 1 3 5 7 9]    => array1[5]

    Whereas a 2-D array will hold elements much like a matrix, like this:
    | 2  4 |
    | 6  8 |            => array2[2][2]
    So we get a matix of 2rows and 2 columns.

    Now that we have a basic concept of 2-D array, lets go a little further.
    The initialization is petty much same as that in the above link. We shall only do the addition of 2-D arrays.

    int main()
    {
    int x[2][2] , y[2][2] , z[2][2];
    //for simplicity 2,2 matrix is used, but you can also make a user specified
    
    int i , j , k;
    
    cout<<"enter number for 1st matrix"<<endl; //applying for loop to enter the data
    
    for( i = 0 ; i < 2 ; i++)
    for( j = 0 ; j < 2 ; j++)
    {
    cin>>x[i][j];
    }
     
    cout<<"enter numbers for 2nd matrix"<<endl;
    for( i = 0 ; i < 2 ; i++)
    for( j = 0 ; j < 2 ; j++)
    {
    cin>>y[i][j];
    }
    
    for( i = 0 ; i < 2 ; i++)
    for( j = 0 ; j < 2 ; j++)
    {
    z[i][j] = 0;
    for( k = 0 ;k < 2 ; k++)
    z[i][j]=x[i][j]+y[i][j]; // x + y stored in z
    }
    
    cout<<"additon of matrix is"<<endl;   // z is displayed
    for( i = 0 ; i < 2 ; i++)
    {
    for( j = 0 ; j < 2 ; j++)
    cout<<z[i][j]<<"\t";
    cout<<"\n";
    }
    getch();
    return 0;
    }
    
    
    So here it is a simple program to add two 2-D arrays

    Saturday, November 16

    Recursive functions

    19:30 By

    Recursive functions

    Recursive functions are way much difficult then simple functions
    1. in a function you place set of commands in a bracket and use it as many time as u want
    2. in recursive functions you make such a function which with the help of other functions and the repetition of it's own body gives you output ; complex but short code.
    As compared to recursive function simple function when called runs specific commands inside it's body (could be loop but still simple as for command) it's decision criteria is small or let's say limited.
    In recursive function you make some kind of super function which has wide choice of features including that it's body is small.
    Definition: When a function calls itself or other functions while execution it is said to be recursive function.
    Here is a simple example : 
    To print a countdown form a digit that user inputs up to '0'
    1. #include <iostream>
    2. using namespace std;
    3. void sample_recursive_function(int N)
    4. {
    5.            if (N==0) { cout<<"N"<<endl; }
    6.          else  { cout<<"N"<<endl; --N; sample_recursive_function(N);}
    7. }
    8. int main()
    9. {
    10.           int N;
    11.           cout<<"Enter the number: ";
    12.           cin>>N;
    13.           sample_recursive_function(N);
    14.           return 0;
    15. }
    Enter the number: 5                                                                                                                                                       
    5                                                                                                                                                                                              
    4                                                      -                                                                                                                                      
    3                                                                                                                                                                                              
    2                                                                                                                                                                                              
    1                                                                                                                                                ^   --                                     
    0                                                                                                                                                                       -                     
    Press any key to continue . . . .                                                                                                                                  

    In this function there is not much as coding or might say complex coding but it is a complex logic. This is what is difference between these functions.
    This function can also call other functions described in this program hence you can generate loop in which more then 1 functions will work with each other to generate desired output;

                 A -------------> B
                                          |
                  |                             |
                  |                             |
                  |                            V
                D <-------------  C
    In this diagram functions are related to each other because when you call one function in another function the control goes to this function and once this function is finished then it will allow for control to go back to main called function..
    Here is an example :
    1.              int sum(int a , int b )                                      //f1
    2.             {            
    3.                         int c=  a+b;
    4.                         if  ( check_type(c)  == 1 )
    5.                        { return c;
    6.                         else
    7.                                 c+=1;
    8.             }

    9.             int check_type(int x)                                   //f2
    10.             {
    11.                       int check=x; 
    12.                      if ( x%2==0 ) 
    13.                       { return 1;} 
    14.                      if ( c%2!=0 )
    15.                        { return 0; }
    16.             }
    Here f1 is calling f2 to change it's output. A simple recursive function.
    Hope you understood the concept of recursive functions; gud luck; Allah HAfiz

    Colour Coding in C++

    15:37 By

    The first time i saw colour in c++ was amazing experience because just black  and white stuff is more like old school comparing to modern software and  technology. It was hard to find well defined code and definition for colours in c++ language ; took me a while but i got it finally so here is this code in simple language, hope it helps you...

    _________________________________________________________________________
    To change whole screen colour i.e. foreground (text) and background, it is very simple and         easy command.

    The header file for this command is :                   <windows.h>
    The command   is :                                          system("Colour _ _");

    In place of _ _ you have to enter colour combination you want ; first place takes background colour and 2nd place takes foreground colour (text colourthis is list of all colours available for this command:

    1_____Blue                                       A______Light Green
    2_____Green                                    B______Light Aqua
    3_____Aqua                                      C______Light Red
    4_____Red                                        D______Light Purple
    5_____Purple                                   E______Light Yellow
    6_____Yellow                                   F______Bright White 
    7_____White
    8_____Gray
    9_____Light Blue
    0_____Black

    It's not perfact colouring but it is simple to use

    1. #include <iostream>
    2. #include <windows.h>
    3. using namespace std;
    4. int main()
    5. {
    6.            system("Color 0A");  // first 0 = black background second A = light green
    7.            cout<<"This is my fev. colour combination for this command"<<endl;
    8.       return 0;
    9. }
    This is my fev. colour combination for this command              
    
    
    Press any key to continue . . .                                                 
    =========================================================================

    The detailed coding

    _________________________________________________________________________
    To change minor colour i.e. colour of just 1 character so that we can use as much colour combinations ; it comes to this code because command showed above will not allow you to print 2 or more colours in single output combination. This command is not capable of changing whole background so i prefer to select background colour from system command and then change text colour from this code i'm about to share with you guys.

    This must be wirten at start of main:   HANDLE color=GetStdHandle(STD_OUTPUT_HANDLE);
    The header file for this command is :                   <windows.h>
    The command   is :                            SetConsoleTextAttribute(color, _ );


    In place of _ you have to enter colour code you want ; there is a brief list of some basic colours for this command:

    1_____Blue                                       10______Light Green
    2_____Green                                    11______Light Aqua
    3_____Aqua                                      12______Light Red
    4_____Red                                        13______Light Purple
    5_____Purple                                   14______Light Yellow
    6_____Yellow                                   15______Bright White 
    7_____White
    8_____Gray
    9_____Light Blue
    0_____Black


    1. #include <iostream>
    2. #include <windows.h>
    3. using namespace std;
    4. int main()
    5. {
    6.         HANDLE color=GetStdHandle(STD_OUTPUT_HANDLE); //just once
    7.         SetConsoleTextAttribute(color, 10);
    8.            cout<<"This";
    9.         SetConsoleTextAttribute(color, 11);
    10.         cout<<" is";
    11.         SetConsoleTextAttribute(color, 12);
    12.         cout<<" a";
    13.         SetConsoleTextAttribute(color, 13);
    14.         cout<<" colour";
    15.         SetConsoleTextAttribute(color, 14);
    16.         cout<<" combination"<<endl;
    17.       return 0;
    18. }
    This is a colour combination                                                   
    
    
    Press any key to continue . . .                                                 

    But the best thing is that it doesnot stops here at 15 ; you can go up to 300 for different colour combinations for headline your text on your program; enjoy
    Like this post then i will tell you how to use 2nd one command very easily like this:
    clr( _ );
    that's it..@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

    Ascii Art with C++

    While posts on shaskaas are going on let me share another tweak with you. As a trademark thingy you can insert your name with ascii art in beginning of your program and this will always impress your teachers. I used star wars theme always for my assignments and you can bet the marks i got :P
    
    

    We use figglet for generating asscii art Figglet Fonts

    Then i would just cout this text

    /**
    _    __  .___  ___.      ___      .______      
    |  |  |  | |   \/   |     /   \     |   _  \     
    |  |  |  | |  \  /  |    /  ^  \    |  |_)  |    
    |  |  |  | |  |\/|  |   /  /_\  \   |      /     
    |  `--'  | |  |  |  |  /  _____  \  |  |\  \----.
     \______/  |__|  |__| /__/     \__\ | _| `._____|
      
    **/                                               
    
    Happy Coding :P

    Friday, November 15

    Program that converts ASCII number to character and vice versa By Umair Sajid

    12:14 By

    This Program can also be done using if-else structure but switch statement is most appropriate. 


    #include<iostream>  /* Header Files */
    #include<stdlib.h>    
    #include<conio.h>    
    using namespace std; 
    int main() 
      int number,option; 
      char letter; 
     cout<<"1.Convert ASCII Value to Character "<<endl;
     
     cout<<"2.Convert Character to ASCII Value "<<endl;
     
     cout<<"Enter Your Choice :"; cin>>option;
     
     switch(option) 
     { 
     case 1:
       cout<<"Enter The Number :"; 
       cin>>number; 

       cout<<"The Corresponding character is :"<<char(number)<<endl;  break;
     
     case 2: 
       cout<<"Enter The Letter :";
       cin>>letter; 

       cout<<"ASCII Value of the letter is:"<<int(letter)<<endl; 
     break;
     
     default:
     cout<<"*** INVALID OPTION ***"; 
     break; 
     } 
     getch();
     }