Posts

CS8461- OPERATING SYSTEMS LABORATORY-Write C programs to simulate UNIX commands like cp, ls, grep, etc.

Write C programs to simulate UNIX commands like cp, ls, grep, etc. x Before seeing the program you have to learn about what is the meaning of the following commands. cp - copy- it is used to copying contents from one file to another file. Syntax: cp Source Destination ls -list- its used to list all file names in the directory. Syntax: ls grep- The grep filter searches a file for a particular pattern of characters, and displays all lines that contain that pattern. Syntax: grep [options] pattern [files] Options Description -c : This prints only a count of the lines that match a pattern -h : Display the matched lines, but do not display the filenames. -i : Ignores, case for matching -l : Displays list of a filenames only. -n : Display the matched lines and their line numbers. Below code is included code of  both cp & ls command. Program: #include<stdio.h> #include<stdlib.h> #include<dirent.h> #define D...

CS8382-OBJECT ORIENTED PROGRAMMING LABORATORY-TO FIND THE MAXIMUM VALUE FROM THE GIVEN TYPE OF ELEMENTS USING GENERIC FUNCTION

CS8383-OBJECT ORIENTED PROGRAMMING LABORATORY-TO FIND THE MAXIMUM VALUE FROM THE GIVEN TYPE OF ELEMENTS USING  GENERIC FUNCTION CS8382-OBJECT ORIENTED PROGRAMMING LABORATORY PROGRAM: import java.util.Scanner; public class MaximumTest {    // determines the largest of three Comparable objects        public static <T extends Comparable<T>> T maximum(T x, T y, T z) {       T max = x;   // assume x is initially the largest              if(y.compareTo(max) > 0) {          max = y;   // y is the largest so far       }              if(z.compareTo(max) > 0) {          max = z;   // z is the largest now                        }       return ma...

CS8382-OBJECT ORIENTED PROGRAMMING LABORATORY-TO GERNERATE RANDOM NUMBER USING LINEAR CONGRUENTIAL METHOD IN JAVA

CS8382-OBJECT ORIENTED PROGRAMMING LABORATORY GERNERATE RANDOM NUMBER USING  LINEAR CONGRUENTIAL METHOD IN JAVA PROGARM:  import java.util.*; public class myRnd {         final int m,a,b;      int x;   public myRnd(){             Scanner in=new Scanner(System.in);         System.out.println("enter the value of m");         m=in.nextInt();                 System.out.println("enter the value of a");         a=in.nextInt();         System.out.println("enter the value of b");         b=in.nextInt();                               x = m / 2;   }          double next() {           ...

CS8382-OBJECT ORIENTED PROGRAMMING LABORATORY-Create user defined Exception Handling in Java

CS8382-OBJECT ORIENTED PROGRAMMING LABORATORY CREATE A USER DEFINED EXCEPTION HANDLING IN JAVA  PROGRAM: import java.util.Scanner; import java.io.*; public class Demo{ public static void main(String args[]){ try { int ch;   System.out.println("enter\n1.arithmeticexception\n2.arrayindexOfBoundexception\n3.Nullpointerexception\n4.NumberFormtexception \n enter your choice:\n"); Scanner in=new Scanner(System.in); ch=in.nextInt(); switch(ch) {   case 1:            int  a;            a=args.length;            System.out.println("a"+a);            int b=42/a;             break; case 2:            int c[]={1};            c[42]=99;            break; case 3:             ...

CS8382-OBJECT ORIENTED PROGRAMMING LABORATORY-FILE HANDLING METHODS

CS8382-OBJECT ORIENTED PROGRAMMING LABORATORY QUESTION :Write a Java program that reads a file name from the user, displays information about whether the file exists, whether the file is readable, or writable, the type of file and the length of the file in bytes PROGRAM: import java.io.*; import java.util.Scanner; class Opfile{     Scanner sc= new Scanner(System.in); void show(){     String fname; //getting file name from user System.out.println("enter file name");         fname=sc.next();         //assign as file name         File f= new File(fname);          String line=null;         try         {              FileReader fileReader=new FileReader(f);                              ...

CS8382-OBJECT ORIENTED PROGRAMMING LABORATORY-STACK ADT USING JAVA ARRAY WITH EXCEPTION HANDLING

CS8382-OBJECT ORIENTED PROGRAMMING LABORATORY QUESTION: Design a Java interface for ADT Stack. Implement this interface using array. Provide necessary exception handling in both the implementations. Program: import java.io.*; interface Mystack {     public void pop();     public void push();     public void display(); } class Stack_array implements Mystack {     final static int n=5;     int stack[]=new int[n];     int top=-1;     public void push()     {         try         {             BufferedReader br=new BufferedReader(new InputStreamReader(System.in));             if(top==(n-1))             {                 System.out.println(" Stack Overflow");                 ...