Friday, November 9, 2012

84. ERROR DETECTION USING CHECKSUM


//CHECKSUM
import java.util.*;

public class Checksum 
{
static int check[]=new int[4];
static int code[]=new int[12];
public static void exor(int a[], int n)
{
int i,j=0;
for(i=0;i<4;i++)
{
if((a[i]==1 && a[i+4]==1)||(a[i]==0 && a[i+4]==0))
{
check[i]=0;
}
else
{
check[i]=1;
}     
}

Wednesday, October 24, 2012

83. STOP & WAIT PROTOCOL USING SOCKETS IN JAVA


//SENDER PROGRAM

import java.io.*;
import java.net.*;
public class Sender{
Socket sender;
ObjectOutputStream out;
ObjectInputStream in;
String packet,ack,str, msg;
int n,i=0,sequence=0;
Sender(){}
public void run(){
 try{
 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Waiting for Connection....");
 sender = new Socket("localhost",2004);
sequence=0;

82. JAVA PROGRAM FOR SLIDING WINDOW PROTOCOL


//SENDER PROGRAM

import java.net.*;
import java.io.*;
import java.rmi.*;
public class slidsender
{
public static void main(String a[])throws Exception
{
ServerSocket ser=new ServerSocket(10);
Socket s=ser.accept();
DataInputStream in=new DataInputStream(System.in);
DataInputStream in1=new DataInputStream(s.getInputStream());
String sbuff[]=new String[8];
PrintStream p;
int sptr=0,sws=8,nf,ano,i;
String ch;
do
{
p=new PrintStream(s.getOutputStream());
System.out.print("Enter the no. of frames : ");
nf=Integer.parseInt(in.readLine());
p.println(nf);
if(nf<=sws-1)
{

81. TCP/UDP CLIENT SERVER PROGRAM IN JAVA


//CLEINT PROGRAM

import java.io.*;
import java.net.*;
import java.lang.*;
class client
{
public static void main(String a[])throws IOException
{
Socket s=new Socket("LocalHost",8000);
DataInputStream in=new DataInputStream(s.getInputStream());
DataInputStream inn=new DataInputStream(System.in);
PrintStream dos=new PrintStream(s.getOutputStream());
while(true)
{
String str=in.readLine();
System.out.println("msg received:"+str);
if(str.equals("end"))
{

80. JAVA PROGRAM FOR HAMMING CODE


//HAMMING CODE

import java.util.*;
import java.lang.*;
class Hamming
{
            public static void main(String args[])
            {
                        int i=0,j,d=0,sum=0;
                        int a[]=new int[7];
                        int b[]=new int[11];
                        int c[]=new int[11];
                        int p[]=new int[4];
                        Scanner sr=new Scanner(System.in);
                        System.out.println("Enter the data code:");
                        for(i=0;i<7;i++)
                        {
                                    a[i]=sr.nextInt();
                        }

79. JAVA PROGRAM FOR CYCLIC REDUNDANCY CHECK


//CYCLIC REDUNDANCY CHECK

import java.io.*;
import java.lang.*;
public class crc
{
public static void main(String args[]) throws IOException
{
int f[]=new int[25];
int gen[]=new int[10];
int rem[]=new int[10];
int flen,glen,rlen,i,j;
int p,sum,iframe,igen,irem;
String data;

Friday, August 24, 2012

78. BLOCK INTERCHANGE IN 8086


DATA SEGMENT
X DB 01H,02H,03H,04H,05H
Y DB 11H,12H,13H,14H,15H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA
MOV DS,AX
MOV CX,05H
LEA SI,X 
LEA DI,Y 
UP: MOV BL,[SI] 
MOV AL,[DI]
MOV [SI],AL 
MOV [DI],BL 
INC SI 
INC DI
DEC CX 
JNZ UP
MOV AH,4CH
INT 21H
CODE ENDS
END START

77. BLOCK TRANSFER IN 8086



DATA SEGMENT
X DB 01H,02H,03H,04H,05H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA 
MOV DS,AX
MOV CX,05H 
LEA SI,X+04 
LEA DI,X+04+03
UP: MOV BL,[SI] 
MOV [DI],BL 
DEC SI 
DEC DI
DEC CX 
JNZ UP
MOV AH,4CH
INT 21H
CODE ENDS
END START

Thursday, August 23, 2012

76. TCP CLIENT & SRVER IN JAVA

//TCP SERVER
import java.lang.*; import java.io.*; import java.net.*; class Server { public static void main(String args[]) { String data = "Toobie ornaught toobie"; try { ServerSocket srvr = new ServerSocket(1234); Socket skt = srvr.accept(); System.out.print("Server has connected!\n"); PrintWriter out = new PrintWriter(skt.getOutputStream(), true);

Friday, July 6, 2012

75. HTTP SERVER IN JAVA


// HTTP SERVER
import java.io.*;
import java.net.*;
import java.util.*;
import java.lang.*;


public class HttpServer
{
     public static void main(String [] args)
     {
          int i=1;
System.out.println("********************************************************************************");
System.out.println("******************************  HTTP 
SERVER***********************************");
System.out.println("********************************************************************************");
          System.out.println("Server Started...");
          System.out.println("Waiting for connections...");
          try
          {

74. CLIENT SERVER MULTICASTING


//SERVER SIDE
import java.io.*;
import java.net.*;
import java.util.Vector;
import java.util.Enumeration;
public class chatkaro12mServer
{
//static String k=socket.getInetAddress().getHostName();
private int port=5001;
private boolean li=true;
private Vector clients=new Vector();
public static void main(String a[])
{
System.out.println(" Press ctrl-c to Quit.");
new chatkaro12mServer().server();
}

73. CLCHAT IN JAVA


//CLIENT SIDE 
import java.net.*;
import java.io.*;
public class CLChatClient {


   static final int DEFAULT_PORT = 1728;  // Port where server is
                                          // listening, if no
                                          // port is specified
                                          // on the command line.
                                         
   static final String HANDSHAKE = "CLChat";  // Handshake string.
                   // Each end of the connection sends this string
                   // to the other just after the connection is 
                   // opened.  This is done to confirm that the
                   // program on the other side of the connection 
                   // is a CLChat program.   

Wednesday, July 4, 2012

72. FRACTAL EXPLORER IN JAVA




import java.awt.*;
import java.applet.*;
import java.awt.image.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;


public class Fractal extends Applet implements ActionListener, MouseListener, MouseMotionListener, 
AdjustmentListener, KeyListener, DocumentListener {
public static final int X = 800, Y = 550, ButX=72, ButY=26;
public static final int Min_Iter=0, Max_Iter=10000, SL_phMAX=200, SL_peMAX=400, Max_Fractal=6;
public static final double STX[]={ -2.7, -2.3, -2.5, -2.2, -5.2, 2.98 };

71. SUM OF SUBSETS PROBLEM


//SUM OF SUBSETS PROBLEM
import java.io.*;
import java.util.*;
public class SumOfSubsets
{
static int [] w;
static int [] x;
public static BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
public static void SumOfSubsets(int s, int k, int r, int m)
{
int i;
x[k]=1;
if((s+w[k])==m)
{
System.out.print("{");
for(i=1;i<=k;i++) System.out.print(x[i]+" ");

70. HAMILTONIAN CYCLE PROBLEM


//HAMILTONIAN CYCLE PROBLEM
import java.io.*;
public class Hamiltonian
{
static int [][] G;
static int [] x;
static int n;
static boolean found = false;
public static BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws IOException
{
System.out.println("\t\t\t\tHamiltonian Cycle");
System.out.print("\nEnter the number of the vertices: ");
n = Integer.parseInt(br.readLine());
G = new int[n+1][n+1];
x = new int[n+1];

69. GRAPH COLORING PROBLEM


//GRAPH COLORING PROBLEM
import java.io.*;
public class GraphColoring
{
static int [][] G;
static int [] x;
static int n, m;
static boolean found = false;
public static BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws IOException
{
System.out.println("\t\t\t\tGRAPH COLORING");
System.out.print("\nEnter the number of the vertices: ");
n = Integer.parseInt(br.readLine());
G = new int[n+1][n+1];
x = new int[n+1];

Tuesday, July 3, 2012

68. MIDPOINT SUBDIVISION LINE CLIPPING


//MIDPOINT SUBDIVISION LINE CLIPPING 
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
#include<math.h>
#include<graphics.h>
typedef struct coordinate
{
int x,y;
char code[4];
}PT;
void drawwindow();
void drawline (PT p1,PT p2,int cl);
PT setcode(PT p);

Sunday, July 1, 2012

67. THICK LINE DRAWING



//THICK LINE DRAWING
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int gd = DETECT, gm  ;
float wy, wx, x1, y1, x2, y2;
int i, thickness;
initgraph(&gd, &gm, "C:\\TC\\BGI");
printf("Enter the co-ordinates for the line:\n");
printf("X1: ");

66. SIERPINSKI TRIANGLE IN C


//SIERPINSKI TRIANGLE IN C
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <math.h>
#include <graphics.h>
void DrawSierpinski(void);
void main(void)
{
int gd=VGA;
int gm=VGAHI;
initgraph(&gd, &gm, "C:\\tc\\bgi");
DrawSierpinski();
getch();
}

65. MANDELBROT SET IN C


#include <stdio.h>
#include <graphics.h>
#include <conio.h>
#include <math.h>
#include <stdlib.h>
#include <alloc.h> 
int MX, MY; 
int MC; /* max color */
void init( void )
{
  int gd = 0, gm = VGALO;
  initgraph( &gd, &gm, "c:\\tc\\bgi");
} 
void initPalette( void )
{ int i;

Saturday, June 30, 2012

64. DDA LINE DRAWING


//DDA LINE DRAWING
#include<stdio.h>
#include<graphics.h>
#include<math.h>
main()
{
float x,y,x1,y1,x2,y2,dx,dy,length;
int i,gd,gm;
clrscr();
printf("Enter the value of x1 :\t");
scanf("%f",&x1);
printf("Enter the value of y1 :\t");
scanf("%f",&y1);

63. BRESENHAM LINE DRAWING


//BRESENHAM LINE DRAWING
#include<stdio.h>
#include<graphics.h>
#include<math.h>
main()
{
float x,y,x1,y1,x2,y2,dx,dy,e;
int i,gd,gm;
clrscr();
printf("Enter the value of x1 :\t");
scanf("%f",&x1);
printf("Enter the value of y1 :\t");
scanf("%f",&y1);
printf("Enter the value of x2 :\t");
scanf("%f",&x2);

62. CODE CONVERSION IN 8086


ASCII ADJUSTMENT INSTRUCTIONS


CODE SEGMENT
ASSUME CS:CODE
START: MOV AX,31H 
ADD AX,39H 
AAA
ADD AX,3030H 
MOV BL,9
MOV AX,0702H 
AAD 

Thursday, June 28, 2012

61. 16-BIT DIVISION IN 8086


16-BIT DIVISION FOR SIGNED NUMBERS


DATA SEGMENT
NUM1 DW 4567H,2345H
NUM2 DW 4111H
QUO DW 2 DUP(0)
REM DW 1 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA

60. 8-BIT DIVISION IN 8086


8-BIT DIVISION FOR UNSIGNED NUMBERS


DATA SEGMENT
NUM1 DB 72H,
NUM2 DB 02H
QUO DB 1 DUP(0)
REM DB 1 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AL,NUM1 

Wednesday, June 27, 2012

59. DDA CIRCLE DRAWING IN C


//DDA CIRCLE DRAWING
#include<stdio.h>
#include<graphics.h>
#include<math.h>
main()
{
float x1,y1,x2,y2,startx,starty,epsilon;
int gd,gm,i,val,cx,cy;
int r;
clrscr();
clrscr();
printf("Enter the center coordinates of a circle :"); 
scanf("%d%d",&cx,&cy); 
clrscr();

58. BEIZER CURVE IN C


//BEIZER CURVE
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int x,y,z;
void main()
{
float u;
int gd,gm,ymax,i,n,c[4][3];
for(i=0;i<4;i++) { c[i][0]=0; c[i][1]=0; }
printf("\n\n Enter four points : \n\n");
for(i=0; i<4; i++)
{
printf("\t X%d Y%d : ",i,i);
scanf("%d %d",&c[i][0],&c[i][1]);
}

Tuesday, June 26, 2012

57. LIANG BARSKY LINE CLIPPING


//LIANG BARSKY LINE CLIPPING
#include<graphics.h>
#include<dos.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int gd, gm ;
int x1 , y1 , x2 , y2 ;
int wxmin,wymin,wxmax, wymax ;
float u1 = 0.0,u2 = 1.0 ;
int p1 , q1 , p2 , q2 , p3 , q3 , p4 ,q4 ;
float r1 , r2 , r3 , r4 ;
int x11 , y11 , x22 , y22 ;
clrscr();
printf("Enter the windows left xmin , top boundry ymin\n");
scanf("%d%d",&wxmin,&wymin);
printf("Enter the windows right xmax ,bottom boundry ymax\n");
scanf("%d%d",&wxmax,&wymax);

56. COHEN SUTHERLAND LINE CLIPPING


//COHEN SUTHERLAND LINE CLIPPING
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#include<graphics.h>
typedef struct coordinate
{
int x,y;
char code[4];
}PT;
void drawwindow();
void drawline (PT p1,PT p2,int cl);
PT setcode(PT p);
int visibility (PT p1,PT p2);
PT resetendpt (PT p1,PT p2);
main()
{

55. SUTHERLAND HODGEMAN POLYGON CLIPPING


//SUTHERLAND HODGEMAN POLYGON CLIPPING
#include<stdio.h>
#include<graphics.h>
#include<math.h>
typedef struct
{
float x;
float y;
}PT;
int n;
main()
{
int i,j,gd,gm;
PT d,p1,p2,p[20],pi1,pi2,pp[20];
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"");
printf("Enter coordinates (left,top) of point1 : ");
scanf("%f%f",&p1.x,&p1.y);
printf("Enter coordinates (right,bottom) of point2 : ");
scanf("%f%f",&p2.x,&p2.y);
printf("Enter the number of vertex : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{

54. FLOOD FILL & BOUNDARY FILL ALGORITHM


//FLOOD FILL WITH EIGHT CONNECTED REGIONS
#include<stdio.h>
#include<graphics.h>
main()
{
int gd,gm;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"c:\\tc\\bgi");
rectangle(50,50,100,100);
flood(55,55,4,15);
getch();
closegraph();
}
flood(seed_x,seed_y,foreground_col,background_col)
{

53. MIDPOINT CIRCLE DRAWING


//MIDPOINT CIRCLE
#include<stdio.h>
#include<graphics.h>
#include<math.h>
main()
{
float d;
int gd,gm,x,y,cy,cx;
int r;
clrscr();
printf("Enter the center coordinates of a circle :"); 
scanf("%d%d",&cx,&cy); 
clrscr();
printf("Enter the radius of a circle :");
scanf("%d",&r);
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"C:\\TC\\BGI");
x = 0;
y = r;

52. BRESENHAM CIRCLE DRAWING


//BRESENHAM CIRCLE
#include<stdio.h>
#include<graphics.h>
#include<math.h>
main()
{
float d;
int gd,gm,x,y,cy,cx;
int r;
clrscr();
printf("Enter the center coordinates of a circle :");
scanf("%d%d",&cx,&cy);
clrscr();
printf("Enter the radius of a circle :");
scanf("%d",&r);
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"C:\\TC\\BGI");
x = 0;
y = r;

51. 16 & 32-BIT ADDITIONS IN 8086


16-BIT ADDITION


DATA SEGMENT
NUM DW 1234H, 0F234H
SUM DW 2 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AX,NUM 

50. 16-BIT MULTIPLICATION IN 8086



16-BIT MULTIPLICATION FOR UNSIGNED NUMBERS


DATA SEGMENT
NUM DW 1234H,1234H
PROD DW 2 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
LEA SI,NUM
MOV AX,[SI] 
MOV BX,[SI+2]

49. 16 & 32-BIT SUBTRACTIONS IN 8086



16-BIT SUBTRACTION

DATA SEGMENT
NUM DW 4567H,2345H
DIF DW 1 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME
CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
CLC

48. MATRIX MULIPLICATION

MOV SI,1000
       MOV BP,1020
       MOV DI,1050
L2:  MOV CX,00
L1:  MOV AL,[SI]
       MOV BL,[BP]
       MUL BL
       ADD CX,AX
       ADD BP,03
       INC SI

47. SEPARATING +VE & -VE NUMBERS

MOV SI,1100
      MOV CX,0A
      MOV AL,00
L2: MOV BX,[SI]
      ADD BX,00H
      JS L1
      INC SI
      INC AL

Monday, June 25, 2012

46. KOCH CURVE GENERATOR IN JAVA


//KOCH CURVE GENERATOR
import java.awt.*;
import java.awt.event.*;
public class Koch extends Frame
{  public static void main(String[] args){new Koch();}
   Koch()
   {  super("Koch. Click the mouse button to increase the level");
      addWindowListener(new WindowAdapter()
         {public void windowClosing(
                 WindowEvent e){System.exit(0);}});
      setSize (600, 500);
      add("Center", new CvKoch());
      show();
    }
}

Sunday, June 24, 2012

45. FTP PROTOCOL IN JAVA


Server Program:


import java.io.*;
import java.net.*;
public class Server
{
public static void main(String asd[]) throws Exception
{
ServerSocket ss=new ServerSocket(1024);
System.out.println(“ServerSocket Generated”);
Socket s=ss.accept();

44.UDP PROTOCOL IN JAVA


Server Program:

import java.io.*;
import java.net.*;
public class Server
{
public static void main(String str1[]) throws Exception
{
DatagramSocket ds;
byte[] buf=new byte[1024];
ds=new DatagramSocket(200);
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println(“Enter the String”);
InetAddress ia=InetAddress.getLocalHost();
while(true)
{

43. PRIORITY QUEUE USING HEAP


//PRIORITY QUEUE USING HEAP
#include<iostream.h>
#include<process.h>
#include<math.h>
#include<iomanip.h>
#include<malloc.h>
struct Heap
{
int capacity;
int size;
int *element;
};

42. HASHING TECHNIQUE IN C++



//HASHING TECHNIQUE
#include<iostream.h>
#include<iomanip.h>
struct listnode;
typedef struct listnode *position;
typedef position list;
struct hashtbl;
typedef struct hashtbl *hashtable;
hashtable initialize(int tablesize);
void destroytable(hashtable h);
position find(int key, hashtable h);
void insert(int key,hashtable h);
int retrieve(position p);
int hash(int key, int tablesize);

41. PRODUCER CONSUMER PROBLEM USING SEMAPHORE


//PRODUCER CONSUMER PROBLEM
#include<stdio.h>
#include<sys/types.h>
#include<sys/sem.h>
#include<stdlib.h>
#include<sys/shm.h>
#include<errno.h>
#include<sys/ipc.h>
void sem_acq(int);
void sem_rel(int);
int main()
{          int mutex,empty,full,shmid, n;
pid_t ret;
int in=-1,out=-1;
char *buffer;
char c[2];