Posts

Showing posts from 2016

5th sem OOPJ Create a class called Student. Write a student manager program to manipulate the student information from files by using DataInputStream and DataOutputStream.

import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; /**  *  * @author Yash  */ public class pra13 {     public static void main(String arg[]) throws FileNotFoundException, IOException{         DataInputStream din = new DataInputStream(new FileInputStream("new.txt"));         DataOutputStream dout = new DataOutputStream(new FileOutputStream("output1.txt"));                 String str;                 while((str=din.readLine()) != null){         String s2 = str.toUpperCase();         dout.writeBytes(s2 + "\n");         }         din.close();         dout.close();     } }

5th sem OOPJ Create a class called Student. Write a student manager program to manipulate the student information from files by using BufferedReader and BufferedWriter.

import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; /**  *  * @author Yash  */ public class pra12 {     public static void main(String arg[]) throws FileNotFoundException, IOException{         BufferedReader br = new BufferedReader(new FileReader("new.txt"));         BufferedWriter bw = new BufferedWriter(new FileWriter("output.txt"));                 int i;         do{             i=br.read();             if(i != -1){                 if(Character.isUpperCase((char)i)){                 bw.write(Character.toLowerCase((char)i));                 }else{                     bw.write((char)i);                 }             }         }while(i != -1);         br.close();         bw.close();                 } }

5th sem OOPJ Create a class called Student. Write a student manager program to manipulate the student information from files by using FileInputStream and FileOutputStream

