Showing posts with label System Program. Show all posts
Showing posts with label System Program. Show all posts

Mouse Programming in C

(1) Write a c program which restricts the movement of pointer?
 
Answer:
 
//restrict the x and y coordinate
#include <dos.h>
#include <stdio.h>
void main()
{
union REGS i,o;
//show mouse pointer
i.x.ax=1;
int86(0x33,&i,&o);
//x coordinate restriction
i.x.ax=7;
i.x.cx=20;
i.x.dx=300;
int86(0x33,&i,&o);
//y coordinate restriction
i.x.ax=8;
i.x.cx=50;
i.x.dx=250;
int86(0x33,&i,&o);
getch();
}
 
(2) Write c program which display position of pointer in (x coordinate, y coordinate)?
 
Answer:
 
#include<dos.h>
#include<stdio.h>
void main()
{
union REGS i,o;
int x,y,k;
//show mouse pointer
i.x.ax=1;
int86(0x33,&i,&o);
while(!kbhit())  //its value will false when we hit key in the key board
{
i.x.ax=3;    //get mouse position
x=o.x.cx;
y=o.x.dx;
clrscr();
printf("(%d , %d)",x,y);
delay(250);
int86(0x33,&i,&o);
}
getch();
}

Write a C Program which shutdown windows operating system ?


Write the following program in TURBO C.

void main(void)
{
system("shutdown -s");
}


Save the above .Let file name is close.c and compile and execute the above program. Now close the turbo c compiler and open the directory in window you have saved the close.c ( default directory c:\tc\bin) and double click the its exe file(close.exe).After some time your window will shutdown.


Good questions on Advance C programming Language

(1) What will happen when you will compile and execute the following code?

#include”dos.h”
#include”stdio.h”
void main()
{
int x,y,b;
union REGS i,o;
i.h.ah=0;
i.h.al=0x13;
int86(0x10,&i,&o);
getch();
}
(a)It will switch to 32 bit color graphics mode.
(b)It will switch to 256 bit color graphics mode.
(c)It will switch to 32 bit text mode.
(d)It will switch to 256 bit text mode.

Answer: (b)

(2) What will happen when you will compile and execute the following code?

#include”dos.h”
void main()
{
union REGS i,o;
i.h.ah=0x39;
i.x.dx="ravan";
int86(0x21,&i,&o);
getch();
}
(a) It will create a file in current working directory.
(b) It will create a file in bin directory.
(c) It will create a directory in current working directory.
(d) It will create a directory in bin directory.

Answer: (c)

(3) What will output when you will compile and execute the following code?

void main()
{
clrscr();
    asm mov ax,15;
    asm mov bx,1;
    india:
    asm xor ax,5;
    asm dec bx;
    asm jz india;
printf("%d ",_AX);
getch();
}

(a)20
(b)15
(c)21
(d)Infinite loop

Answer: (b)

Explanation:
Statement jz India means jump to label india till content of last register i.e. bx is zero. When content of register bx became not zero then stop the jumping.

(4) What will happen when you will compile and execute the following code?

void main()
{
int num;
clrscr();
scanf("%d",&num);
asm mov ax,1;
asm mov bx,1;
asm mov cx,num;
come:
asm mul bx;
asm inc bx;
asm dec cx;
asm jnz come;
printf("%d ",_AX);
getch();
}
(a)It will convert given decimal number to binary number.
(b)It will convert given decimal number to hexadecimal number.
(c)It will produce fibonacii series up to given number.
(d)It will produce factorial of given number.
Answer: (d)

(5) What will happen when you will compile and execute the following code?

void main()
{
clrscr();
asm{
         mov ax,10;
         shl,2;
}
printf("%d",_AX);
getch();
}
(a)2
(b)40
(c)20
(d)10

Answer: (b)

Explanation:
ax and bx is general purpose register.
Statement mov ax,61 means value 61 is storing at register ax.
Statement shl 2 is equivalent to a<<2>

