Subscribe:Posts Comments | Read Articles on Various Topics - Pro Articles

By PDMACpayday loans

You Are Here: Home » C and C++, Technical Interview Questions » C and C++ Graphics Test Questions

C and C++ Programmers / programming language job test / employment questions related to graphics designing. See more placement papers and technical interview questions for C, C++ software developers and programmers.

  1. Graphics
    Building Mouse Cursors…
    In text mode the mouse cursor appears as a block, whereas in graphics mode it appears as an arrow. If we wish we can change the graphics cursor to any other shape the way Windows does. The mouse cursor in graphics mode occupies a 16 by 16 pixel box. By highlighting or dehighlighting some of the pixels in this box we can get the desired shape. For example, the following bit-pattern can be used to generate the cursor which looks like an hour-glass.
    1111111111111111 0000000000000000
    1000000000000001 0000000000000000
    1111111111111111 0000000000000000
    1000000000000001 0000000000000000
    0100000000000010 1000000000000001
    0010000000000100 1100000000000011
    0000100000010000 1111000000001111
    0000001001000000 1111110000111111
    0000001001000000 1111110000111111
    0000100000010000 1111000000001111
    0010000000000100 1100000000000011
    0100000000000010 1000000000000001
    1000000000000001 0000000000000000
    1111111111111111 0000000000000000
    1000000000000001 0000000000000000
    1111111111111111 0000000000000000
    Mouse pointer bitmap Screen Mask the one’s in the mouse pointer bitmap indicate that the pixel would be drawn whereas the zeros indicate that the pixel would stand erased. It is important to note that the mouse pointer bit pattern is 32 bytes long. However, while actually writing a program to change the pointer shape we need a 64 byte bit-map. This provision is made to ensure that when the cursor reaches a position on the screen where something is already written or drawn only that portion should get overwritten which is to be occupied by the mouse cursor. Of the 64 bytes the first 32 bytes contain a bit mask which is first ANDed with the screen image, and then the second 32 bytes bit mask is XORed with the screen image.
    The following program changes the mouse cursor in graphics mode to resemble an hour glass.
    # include “graphics.h”
    # include “dos.h”
    union REGS i, o ;
    struct SREGS s ;
    int cursor[32] =
    {
    /* Hour-glass screen mask */
    0×0000, 0×0000, 0×0000, 0×0000,
    0×8001, 0xc003, 0xf00f, 0xfc3f,
    0xfc3f, 0xf00f, 0xc003, 0×8001,
    0×0000, 0×0000, 0×0000, 0×0000,
    /* The mouse pointer bitmap */
    0xffff, 0×8001, 0xffff, 0×8001,
    0×4002, 0×2004, 0×1008, 0×0240,
    0×0240, 0×0810, 0×2004, 0×4002,
    0×8001, 0xffff, 0×8001, 0xffff,
    } ;
    main( )
    {
    int gd = DETECT, gm ;
    initgraph ( &gd, &gm, “c:\\tc\\bgi” ) ;
    if ( initmouse( ) == -1 )
    {
    closegraph( ) ;
    printf ( “\n Mouse not installed!” ) ;
    exit( ) ;
    }
    gotoxy ( 10, 1 ) ; printf ( “Press any key to exit…” ) ;
    changecursor ( cursor ) ; showmouseptr( ) ;
    getch( ) ;
    }
    initmouse( )
    {
    i.x.ax = 0 ; int86 ( 0×33, &i, &o ) ;
    return ( o.x.ax == 0 ? -1 : 0 ) ;
    }
    showmouseptr( )
    {
    i.x.ax = 1 ; int86 ( 0×33, &i, &o ) ;
    }
    changecursor ( int *shape )
    {
    i.x.ax = 9 ; /* service number */
    i.x.bx = 0 ; /* actual cursor position from left */
    i.x.cx = 0 ; /* actual cursor position from top */
    i.x.dx = ( unsigned ) shape ; /* offset address of pointer image*/
    segread ( &s ) ;
    s.es = s.ds ; /* segment address of pointer */
    int86x ( 0×33, &i, &i, &s ) ;
    }

  2. Towers Of Hanoi
    Suppose there are three pegs labeled A, B and C. Four disks are placed on peg A. The bottom-most disk is largest, and disks go on decreasing in size with the topmost disk being smallest. The objective of the game is to move the disks from peg A to peg C, using peg B as an auxiliary peg. The rules of the game are as follows:
    Only one disk may be moved at a time, and it must be the top disk on one of the pegs. A larger disk should never be placed on the top of a smaller disk. Suppose we are to write a program to print out the sequence in which the disks should be moved such that all disks on peg A are finally transferred to peg C. Here it is…
    main( )
    {
    int n = 4 ;
    move ( n, ‘A’, ‘B’, ‘C’ ) ;
    }
    move ( n, sp, ap, ep )
    int n ;
    char sp, ap, ep ;
    {
    if ( n == 1 )
    printf ( “\n Move from %c to %c “, sp, ep ) ;
    else
    {
    move ( n – 1, sp, ep, ap ) ;
    move ( 1, sp, ‘ ‘, ep ) ;
    move ( n – 1, ap, sp, ep ) ;
    }
    }
    And here is the output…
    Move from A to B
    Move from A to C
    Move from B to C
    Move from A to B
    Move from C to A
    Move from C to B
    Move from A to B
    Move from A to C
    Move from B to C
    Move from B to A
    Move from C to A
    Move from B to C
    Move from A to B
    Move from A to C
    Move from B to C
    This problem is the famous Towers of Hanoi problem, wherein three pegs are to be employed for transferring the disks with the given criteria. Here’s how we go about it. We have three pegs: the starting peg, sp, the auxiliary peg ap, and the ending peg, ep, where the disks must finally be. First, using the ending peg as an auxiliary or supporting peg, we transfer all but the last disk to ap. Next the last disk is moved from sp to ep. Now, using sp as the supporting peg, all the disks are moved from ap to ep. ?A?, B and C denote the three pegs. The recursive function move( ) is called with different combinations of these pegs as starting, auxiliary and ending pegs.

  3. What would be the output of following program?
    struct syntax
    {
    int i ;
    float g ;
    char c ;
    }
    main( )
    {
    printf ( “I won’t give you any error” ) ;
    }
    Ans: The above program would get compiled successfully and on execution it would print the message given in printf(). What strikes in the above code snippet is the structure syntax which is declared but not terminated with the statement terminator, the semicolon. The compiler would not give any error message for it, as it assumes that main( ) function have a return type of struct syntax and hence would successfully compile and execute the program.

Leave a Reply

© Copyright 2010 Latestexams. All Rights Reserved | Privacy Policy | Terms & Conditions