import java.io.FileInputStream; import java.io.FileOutputStream; /**  *  * @author Yash  */ public class pra11 {     public static void main(String arg[])throws Exception{         FileOutputStream fout = new FileOutputStream("new.txt"); //new.txt shold be on same directory of the java program file.         String s1 = "\n Student's name : Mr. abc\n Branch : Computer Engineering\n Sem : 5th\n Batch : H";         byte b[] = s1.getBytes();         fout.write(b);                 FileInputStream fin = new FileInputStream("new.txt");         int i = 0;         while((i=fin.read()) != -1){             System.out.print((char)i);         }         fin.close();     } }

5th sem OOPJ Write an interactive program to print a diamond shape. For example, if user enters the number 3, the diamond will be as follows:

import java.util.Scanner; /**  *  * @author Yash  */ public class pra10 {     public static void main(String arg[]){         int i,j,k,n;         Scanner sc = new Scanner(System.in);         System.out.print("Enter the Range :");         n=sc.nextInt();         for(i=1;i<=n;i++){             for(j=n;j>=i;j--){                 System.out.print(" ");             }             for(k=1;k<=i;k++){                 System.out.print(" *");             }             System.out.println(" ");         }         for(i=1;i<=n;i++){             for(j=0;j<=i;j++){                 System.out.print(" ");             }             for(k=n;k>i;k--){                 System.out.print(" *");             }             System.out.println(" ");         }     } }

5th sem OOPJ Write an interactive program to print a string entered in a pyramid form. For instance, the string “stream” has to be displayed as follows.

import java.util.Scanner; /**  *  * @author Yash  */ public class pra9 {     public static void main(String arg[]){         char c;         int i,j,k;         Scanner sc = new Scanner(System.in);         String s1;         System.out.print("Enter the String :");         s1=sc.next();         for(i=0;i<s1.length();i++){             for(j=0;j<=s1.length()-i;j++){                 System.out.print(" ");             }             for(k=0;k<=i;k++){                 c = s1.charAt(k);                 System.out.print(c+" ");             }             System.out.println(" ");         }     } }

5th sem OOPJ Create a class which asks the user to enter a sentence, and it should display count of each vowel type in the sentence. The program should continue till user enters a word “quit”. Display the total count of each vowel for all sentences.

import java.util.*; /**  *  * @author Yash  */ public class pra8 { public static void main(String arg[]){         String s1 = new String();                 while(!s1.equals("quit")){         char ch;         int vol=0,cont=0;         System.out.println("Enter the String..");         Scanner sc = new Scanner(System.in);         s1 = sc.nextLine();         StringBuffer sb = new StringBuffer(s1);         for(int i=0;i<sb.length();i++){             ch = sb.charAt(i);             if( ch=='a' || ch=='A' || ch=='e' || ch=='E' || ch=='i' || ch=='I' || ch=='o' || ch=='O' || ch=='u' || ch=='U'){                 vol++;             }else{                 cont++;             }         }         System.out.println("voweles : "+vol);         System.out.println("Consonants :" +cont);         }     }   }

5th sem OOPJ Write a program to find that given number or string is palindrome or not.

import java.io.*; import java.util.*; /**  *  * @author Yash  */ class pra7{     public static void main(String arg[]){                 Scanner sc = new Scanner(System.in);                 System.out.println("Enter String :");         int n = sc.nextInt();                 int r,sum=0,temp;                   temp=n;           while(n>0){           r=n%10;  //getting remainder         sum=(sum*10)+r;           n=n/10;               }           if(temp==sum)               System.out.println("palindrome number ");           else               System.out.println("not palindrome");     }   }

5th sem OOPJ Write a program to count the number of words that start with capital letters.

import java.io.*; /**  *  * @author Yash  */ class pra6{     public static void main(String arg[]) throws IOException{         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));                 int num=0;         System.out.println("Write a line :");         String str  = br.readLine();                 for(int i=0;i<str.length();i++){             if(Character.isUpperCase(str.charAt(i))){              num++;             }         }         System.out.println("The Number of Upper case is : "+num);     }   }

5th sem OOPJ Write a program to accept a line and check how many consonants and vowels are there in line.

import java.io.*; /**  *  * @author Yash  */ class pra5{     public static void main(String arg[]) throws IOException{         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));         char ch;         int vol=0,cont=0;         System.out.println("Write a line :");         String str  = br.readLine();                 for(int i=0;i<str.length();i++){             ch = str.charAt(i);             if( ch=='a' || ch=='A' || ch=='e' || ch=='E' || ch=='i' || ch=='I' || ch=='o' || ch=='O' || ch=='u' || ch=='U'){                 vol++;             }else{                 cont++;             }         }         System.out.println("voweles : "+vol);         System.out.println("Consonants :" +cont);     }   }

5th sem OOPJ Write a program to find length of string and print second half of the string.

import java.text.*; import java.util.*; /**  *  * @author Yash  */ class pra4{     public static void main(String arg[]){         Scanner sc = new Scanner(System.in);         DecimalFormat numfor = new DecimalFormat("#.000");//This is to fix after the decimal size.                 System.out.println("Enter your String :");         String str = sc.nextLine();         System.out.println("The Length of string is : "+str.length());         System.out.println("Second half of string is :"+str.substring(str.length()/2,str.length()));             }   }

5th sem OOPJ Write a program to enter two numbers and perform mathematical operations on them.

import java.text.*; import java.util.*; /**  *  * @author Yash  */ class pra3{     public static void main(String arg[]){         Scanner sc = new Scanner(System.in);         Scanner sc1 = new Scanner(System.in);                 double a,b;                                 System.out.println("Select  '+' '-' '*' '/' ");         System.out.print("Enter the value of a : ");         a = sc.nextDouble();         System.out.print("Enter the value of b : ");         b = sc.nextDouble();         System.out.println("Select you choice:");         String cho = sc1.nextLine();         switch(cho){             case "+" :                 System.out.println("You have selected addition ");                 System.out.println("Your Answer is : "+(a+b));                 break;             case "-":                 System.out.println("You have selected subtrac

5th sem OOPJ Write a program that calculates percentage marks of the student if marks of 6 subjects are given.

import java.text.*; import java.util.*; /**  *  * @author Yash  */ class pra2{     public static void main(String a[]){         Scanner sc = new Scanner(System.in);         DecimalFormat numfor = new DecimalFormat("#.000");//This is to fix after the decimal size.         int arr[] = new int[6];         int total=0;                 for(int i=0;i<arr.length;i++){             System.out.println("Enter sunject "+(i+1)+" Marks:");             arr[i] = sc.nextInt();             total +=arr[i];         }         double per = total/6;         System.out.println("Percentage of 6 subject is"+numfor.format(per));     }   }

5th sem OOPJ Write a program to convert rupees to dollar. 60 rupees=1 dollar.

import java.text.*; import java.util.*; /**  *  * @author Yash  */ class pra1{     public static void main(String a[]){         Scanner sc = new Scanner(System.in);         DecimalFormat numfor = new DecimalFormat("#.000");//This is to fix after the decimal size.         System.out.println("Enter the rupees :");         double rup = sc.nextInt();         double dol = rup/60;         System.out.println("Your Current doller is : " + numfor.format(dol));     }   }

5th sem ADA programm to implement sorting algorithms

Bubble sort in c #include<stdio.h> void bubble(int n,int arr[]); void main() {     int n;     printf("enter the size of array:");     scanf("%d",&n);     int arr[n];     int i,j,k;     printf("enter the array elemets:\n");     for(i=0;i<n;i++)     {         scanf("%d",&arr[i]);     }     bubble(n,arr);      printf("\nyour sorted array is :\n");     for(i=0;i<n;i++)     {         printf("%d\n",arr[i]);     } } void bubble(int n, int arr[n]) {     int i,j,swap;     for(i=0;i<n;i++)     {         for(j=0;j<n-i-1;j++)         {             if(arr[j]>arr[j+1])             {                 swap=arr[j];                 arr[j]=arr[j+1];                 arr[j+1]=swap;             }         }     } }

5th sem ADA programm to implement sorting algorithms

 Insertion sort in c #include<stdio.h> void insertion(int n,int arr[]); void main() {     int n,i;     printf("enter the size of array:");     scanf("%d",&n);     int arr[n];     printf("enter the array elements:\n");     for(i=0;i<n;i++)     {         scanf("%d",&arr[i]);     }     insertion(n,arr);     printf("\nyour sorted array is:\n");     for(i=0;i<n;i++)     {         printf("%d\n",arr[i]);     } } void insertion(int n,int arr[n]) {     int i,j,swap;     for(i=1;i<n;i++)     {         j=i;         while(j>0 && arr[j] < arr[j-1])         {             swap=arr[j];             arr[j]=arr[j-1];             arr[j-1]=swap;             j--;         }     } }

4th sem OOPC Write the following programs using INHERITANCE in CPP language.

1.        To enter and display the student data using single inheritance technique. #include<iostream> #include<conio.h> using namespace std; class student{ public:     int roll_no;     char name[20];     void get(){         cout<<"\nEnter Student name: ";         cin>>name;         cout<<"Enter Student Roll No: ";         cin>>roll_no;     } }; class subject:public student{ public:     char sub1[10],sub2[10],sub3[10];         void getsub(){             cout<<"Enter first subject: ";             cin>>sub1;             cout<<"Enter Second subject: ";             cin>>sub2;             cout<<"Enter Third subject: ";             cin>>sub3;             } }; class school:public subject{     public:     void display(){             cout<<"\nRoll No: "<<roll_no<<"\nName: "<<name<<&quo

4th sem OOPC Write the following programs using OPERATOR OVERLOADING in CPP language.

1.        Write a program to enter two integers, two float number, two double numbers and find and display the greater of them using function overloading technique. #include<iostream> #include<conio.h> using namespace std; class over{     public:     int get(int,int);     float get(float,float);     double get(double,double); }; int over::get(int a,int b){         if(a>b){             return a;         }else{             return b;         } } float over::get(float a,float b){         if(a>b){             return a;         }else{             return b;         } } double over::get(double a,double b){     if(a>b){         return a;     }else{         return b;     } } int main(){     int n1,n2,t;     float x,y;     double p,q;     over obj;     //clrscr();     cout<<"\nEnter two integer number: "<<endl;     cin>>n1>>n2;     t=obj.get(n1,n2);     cout<<"Maximum number is: "<

4th sem OOPC Write the following programs using CONSTRUCTOR & DESTRUCTOR in CPP language.

1.        To enter two operands using constructor and perform arithmetic operations (+,-,*, /) on them and display the results. #include<iostream> #include<conio.h> using namespace std; class operation {     public:     int a,b;     operation(int x,int y)     {         a=x;         b=y;         cout<< a<< "+" << b <<"="<< a+b<<"\n";         cout<<a << "-"<<b<<"="<<a-b<<"\n";         cout<<a<<"*"<<b<<"="<<a*b<<"\n";         cout<<a<<"/"<<b<<"="<<a/b<<"\n";     } }; int main() {     int m,n;     cout <<"enter the values of oprands "<<endl;     cin>>m>>n;     operation(m,n);     return 0; } 2.        Write a program to generate a Fibonacci series

4th sem oopc programs usinng function in cpp

Ø   Write the following programs using FUNCTION in CPP language. 1.        Write a program to find sum of three numbers using functions. 1.        Write a program to find sum of three numbers using functions. #include<iostream.h> #include<conio.h> int sum(int a,int b,int c){     return(a+b+c); } int main(){     int x,y,z;     clrscr();     cout<<"Enter three value:"<<endl;     cin>>x>>y>>z;     cout<<"Sum is "<<sum(x,y,z);     getch();     return 0; } 2.      Write a function big to find largest of two numbers and use this function in the main program to find largest of three numbers.  #include<iostream.h> #include<conio.h> int max(int,int); int max(int ,int ,int); int main(){     int a,b,c;     clrscr();     cout<<"Enter a value : \n";     cin>>a>>b>>c;     cout<<"Max from three value.\n"<<max(a,b,

4th sem oopc programs in CPP (C++)

Ø   Write the following programs in CPP (C++) language. 1.        To find highest of three numbers using if loop. #include<iostream.h> int main(){ int a,b,c; cout<<"Enter three Value of A B and C"<<endl; cin>>a>>b>>c; if(a>b){ cout<<"A is max"<<endl; }else if(b>c){ cout<<"B is max"<<endl; }else{ cout<<"C is max"<<endl; } return 0; } 2.        Write a program to convert degree Fahrenheit to Celsius. #include<iostream.h> #include<conio.h> void main(){    float f,c;    clrscr();    cout<<"Enter fahrenhit temp: \n";    cin>>f;    c=(f-32)*5/9;    cout<<"Farenhit temp \n"<<f;    cout<<"Eguivalent of celcius \n"<<c;    getch();    return 0; }   3.        Write a program to display prime property of a given number. #include<iostream.h> #include<

4th sem oopc programs in C

Ø   Write the following programs in C language. 1.Write a program to find area of a circle. #include<stdio.h> #include<conio.h> #define PI 3.14 int main(){  float r,ans;  printf(" Enter the radius os circule r=");  scanf("%f",&r);  ans=PI*r*r;  printf("\n Radius of the circle is %.2f ",ans);  return 0; } 2.        Write a program for sum of two numbers . #include<stdio.h> #include<conio.h> int main(){     int a,b,c;     printf("\n Enter the value of A=");     scanf("%d",&a);     printf("\n Enter the value of B=");     scanf("%d",&b);     c=a+b;     printf("\n Sum of two number is %d \n",c);     return 0; } 3.        Write a program to swap two numbers using third variable . #include<stdio.h> #include<conio.h> int main(){   int a,b,temp;   printf("Enter two number. \n");