Monday, 24 March 2014
Tuesday, 18 March 2014
c program for implement paging technique
#include<stdio.h>
int main()
{
int lmem,psize,pmem,i,j,k,c[10],str,pno,off;
int a[20],b[35],ch,page,index,abs,frame;
printf("\n enter page size::");
scanf("%d",&psize);
printf("\nenter logical memory size::");
scanf("%d",&lmem);
printf("\n%d",lmem);
printf("\n enter data::");
for(i=0;i<lmem;i++)
scanf("%d",&a[i]);
for(i=0;i<32;i++)
b[i]=-1;
for(i=0;i<lmem/psize;i++)
{
printf("\nenter starting location for page::%d",i);
scanf("%d",&str);
if(str%4==0)
{
c[i]=str/4;
for(j=str,k=i*4;j<j+psize,k<i*4+psize;j++,k++)
{
b[j]=a[k];
}
}
else
{
printf("\n wrong entry for page the page address shud
be multiples of 4");
}
}
printf("\n the page table is::");
printf("\n page \t\t frame");
for(i=0;i<lmem/psize;i++)
printf("\n %d\t %d",i,c[i]);
printf("enter the pageno and offset\n");
scanf("%d%d",&pno,&off);
abs=c[pno]*4+off;
printf("\n the physical address %d is::%d",b[abs],abs);
return 0;
}
int main()
{
int lmem,psize,pmem,i,j,k,c[10],str,pno,off;
int a[20],b[35],ch,page,index,abs,frame;
printf("\n enter page size::");
scanf("%d",&psize);
printf("\nenter logical memory size::");
scanf("%d",&lmem);
printf("\n%d",lmem);
printf("\n enter data::");
for(i=0;i<lmem;i++)
scanf("%d",&a[i]);
for(i=0;i<32;i++)
b[i]=-1;
for(i=0;i<lmem/psize;i++)
{
printf("\nenter starting location for page::%d",i);
scanf("%d",&str);
if(str%4==0)
{
c[i]=str/4;
for(j=str,k=i*4;j<j+psize,k<i*4+psize;j++,k++)
{
b[j]=a[k];
}
}
else
{
printf("\n wrong entry for page the page address shud
be multiples of 4");
}
}
printf("\n the page table is::");
printf("\n page \t\t frame");
for(i=0;i<lmem/psize;i++)
printf("\n %d\t %d",i,c[i]);
printf("enter the pageno and offset\n");
scanf("%d%d",&pno,&off);
abs=c[pno]*4+off;
printf("\n the physical address %d is::%d",b[abs],abs);
return 0;
}
c program for implementing segmentation in memory using array
#include<stdio.h>
int main()
{
int a[10][10],b[100],i,j,n,x,base,size,seg,off;
printf("Enter the segments count\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the %d size \n",i+1);
scanf("%d",&size);
a[i][0]=size;
printf("Enter the base address\n");
scanf("%d",&base);
a[i][1]=base;
for(j=0;j<size;j++)
{
x=0;
scanf("%d",&x);
// b[base]=x;
base++;
b[base]=x;
}
}
printf("Enter the segment number and offset value \n");
scanf("%d%d",&seg,&off);
if(off<a[seg][0])
{
int abs=a[seg][1]+off;
printf("the offset is less tha %d",a[seg][0]);
printf("\n %d + %d = %d\n",a[seg][1],off,abs);
printf("the element %d is at %d ",b[abs+1],abs);
}
else
{
printf("ERROr IN LOCATING");
}
}
int main()
{
int a[10][10],b[100],i,j,n,x,base,size,seg,off;
printf("Enter the segments count\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the %d size \n",i+1);
scanf("%d",&size);
a[i][0]=size;
printf("Enter the base address\n");
scanf("%d",&base);
a[i][1]=base;
for(j=0;j<size;j++)
{
x=0;
scanf("%d",&x);
// b[base]=x;
base++;
b[base]=x;
}
}
printf("Enter the segment number and offset value \n");
scanf("%d%d",&seg,&off);
if(off<a[seg][0])
{
int abs=a[seg][1]+off;
printf("the offset is less tha %d",a[seg][0]);
printf("\n %d + %d = %d\n",a[seg][1],off,abs);
printf("the element %d is at %d ",b[abs+1],abs);
}
else
{
printf("ERROr IN LOCATING");
}
}
Monday, 17 March 2014
applet face program
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*
<applet code="Baby.class" height=500 width=600>
</applet>
*/
public class Baby extends Applet
{
public void paint(Graphics g)
{
Font f1 = new Font("SansSerif",Font.BOLD | Font.ITALIC,35);
g.drawArc(150,100,300,250,0, 180);
g.drawArc(150,100,300,320,180, 180);
g.setColor(Color.pink);
g.fillArc(130,50,340,290,0, 180);
g.setColor(Color.black);
g.setFont(f1);
g.drawString(" BABY" ,230,140);
g.drawLine(150,225,150,260);
g.drawLine(450,225,450,260);
g.drawArc(120,200,60,70,84, 180);
g.drawArc(125,225,45,30,84, 180);
g.drawArc(420,200,60,70,267, 186);
g.drawArc(425,225,50,30,267, 186);
for(int i=0;i<=4;i++)
{
g.drawArc(210,205+i,50,20,0, 180);
g.drawArc(340,205+i,50,20,0, 180);
}
g.fillOval(220,225,30,30);
g.fillOval(350,225,30,30);
g.drawLine(300,250,270,325);
g.drawArc(270,315,50,20,180, 180);
g.drawArc(240,310,120,80,200, 140);
g.drawLine(250,353,235,377);
g.drawLine(350,353,365,377);
}
}
jdbc java program to access database using MSaccess
import java.sql.*;
import java.io.*;
class JdbcDemo1
{
Connection con;
Statement stmt;
ResultSet rs;
JdbcDemo1()
{
try
{
Class.forName("sun.jdbc.odbc. JdbcOdbcDriver");
con = DriverManager.getConnection( "Jdbc:Odbc:d1", "","");
stmt = con.createStatement();
String sql = "INSERT INTO mm " + "VALUES (97,'muthuma')";
stmt.executeUpdate(sql);
sql = "INSERT INTO mm " + "VALUES (998,'leena')";
stmt.executeUpdate(sql);
sql="DELETE FROM mm " + "WHERE ID=97";
stmt.executeUpdate(sql);
sql="UPDATE mm " + "SET Nam= 'prem' WHERE ID in (998)";
stmt.executeUpdate(sql);
rs = stmt.executeQuery("SELECT * FROM mm");
while (rs.next()) {
int ID = rs.getInt("ID");
String Nam=rs.getString("Nam");
System.out.println("ID:"+ID+"\ tNam:"+Nam);
}
}
catch(SQLException e)
{
System.out.println(e);
}
catch(ClassNotFoundException e)
{
System.out.println(e);
}
}
}
class JdbcDemo
{
public static void main(String args[])
{
new JdbcDemo1();
}
}
import java.io.*;
class JdbcDemo1
{
Connection con;
Statement stmt;
ResultSet rs;
JdbcDemo1()
{
try
{
Class.forName("sun.jdbc.odbc.
con = DriverManager.getConnection( "Jdbc:Odbc:d1", "","");
stmt = con.createStatement();
String sql = "INSERT INTO mm " + "VALUES (97,'muthuma')";
stmt.executeUpdate(sql);
sql = "INSERT INTO mm " + "VALUES (998,'leena')";
stmt.executeUpdate(sql);
sql="DELETE FROM mm " + "WHERE ID=97";
stmt.executeUpdate(sql);
sql="UPDATE mm " + "SET Nam= 'prem' WHERE ID in (998)";
stmt.executeUpdate(sql);
rs = stmt.executeQuery("SELECT * FROM mm");
while (rs.next()) {
int ID = rs.getInt("ID");
String Nam=rs.getString("Nam");
System.out.println("ID:"+ID+"\
}
}
catch(SQLException e)
{
System.out.println(e);
}
catch(ClassNotFoundException e)
{
System.out.println(e);
}
}
}
class JdbcDemo
{
public static void main(String args[])
{
new JdbcDemo1();
}
}
life cycle of java applet
import java.applet.*;
import java.awt.*;
public class life extends Applet
{
String str="";
// Born State
public void init()
{
str+="Executing Born / init state ";
}
// Start State
public void start()
{
str+="Executing Start state ";
}
// Stop / Idle State
public void stop()
{
str+="Executing Stop state ";
}
public void paint(Graphics g)
{
g.drawString(str,25,100);
}
// Dead / Destroy State
public void destroy()
{
System.out.println("Destroy / Dead is calling...");
System.out.println("Applet is deleted from memory...");
}
}
/*<applet code="life.class" height="150" width="150" align="MIDDLE">
</applet>*/
Friday, 14 March 2014
c program for non premptive priority scheduling
#include<stdio.h>
int main()
{
int i,j,n,time,sum_wait=0,sum_turnaround=0;
int smallest,at[10],bt[10],priority[10],remain;
printf("Enter no of Processes : ");
scanf("%d",&n);
remain=n;
for(i=0;i<n;i++)
{
printf("Enter arrival time, burst time and priority for process p%d :",i+1);
scanf("%d",&at[i]);
scanf("%d",&bt[i]);
scanf("%d",&priority[i]);
}
priority[9]=11;
printf("\n\nProcess\t|Turnaround time|waiting time\n");
for(time=0;remain!=0;)
{
smallest=9;
for(i=0;i<n;i++)
{
if(at[i]<=time && priority[i]<priority[smallest] && bt[i]>0)
{
smallest=i;
}
}
time+=bt[smallest];
remain--;
printf("P[%d]\t|\t%d\t|\t%d\n",smallest+1,time-at[smallest],time-at[smallest]-bt[smallest]);
sum_wait+=time-at[smallest]-bt[smallest];
sum_turnaround+=time-at[smallest];
bt[smallest]=0;
}
printf("\nAvg waiting time = %f\n",sum_wait*1.0/n);
printf("Avg turnaround time = %f",sum_turnaround*1.0/n);
return 0;
}
int main()
{
int i,j,n,time,sum_wait=0,sum_turnaround=0;
int smallest,at[10],bt[10],priority[10],remain;
printf("Enter no of Processes : ");
scanf("%d",&n);
remain=n;
for(i=0;i<n;i++)
{
printf("Enter arrival time, burst time and priority for process p%d :",i+1);
scanf("%d",&at[i]);
scanf("%d",&bt[i]);
scanf("%d",&priority[i]);
}
priority[9]=11;
printf("\n\nProcess\t|Turnaround time|waiting time\n");
for(time=0;remain!=0;)
{
smallest=9;
for(i=0;i<n;i++)
{
if(at[i]<=time && priority[i]<priority[smallest] && bt[i]>0)
{
smallest=i;
}
}
time+=bt[smallest];
remain--;
printf("P[%d]\t|\t%d\t|\t%d\n",smallest+1,time-at[smallest],time-at[smallest]-bt[smallest]);
sum_wait+=time-at[smallest]-bt[smallest];
sum_turnaround+=time-at[smallest];
bt[smallest]=0;
}
printf("\nAvg waiting time = %f\n",sum_wait*1.0/n);
printf("Avg turnaround time = %f",sum_turnaround*1.0/n);
return 0;
}
creating xml using javascript
<html>
<head>
<script type="text/javascript">
var x='<?xml version="1.0"?>\n';
x+='<Contacts>\n';
function savexml()
{
x+='<Contact>\n';
x+='<Name>'+document.getElementById('nam').value+'</Name>\n';
x+='<Phone>'+document.getElementById('phon').value+'</Phone>\n';
x+='<Email>'+document.getElementById('emai').value+'</Email>\n';
x+='</Contact>\n';
}
function exitxml()
{
x+='</Contacts>';
alert(x);
}
</script>
</head>
<body>
DISPLAY XML
Name: <input type="text" id="nam"><br>
Phone: <input type="text" id="phon"><br>
Email: <input type="text" id="emai"><br>
<input type="button" value="Save" onClick="savexml();">
<input type="button" value="Exit" onClick="exitxml();">
</body>
</html>
<head>
<script type="text/javascript">
var x='<?xml version="1.0"?>\n';
x+='<Contacts>\n';
function savexml()
{
x+='<Contact>\n';
x+='<Name>'+document.getElementById('nam').value+'</Name>\n';
x+='<Phone>'+document.getElementById('phon').value+'</Phone>\n';
x+='<Email>'+document.getElementById('emai').value+'</Email>\n';
x+='</Contact>\n';
}
function exitxml()
{
x+='</Contacts>';
alert(x);
}
</script>
</head>
<body>
DISPLAY XML
Name: <input type="text" id="nam"><br>
Phone: <input type="text" id="phon"><br>
Email: <input type="text" id="emai"><br>
<input type="button" value="Save" onClick="savexml();">
<input type="button" value="Exit" onClick="exitxml();">
</body>
</html>
c program for sjf non preemptive
#include<stdio.h>
int main()
{
int time,bt[10],at[10],sum_bt=0,smallest,n,i;
int sum_turnaround=0,sum_wait=0;
printf("Enter no of processes : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter arrival time for process P%d : ",i+1);
scanf("%d",&at[i]);
printf("Enter burst time for process P%d : ",i+1);
scanf("%d",&bt[i]);
sum_bt+=bt[i];
}
bt[9]=9999;
printf("\n\nProcess\t|Turnaround Time| Waiting Time\n\n");
for(time=0;time<sum_bt;)
{
smallest=9;
for(i=0;i<n;i++)
{
if(at[i]<=time && bt[i]>0 && bt[i]<bt[smallest])
smallest=i;
}
printf("P[%d]\t|\t%d\t|\t%d\n",smallest+1,time+bt[smallest]-at[smallest],time-at[smallest]);
sum_turnaround+=time+bt[smallest]-at[smallest];
sum_wait+=time-at[smallest];
time+=bt[smallest];
bt[smallest]=0;
}
printf("\n\n average waiting time = %f",sum_wait*1.0/n);
printf("\n\n average turnaround time = %f",sum_turnaround*1.0/n);
return 0;
}
int main()
{
int time,bt[10],at[10],sum_bt=0,smallest,n,i;
int sum_turnaround=0,sum_wait=0;
printf("Enter no of processes : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter arrival time for process P%d : ",i+1);
scanf("%d",&at[i]);
printf("Enter burst time for process P%d : ",i+1);
scanf("%d",&bt[i]);
sum_bt+=bt[i];
}
bt[9]=9999;
printf("\n\nProcess\t|Turnaround Time| Waiting Time\n\n");
for(time=0;time<sum_bt;)
{
smallest=9;
for(i=0;i<n;i++)
{
if(at[i]<=time && bt[i]>0 && bt[i]<bt[smallest])
smallest=i;
}
printf("P[%d]\t|\t%d\t|\t%d\n",smallest+1,time+bt[smallest]-at[smallest],time-at[smallest]);
sum_turnaround+=time+bt[smallest]-at[smallest];
sum_wait+=time-at[smallest];
time+=bt[smallest];
bt[smallest]=0;
}
printf("\n\n average waiting time = %f",sum_wait*1.0/n);
printf("\n\n average turnaround time = %f",sum_turnaround*1.0/n);
return 0;
}
Subscribe to:
Posts (Atom)