Wednesday, 27 March 2013

JAVA PROGRAMS USING LINKEDLIST, GENERIC COLLECTIONS FOR STUDENT LIST


 import java.util.*; /* scanner function is used*/

class StudList {
  private String name;
  private String USN;
  private String college;

   StudList(String n, String s, String c) {
    name = n;
    USN = s;
    college = c;
  }

  public String toString() {
    return name + ":" + USN + ":" + college;
  }
}

public class FourB {
  public static void main(String args[]) 
{
  LinkedList<StudList> ml = new LinkedList<StudList>();

  ml.add(new StudList("Shwetha", "1MS00IS101", "MSRIT"));
  ml.add(new StudList("Mishti", "1MS00IS102", "RVCE"));
  ml.add(new StudList("Purvi ", "1MS00IS103","BMSCE"));
  ml.add(new StudList("Aditya", "1MS00IS104", "PESIT"));
  ml.add(new StudList("Rohit", "1MS00IS105", "NMIT"));


System.out.println("Accessing Via Iterator....");
Iterator<StudList> it = ml.iterator();

while (it.hasNext()) {
   String element=it.next().toString();
   System.out.println(element + "");
}

System.out.println("Number of students in the list: "+ml.size());

System.out.println("Which student do you want to remove?");
Scanner s = new Scanner(System.in);
int pos = s.nextInt();
ml.remove(pos);

System.out.println("New Kind of For Loop...List is now...");
    for (StudList element : ml){
      System.out.println(element);
    }
System.out.println("Number of students in the list is"+ml.size());
System.out.println("Shuffling the list...");
Collections.shuffle(ml);
System.out.println("List after shuffling is ...");
    for (StudList element : ml){
      System.out.println(element);
    }

System.out.println("First Student is :"+ml.getFirst());
System.out.println("Last Student is :"+ml.getLast());
  }
}



Sunday, 24 March 2013

CN2 LEAKY BUCKET PROGRAM


#include<stdio.h>
#include<stdlib.h>
#define MIN(x,y) (x>y)? y:x
int main()
{

    int orate, drop=0,cap,x,count=0,inp[10]={0},i=0,nsec,ch;
    printf("\n enter the bucket size");
    scanf("%d",&cap);
    printf("\n enter the output rate");
    scanf("%d",&orate);
    do
    {
        printf("\n enter the number of packets coming at second %d",i+1);
        scanf("%d",&inp[i]);
        i++;
        printf("\n press 1 to continue or 0 to exit------");
        scanf("%d",&ch);
        }
         while(ch);
         nsec=i;
        printf("\n sec\t rec\t sent\t drop\t rem\n");
        for(i=0;count||i<nsec;i++)
       {
        printf("%d",i+1);
        printf("\t %d\t",inp[i]);
        printf("%d\t", MIN((inp[i]+count),orate));
        if((x=inp[i]+count-orate)>0)
        {
           if(x>cap)
           {
             count=cap;
            drop=x-cap;
            }
            else
            count=x;
            drop=0;
            }
        else
        {
        drop=0;
        count=0;
        }
        printf("%d\t %d\n",drop,count);
    }
    }
    


Thursday, 7 March 2013

SS pass1 assembler program


there following files have to be included in the program 
# include <stdio.h>
# include <string.h>
void main()
{
char opcode[10],mnemonic[3],operand[10],label[10],code[10];
int locctr,start,length;
FILE *fp1,*fp2,*fp3,*fp4;
fp1=fopen("input.txt","r");
fp2=fopen("symtab.txt","w");
fp3=fopen("out.txt","w");
fp4=fopen("optab.txt","r");
fscanf(fp1,"%s%s%s",label,opcode,operand);
if(strcmp(opcode,"START")==0)
{
start=atoi(operand);
locctr=start;
fprintf(fp3,"\t%s\t%s\t%s\n",label,opcode,operand);
fscanf(fp1,"%s%s%s",label,opcode,operand);
}
else
locctr=0;
while(strcmp(opcode,"END")!=0)
{
fprintf(fp3,"%d\t",locctr);
if(strcmp(label,"**")!=0)
fprintf(fp2,"%s\t%d\n",label,locctr);
rewind(fp4);
fscanf(fp4,"%s",code);
while(strcmp(code,"END")!=0)
{
if(strcmp(opcode,code)==0)
{
locctr+=3;
break;
}
fscanf(fp4,"%s",code);
}
if(strcmp(opcode,"WORD")==0)
locctr+=3;
else if(strcmp(opcode,"RESW")==0)
locctr+=(3*(atoi(operand)));
else if(strcmp(opcode,"RESB")==0)
locctr+=(atoi(operand));
else if(strcmp(opcode,"BYTE")==0)
++locctr;
fprintf(fp3,"%s\t%s\t%s\n",label,opcode,operand);
fscanf(fp1,"%s%s%s",label,opcode,operand);
}
fprintf(fp3,"%d\t%s\t%s\t\%s\n",locctr,label,opcode,operand);
length=locctr-start;
printf("The length of the program is %d",length);
fclose(fp1);
fclose(fp2);
fclose(fp3);
fclose(fp4);
}

INPUT FILES

input.txt


** START 2000
** LDA FIVE
** STA ALPHA
** LDCH CHARZ
** STCH C1
ALPHA RESW 1
FIVE WORD 5
CHARZ BYTE C’Z’
C1 RESB 1
** END **

optab.txt

START
LDA
STA
LDCH
STCH
END


OUTPUT FILES

out.txt

** START 2000
2000 ** LDA FIVE
2003 ** STA ALPHA
2006 ** LDCH CHARZ
2009 ** STCH C1
2012 ALPHA RESW 1
2015 FIVE WORD 5
2018 CHARZ BYTE C’Z’
2019 C1 RESB 1
2020 ** END **

symtab.txt

ALPHA 2012
FIVE 2015
CHARZ 2018
C1 2019




JAVA PACKAGES PROGRAMS


We have to create 3 different packages for this program  and execute  it.

Vehicle.java



package package1;

public abstract class Vehicle
{    
            public int year;
            public abstract void getData();
            public abstract void putData();
}

class FourWheeler extends Vehicle{
            public void getData()
            {
                  year=92;
            }
            public void putData()
            {
                  System.out.println("Year of manufacture of the fourwheeler is"+year);
            }
}
 

prog2.java

package package2;
import package1.*;
class TwoWheeler extends Vehicle{
      private String EngineType="2-s";
      protected String Brand="Y";
      public String Color="Black";
      public void getData()
      {
                  EngineType="2-stroke";
                  Brand="Yamaha";
                  Color="Black";
                  year=88;
      }
      public void putData()
      {
                  System.out.println("Year of manufacture of the twowheeler is"+year);
                  System.out.println("Engine type is " +EngineType+" ,Brand is "+Brand+" ,Color is "+Color);
      }
            void printprivate()
      {
                  System.out.println("Accessing private variable"+ EngineType);
      }
      }
class MyTwoWheeler extends TwoWheeler
{
      public String OwnerName;
      MyTwoWheeler()
      {
            super();
            OwnerName="Mandhara";
            printprivate();
            System.out.println(""+Brand+" "+Color+" "+OwnerName);
      }
     
}

public class prog2 {
      public static void main(String[] args)
      {
            TwoWheeler a=new TwoWheeler();
            a.getData();
            a.putData();
            MyTwoWheeler b=new MyTwoWheeler();
      }

}
 

prog.java

package package3;

public class prog {

}