Menu

Wednesday 10 December 2014

Write a program to generate 2d pie in Computer graphics .

  PROGRAM
#include<graphics.h>
#include<conio.h>

int main()
{
   int gd = DETECT, gm, midx, midy;

   initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");

   setcolor(MAGENTA);
   rectangle(0,40,639,450);
   settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2);
   setcolor(WHITE);
   outtextxy(275,10,"Pie Chart");

   midx = getmaxx()/2;
   midy = getmaxy()/2;

   setfillstyle(LINE_FILL,BLUE);
   pieslice(midx, midy, 0, 75, 100);
   outtextxy(midx+100, midy - 75, "20.83%");

   setfillstyle(XHATCH_FILL,RED);
   pieslice(midx, midy, 75, 225, 100);
   outtextxy(midx-175, midy - 75, "41.67%");

   setfillstyle(WIDE_DOT_FILL,GREEN);
   pieslice(midx, midy, 225, 360, 100);
   outtextxy(midx+75, midy + 75, "37.50%");

   getch();
   return 0;
}


OUTPUT

Write a Program on an Exception Handling.

class MyException
  {
public static void main(String args[])
       { 
try
                {
                                int a = args.length;
                                int b = 42/a;
                                int c[] = {1};
                                c[50] = 25;
                }

                catch(ArithmeticException e)
                {
                System.out.println("DIVIDE BY:" + e);               
                }

                catch(ArrayIndexOutOfBoundsException e)
                {
                System.out.println("ARRAY INDEX:" + e);        
                }              
               
                finally
                {
                System.out.println("FINISHED");       
                }
       }
  }


OUTPUT : 

Write a Program in java to show Multithreading.


classNewThread implements Runnable
                {
                Thread t;
                NewThread() {
               
                t = new Thread(this, "Demo Thread");
                System.out.println("Child thread: " + t);
                t.start(); // Start the thread
                }
               

                public void run()
                {
                try {
                for(int i = 5; i > 0; i--)
                 {
                System.out.println("Child Thread: " + i);
                Thread.sleep(500);
                }
                }
                catch (InterruptedException e) {
                System.out.println("Child interrupted.");
                }
                System.out.println("Exiting child thread.");
                }
                }

                classThreadDemo
               {
                public static void main(String args[ ] )
                 {
                newNewThread();
                try
                {
                for(int i = 5; i > 0; i--)
                {
                System.out.println("Main Thread: " + i);
                Thread.sleep(1000);
                }
                } catch (InterruptedException e) {
                System.out.println("Main thread interrupted.");
                }
                System.out.println("Main thread exiting.");
                }

  }

OUTPUT :