CPU Scheduling algorithm implementation

CPU Scheduling algorithm implementation.

 

CPU Scheduling algorithm implementation

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


  union REGS i, o ;
  int x1,y1,click;
  int count=1;
  char *comments[]={
                           "                              ",
                           "Amazed ?...Try it again!",
                           "C'mon give yourself a chance!",
                           "You can do it !",
                           "Think about $ 1 Million!",
                           "Don't give up !",
                           "LOOSER..!!",
                           "Sorry..You loose !"
                           };

void main()
{

   int x=50,y=50,gdriver = 9, gmode=2;
   initgraph(&gdriver, &gmode, "c:\tc\bgi");
   setcolor(LIGHTRED);
   settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
   outtextxy(240,200,"Developed by :");
   outtextxy(240,250,"WWW");
   rectangle(210,170,420,300);
   settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
   outtextxy(200,400,"Hit any key to continue.........");
   getch();
   cleardevice();


   showmouseptr();
   setbkcolor(9); //sets the backgroundcolour.
   setcolor(YELLOW);
   outtextxy(20,445,"CLICK ON THE BUTTON "VNIT"");
   unpressed(290,430,"EXIT");
   unpressed(x,y,"VNIT");

  while(1)//infinite loop.
   {

           getmousepos();

           if(x1 >= x && x1 <= x+50 && y1 >= y && y1 <= y+30 )//checks if the
mouse pointer is over the button.
              {                                               //where
x,x+50,y,y+50 are ((x,y))top,(x,y)bottom)co-ordinates.
                  hidemouseptr();
                  erasebutton(x,y);
                  x=random(600);
                  y=random(400);
                   //checks whether count=1 so as to display the button on the new
position for only once.

                       setcolor(9);
                       outtextxy(380,445,comments[count-1]);//to erase previousely written
things
                       setcolor(YELLOW);
                       outtextxy(380,445,comments[count]);
                       count++;

                  if(count==9)
                  {
                       setcolor(9);
                       outtextxy(380,445,comments[8]);//to erase previousely written
things
                       setcolor(YELLOW);
                       outtextxy(380,445,comments[1]);
                       count=2;
                  }

                  unpressed(x,y,"VNIT");
                  showmouseptr();


              }
           if(x1>=290&&x1<=340&&y1>=430&&y1<=460 && click==1)//checks if the mouse
pointer is over the "EXIT" button.
            {                                                //for click==1 refer
to mousepos.h.
                  hidemouseptr();
                  pressed(290,430,"EXIT");
                  showmouseptr();
                  sound(1200);
                  delay(100);
                  nosound();
                  while(click!=0)
                      getmousepos();
                  break;
            }

       }

   closegraph();
   restorecrtmode();
}

   unpressed(int x,int y,char *string) //display's an unpressed button.

     {

          setfillstyle(SOLID_FILL,CYAN);//sets the fill pattern and colour.
          bar(x, y, x+50, y+30);//creates a box and the box is automatically
filled with the chosen colour.
          setcolor(LIGHTCYAN);
          line(x,y,x+50,y);//creates a white line just over the box.
          line(x,y,x,y+30);

          setcolor(EGA_DARKGRAY);
          line(x,y+30,x+50,y+30);//creates  a dark line just below the box.
          line(x+2,y+31,x+50,y+31);
          line(x+50,y,x+50,y+30);
          line(x+51,y,x+51,y+31);
          setcolor(BLUE);
          outtextxy(x+10,y+12,string);//displays text on the box.
          return 0;
     }


    pressed(int x,int y,char *string)

      {
            setfillstyle(SOLID_FILL,CYAN);
            bar(x, y, x+50, y+30);
            setcolor(EGA_DARKGRAY);
            line(x,y,x+50,y);
            line(x-1,y-1,x+51,y-1);
            line(x,y,x,y+30);
            line(x-1,y-1,x-1,y+30);

            setcolor(LIGHTCYAN);
            line(x,y+30,x+50,y+30);
            line(x-1,y+31,x+50,y+31);
            line(x+50,y,x+50,y+30);
            line(x+51,y-1,x+51,y+31);

            setlinestyle(DOTTED_LINE,1,NORM_WIDTH);
            setcolor(EGA_DARKGRAY);
            rectangle(x+4,y+4,x+46,y+26);//creates a dotted rectangle over the
box.
            setcolor(BLUE);
            outtextxy(x+10,y+12,string);
            return 0;
      }

    erasebutton(int x,int y)//erases button.

      {


           setfillstyle(SOLID_FILL,getbkcolor());//gets the background colour


           bar(x, y-1, x+51, y+31);                // and fills the box with the
SOLID_FILL pattern.
           return 0;
      }

    showmouseptr( ) //shows the mouse-pointer.

      {

         i.x.ax = 1 ;

         int86 ( 0x33, &i, &o ) ;
         return 0;
      }
    hidemouseptr()//hides the mouse pointer.
      {
          i.x.ax=2;
          int86(51,&i,&o);//note:-0x33(hex)�51(dec).
          return 0;
      }

   getmousepos() //finds the mouse-pointer position.

    {


         i.x.ax = 3 ;

         int86 ( 0x33, &i, &o ) ;

         click = o.x.bx ;// if the left click button is pressed then click=1.

         x1 = o.x.cx ;  //x co-ordinate.

         y1 = o.x.dx ;  //y co-ordinate.

         return 0;
    }
 

Comments

Popular posts from this blog

C Program to Display the ATM Transaction

Fortran

Java programming language