Thoughts Of The Day

INTERESTING FUNCTIONS IN GRAPHICS

                  Going forward in this Advance Learning Tutorial of C/C++ Today we are going to tell you about some of the very important and fantastic functions. by using these functions your programs can be make more attractive. These functions are work both Text and Graphics modes.

           So, before starting graphics programming it is important and also useful to know about these functions

         Before starting 'Functions' we tell you about an interesting character. All of you must hear about 'BLINKING' word, which is also known as shine or glitter. If you want in your program to blink any character on the screen, so this is also possible in C/C++. 
      To make any character blink on the screen a constant word 'BLINK' has been defined in C/C++. with the help of this constant word ‘BLINK’ you are able to blink any character on the screen.

     ‘BLINK’ constant has the value 128. And how to use it, This will clear in the example given below. 


textcolor( RED + BLINK );
           
            or

textcolor( RED + 128 );      
            Note that BLINK character is used on Text Mode only with  textbackground and textcolor functions of Text Mode.

So just write BLINK will not make any effects. You can also write the value 128 of BLINK character at the position of BLINK word. As shown in above example.  This will correct by both ways.
For better understanding, see example given below and must try at once.

#include <conio.h> 
void main() {
clrscr();

textcolor(RED + BLINK );

cprintf("Welcome In Advance Learning Tutorial\n");

getch(); 
}

          After running the program, you will get the output 'Welcome In Advance Learning Tutorial' is blinking.

  GOTOXY: - 

        Now let's talk about the function by which you can take the cursor at any position or anywhere on the screen. 
        we are requesting to readers that read carefully about this function because it is very useful for making graphics programs. The name of this function is "gotoxy". And here it is the declaration of this function.


 void gotoxy(int x , int y);  
          This function takes two parameters x and y. The value of x and y will be given by user, and this function will move the cursor to that position. 

        Note that if you pass invalid coordinate in this function, so it would not make any sense because the compiler will ignore it. See how to use the function in this example. 
 
Before you use this function remember to include this Header File <conio.h> 



.

#include <conio.h> 
#include <stdio.h>

void main() {

clrscr();

gotoxy(20,12);

printf("Welcome In Advance Learning Tutorial\n");

getch(); 
}


        
  Note that in this example, we are using function 'printf' instead of 'cprintf' that's why we use header file <stdio.h>. 'gotoxy' function works with both functions 'cprintf' as well as 'printf'.

DELAY: - 

                Now we are telling you about another important function, it is known as delay(). With the help of this function you can suspend the execution of the program for some time. How long do you want to suspend the execution of the program, is depends on the value that is passed to the parameter of this function.


   Delay function takes millisecond as the value.  It is mean that if you want to suspend the execution of the program for the 5 seconds so you will have to pass value 5000 in the parameter. Function shows like that.  

                         delay(5000); 
   Important point related to this function is that, Write down any line of code after this [delay(5000)] line will execute after 5 seconds. Because execution of the program will be suspend for 5 seconds. 



Before using this function remember to include Header File <dos.h>. See example of the program.


#include <conio.h> 
#include <stdio.h>
#include <dos.h>

void main() {

clrscr();

printf("Hello\n");

delay(5000);

printf("Welcome In Advance Learning Tutorial\n");

getch(); 
}


          After run the program in the first output you will see HELLO, after 5 seconds the next line will be ‘Welcome in Advance Learning Tutorial’ executed and appears in your output window.


         Now it’s enough for  today’s  C/C++ Advance learning tutorial. If you have any doubt or have any question regarding this discussion so you can ask your questions . You can also discuss your problem in our facebook page.  share it with your friends on Facebook,linked in,Twitter,Google+ ,  etc.

       If you have any problem to understand basic topics of C/C++ such as 'printf' , '
header files' and 'Functions' so you can read these from our blog. 




As well as this tutorial goes forward , we will add the links here for next chapters.

* Please ask your questions in comment box if you have any problem.*



   



Back ChapterIndex Page
              
                                                        

                                    Read This Blog In Hindi Click here

No comments:

Post a Comment


For MNCs Interview Preparation And Practice set of C,C++,JAVA,PHP Questions Like our page.