Assembly Language Programming in C Programming Language


(1)What will be output of following c program?
void main()
{
clrscr();
asm{
         mov ax,61;
         mov bx,10;
         add bx,ax;
    }
printf("\n%d",_BX);
getch();
}

(a)61
(b)10
(c)71
(d)0

(2)What will be output of following c program?
void main()
{
clrscr();
asm{
         mov ax,10;
         mov bx,20;
         mov cx,30;
         add ax,bx;
         sub ax,cx;
     }
printf("%d",_AX);
getch();
}
(a)-20
(b)0
(c)20
(d)-10

(3)What will be output of following c program?
void main()
{
clrscr();
asm{
         mov ax,10;
         mov bx,20;
         mov cx,30;
         add ax,bx;
         add bx,cx
   }
printf("%d  %d   %d",_AX,_BX,_CX);
getch();
}
(a)30 50 30
(b)10 20 30
(c)10 30 60
(d)30 20 10
(4)What will be output of following c program?
void main()
{
clrscr();
asm{
         mov ax,10;
         mov cx,20;
         inc cx;
         div 2;
     }
printf("%d ",_AX);
getch();
}
(a)5
(b)10
(c)15
(d)Compiler error

(5)What will be output of following c program?
void main()
{
clrscr();
asm{
         mov ax,15;
         mov cx,12;
         mov bx,3;
         div bx;
   }
printf("%d ",_AX);
getch();
}

(a)5
(b)4
(c)9
(d)Compiler error

(6)What will be output of following c program?
void main()
{
clrscr();
asm{
         mov ax,15;
         mov bx,3;
         inc bx;
         mul bx;
   }
printf("%d ",_AX);
getch();
}

(a)45
(b)48
(c)60
(d)Compiler error

(7)What will be output of following c program?
void main()
{
int i=0;
clrscr();
asm mov dx,25;
for(i=0;i<5;i++)
asm dec dx;
printf("%d ",_DX);
getch();
}

(a)24 23 22 21 20
(b)24 23 22 21
(c)20
(d)Compiler error

(8)What will be output of following c program?
void main()
{
int j=5;
asm mov cx,10;
clrscr();
asm OR cx,j;
printf("%d ",_CX);
getch();
}

(a)5
(b)10
(c)15
(d)20

(9)What will be output of following c program?
void main()
{
clrscr();
asm {
         mov ax,15;
         mov dx,2;
         and dx,ax;
         not ax;
     }
printf("%d %d ",_AX,_DX);
getch();
}

(a)-15 2
(b)15 -15
(c)15 -16
(d)-16 2

(10)What will be output of following c program?
void main()
{
clrscr();
         asm mov ax,15;
         asm mov bx,5;
         india:
         asm inc ax;
         asm dec bx;
         asm jnz india;
printf("%d ",_AX);
getch();
}
(a)10
(b)20
(c)30
(d)Infinite loop


(1)
Answer: (c)
Explanation:
ax and bx is general purpose register.
Statement mov ax, 61 means value 61 is storing at register ax.
Statement add bx,ax means addition of content of register bx i.e 10 and content of register ax i.e. 61 and result of addition is storing at register bx.
(2)
Answer: (b)
Explanation:
Same concept has used as in question 1.
Mnemonic sub means subtraction.
(3)
Answer: (a)
Explanation:
Same concept has been used as in question 1.
(4)
Answer: (d)
Explanation:
Mnemonic inc means increment content of register by one.
Mnemonic div means division with ax.
Operand of div must be a register not a value.
Note. Register ax is known as accumulator.
(5)
Answer: (a)
Explanation:
Mnemonic div means division of its operand with content of accumulator i.e. ax.
Meaning of div bx means 15/3.
(6)
Answer: (c)
Explanation:
Mnemonic mul means multiplication of its operand with content of accumulator i.e. ax.
Meaning of mul bx means 15*4.
Note: inc bx means increase the content of register bx by one.
(7)
Answer: (c)
Explanation:
dec dx means decrease the content of register dx by one.
(8)
Answer: (a)
Explanation:
Mnemonic or means bitwise OR operations between its operands.
(9)
Answer: (d)
Explanation:
Mnemonic and means bitwise AND operations between its operands.

