C program for Round Robin CPU Scheduling Algorithm

INPUT :
enter the process name : aaa
enter the processing time : 4
enter the process name : bbb
enter the processing time : 3
enter the process name : ccc
enter the processing time : 2
enter the process name : ddd
enter the processing time : 5
enter the process name : eee
enter the processing time : 1
OUTPUT :
p_name p_time w_time
aaa 4 9
bbb 3 3
ccc 2 6
ddd 5 10
eee 1 11
total waiting time : 39
average waiting time : 7.8000
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<string.h>
void main()
{
char p[10][5];
int et[10],wt[10],timer=3,count,pt[10],rt,i,j,totwt=0,t,n=5,found=0,m;
float avgwt;
clrscr();
for(i=0;i<n;i++)
{
printf("enter the process name : ");
scanf("%s",&p[i]);
printf("enter the processing time : ");
scanf("%d",&pt[i]);
}
m=n;
wt[0]=0;
i=0;
do
{
if(pt[i]>timer)
{
rt=pt[i]-timer;
strcpy(p[n],p[i]);
pt[n]=rt;
et[i]=timer;
n++;
}
else
{
et[i]=pt[i];
}
i++;
wt[i]=wt[i-1]+et[i-1];
}while(i<n);
 
count=0;
for(i=0;i<m;i++)
{
for(j=i+1;j<=n;j++)
{
if(strcmp(p[i],p[j])==0)
{
count++;
found=j;
}
}
 if(found!=0)
 {
 
 wt[i]=wt[found]-(count*timer);
 count=0;
 found=0;
 }
}
for(i=0;i<m;i++)
{
totwt+=wt[i];
}
avgwt=(float)totwt/m;
for(i=0;i<m;i++)
{
printf("\n%s\t%d\t%d",p[i],pt[i],wt[i]);
}
printf("\ntotal waiting time %d\n",totwt);
printf("total avgtime %f",avgwt);
}
INPUT :
enter the process name : aaa
enter the processing time : 4
enter the process name : bbb
enter the processing time : 3
enter the process name : ccc
enter the processing time : 2
enter the process name : ddd
enter the processing time : 5
enter the process name : eee
enter the processing time : 1
OUTPUT :
p_name p_time w_time
aaa 4 9
bbb 3 3
ccc 2 6
ddd 5 10
eee 1 11
total waiting time : 39
average waiting time : 7.8000

Java applet program that allows the user to draw lines, rectangles and ovals

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import java.awt.*;
import java.applet.*;
/*
<applet code="Sujith" width=200 height=200>
</applet>
*/
public class Sujith extends Applet
{
 public void paint(Graphics g)
 {
  for(int i=0;i<=250;i++)
  {
   Color c1=new Color(35-i,55-i,110-i);
   g.setColor(c1);
   g.drawRect(250+i,250+i,100+i,100+i);
   g.drawOval(100+i,100+i,50+i,50+i);
   g.drawLine(50+i,20+i,10+i,10+i);
  }
 }
}
Output:
Java applet progrme for draw lines, circle, rectangle Java applet progrme for draw lines, circle, rectangle

Java applet program for handling mouse events

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="Mouse" width=500 height=500>
</applet>
*/
public class Mouse extends Applet
implements MouseListener,MouseMotionListener
{
 int X=0,Y=20;
 String msg="MouseEvents";
 public void init()
 {
  addMouseListener(this);
  addMouseMotionListener(this);
  setBackground(Color.black);
  setForeground(Color.red);
 }
 public void mouseEntered(MouseEvent m)
 {
  setBackground(Color.magenta);
  showStatus("Mouse Entered");
  repaint();
 }
 public void mouseExited(MouseEvent m)
 {
  setBackground(Color.black);
  showStatus("Mouse Exited");
  repaint();
 }
 public void mousePressed(MouseEvent m)
 {
  X=10;
  Y=20;
  msg="NEC";
  setBackground(Color.green);
  repaint();
 }
 public void mouseReleased(MouseEvent m)
 {
  X=10;
  Y=20;
  msg="Engineering";
  setBackground(Color.blue);
  repaint();
 }
 public void mouseMoved(MouseEvent m)
 {
  X=m.getX();
  Y=m.getY();
  msg="College";
  setBackground(Color.white);
  showStatus("Mouse Moved");
  repaint();
 }
 public void mouseDragged(MouseEvent m)
 {
  msg="CSE";
  setBackground(Color.yellow);
  showStatus("Mouse Moved"+m.getX()+" "+m.getY());
  repaint();
 }
 public void mouseClicked(MouseEvent m)
 {
  msg="Students";
  setBackground(Color.pink);
  showStatus("Mouse Clicked");
  repaint();
 }
 public void paint(Graphics g)
 {
  g.drawString(msg,X,Y);
 }
}
Output:
Java mouse handling events Java mouse handling events

C program to find the Shortest path for a given graph