(10)
Answer: (b)
Explanation:
Statement jnz India means jump to label india till content of last register i.e bx is not zero. When content of register bx became zero then stop the jumping.

Hange / Change your Mouse Pointer

use these functions to change ur mouse pointer,using different values in the mask array lets u design ur own pointer.changing cursor mask in the mask array u can desig ur own mouse pointer.plz send feedback


#include "stdio.h"
#include "dos.h"
#include "conio.h"
#include "graphics.h"

void theend();

static int mask[]={/*SCREEN MASK*/
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,
/*CURSOR MASK*/
0x0000,0x0000,0x381c,0x7c3e,0x7c3e,0x7c3e,0x7c3e,
0x3bdc,0x07e0,0x0ff0,0x0ff0,0x0ff0,0x0ff0,0x07e0,
0x03c0,0x0000};


void main()
{int gdriver=DETECT,gmode,buttons;
union REGS regs;
struct SREGS sregs;
initgraph(&gdriver,&gmode,"c:\\tc\\bgi");
regs.x.ax=0; /*INITIALIZE MOUSE*/
int86(0x33,&regs,&regs);
setcolor(LIGHTCYAN);
if(regs.x.ax==0)
{outtextxy(0,0,"NO MOUSE AVAILABLE");
getch();
theend();
}
regs.x.ax=9; /*CHANGE CURSOR SHAPE*/
regs.x.bx=5;
regs.x.cx=0;
regs.x.dx=(int)mask;
segread(&sregs);
sregs.es=sregs.ds;
int86x(0x33,&regs,&regs,&sregs);
regs.x.ax=1; /*SHOW MOUSE POINTER*/
int86(0x33,&regs,&regs);
do
{regs.x.ax=3;
int86(0x33,&regs,&regs);
buttons=regs.x.bx & 3;
}while(buttons!=3);
regs.x.ax=2; /*HIDE MOUSE POINTER*/
int86(0x33,&regs,&regs);
theend();
}

void theend()
{closegraph();}

Write a c program to create a directory in current working directory?

Answer :

#include<dos.h>

void main()
{
union REGS i,o;
i.h.ah=0x39;
i.x.dx="KP";
int86(0x21,&i,&o);
printf("Now Check TC/BIN Folder has New Created Folder That Folder Name Is KP ");
getch();
}

Write the c program to switch the 256 color graphics mode ?


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

void main()
{
         int x,y,b;
         union REGS i,o;

         i.h.ah=0;
         i.h.al=0x13;
         int86(0x10,&i,&o);
         printf("This is 256 color Graphics Mode.");
         getch();
}

Write a c program to find out the last date of modification.

ANSWER :


#include<stdio.h>
#include<conio.h>
#include<sys/stat.h>

void main()
{
    struct stat status;
    FILE *fp;
    fp=fopen("test.txt","r");
    fstat(fileno(fp),&status);
    clrscr();
    printf("Last date of modification : %s",ctime(&status.st_ctime));
    getch();
}




Explanation:
Function int fstat(char *, struct stat *) store the  information of open file in form of  structure struct stat
Structure struct stat has been defined in sys\stat.h as
struct stat {
    short  st_dev,   st_ino;
    short  st_mode,  st_nlink;
    int    st_uid,   st_gid;
    short  st_rdev;
    long   st_size,  st_atime;
    long   st_mtime, st_ctime;
};
Here
(e)st_dev: It describe file has stored in which drive of your computer.
(f)st_mode:  It describes various modes of file like file is read only, write only, folder, character file etc.
(g)st_size: It tells the size of file in byte.
(h)st_ctime:It tells last data of modification of the file in date format.
Function ctime convert date type in string format