OUTPUT:
enter the cost matrix :
0 1 4 2 0
0 0 0 2 3
0 0 0 3 0
0 0 0 0 5
0 0 0 0 0
enter number of paths : 4
enter possible paths :
1 2 4 5 0
1 2 5 0 0
1 4 5 0 0
1 3 4 5 0
minimum cost : 4
minimum cost path :
1–>2–>5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<stdio.h>
#include<conio.h>
void main()
{
int path[5][5],i,j,min,a[5][5],p,st=1,ed=5,stp,edp,t[5],index;
clrscr();
printf("enter the cost matrix\n");
for(i=1;i<=5;i++)
for(j=1;j<=5;j++)
scanf("%d",&a[i][j]);
printf("enter  number of paths\n");
scanf("%d",&p);
printf("enter possible paths\n");
for(i=1;i<=p;i++)
for(j=1;j<=5;j++)
scanf("%d",&path[i][j]);
for(i=1;i<=p;i++)
{
t[i]=0;
stp=st;
for(j=1;j<=5;j++)
{
edp=path[i][j+1];
t[i]=t[i]+a[stp][edp];
if(edp==ed)
break;
else
stp=edp;
}
}
min=t[st];index=st;
for(i=1;i<=p;i++)
{
if(min>t[i])
{
min=t[i];
index=i;
}
}
printf("minimum cost %d",min);
printf("\n minimum cost path ");
for(i=1;i<=5;i++)
{
printf("--> %d",path[index][i]);
if(path[index][i]==ed)
break;
}
getch();
}
OUTPUT:
enter the cost matrix :
0 1 4 2 0
0 0 0 2 3
0 0 0 3 0
0 0 0 0 5
0 0 0 0 0
enter number of paths : 4
enter possible paths :
1 2 4 5 0
1 2 5 0 0
1 4 5 0 0
1 3 4 5 0
minimum cost : 4
minimum cost path :
1–>2–>5

C program for finding remainder

OUTPUT:
enter frame:
1 0 1 1 0 1 0 0
enter generator:
1 0 1 0
remainder is:
0 0 1 0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include<stdio.h>
#include<conio.h>
void main()
{
 int  i,j,gen[4],rem[4],frl=8,genl=4,k,k1,fr[11];
 clrscr();
 printf("enter frame:");
 for(i=0;i<frl;i++)
{
scanf("%d",&fr[i]);
}
for(i=frl;i<11;i++)
{
fr[i]=0;
}
printf("enter generator:");
 for(i=0;i<4;i++)
 scanf("%d",&gen[i]);
  for(k=0;k<frl;k++)
  {
   if(fr[k]==1)
   {
   k1=k;
    for(i=0,j=k;i<genl;i++,j++)
    {
     rem[i]=fr[j]^gen[i];
    }
 
    for(i=0;i<genl;i++)
    {
   fr[k1]=rem[i];
     k1++;
    }
   }
    }
      printf("\nremainder is: ");
      for(i=0;i<4;i++)
     printf("%d",rem[i]);
     getch();
}
OUTPUT:
enter frame:
1 0 1 1 0 1 0 0
enter generator:
1 0 1 0
remainder is:
0 0 1 0

Java program for creating multiple threads

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class NewThread implements Runnable
{
 String name;
 Thread t;
 NewThread(String threadname)
 {
  name=threadname;
  t=new Thread(this,name);
  System.out.println("New Thread:"+t);
  t.start();
 }
 public void run()
 {
  try
  {
   for(int i=5;i>0;i--)
   {
    System.out.println(name+ ":"+i);
    Thread.sleep(1000);
   }
  }
  catch(InterruptedException e)
  {
   System.out.println(name+" Interrupted");
  }
  System.out.println(name+" exiting");
 }
}
class MultiThreadDemo
{
 
public static void main(String[] args)
 {
  new NewThread("One");
  new NewThread("Two");
  new NewThread("Three");
  try
  {
   Thread.sleep(10000);
  }
  catch(InterruptedException e)
  {
   System.out.println("Main Thread Interrupted");
  }
  System.out.println("Main Thread Exiting");
 }
}
Output:
New Thread :Thread[One,5,main]
New Thread : Thread[Two,5,main]
One:5
Two:5
New Thread : Thread[Three,5,main]
Three:5
One:4
Three:4
Two:4
One:3
Three:3
Two:3
One:2
Three:2
Two:2
One:1
Three:1
Two:1
One exiting
Three exiting
Two exiting
Main Thread Exiting

Java program that finds the area of a circle using Client-Server network

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import java.net.*;
import java.io.*;
public class  server
{
 public static void main(String args[]) throws Exception
 {
  ServerSocket ss=new ServerSocket(2000);
  Socket s=ss.accept();
  BufferedReader br=new BufferedReader(newInputStreamReader(s.getInputStream()));
  double rad,area;
  String result;
  rad=Double.parseDouble(br.readLine());
  System.out.println("From Client : "+rad);
  area=Math.PI*rad*rad;
  result="Area is "+area;
  PrintStream ps=new PrintStream(s.getOutputStream());
  ps.println(result);
  br.close();
  ps.close();
  s.close();
  ss.close();
 }
}
public class  client
{
 public static void main(String args[]) throws Exception
 {
 
  Socket s=new Socket("192.168.0.19",2000);
  BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  String rad;
  System.out.println("Enter radius of the circle ");
  rad=br.readLine();
  PrintStream ps=new PrintStream(s.getOutputStream());
  ps.println(rad);
  BufferedReader fs=newBufferedReader(new InputStreamReader(s.getInputStream()));
  String result=fs.readLine();
  System.out.println("From Server : "+result);
  br.close();
  fs.close();
  ps.close();
  s.close();
 }
}
Output:
Java client
Enter radius of the circle
10
From Server: Area is 314.1341345

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | cheap international calls