Trending ▼   ResFinder  

Computer Science ISC Practical Questions

19 pages, 10 questions, 0 questions with responses, 0 total responses,    0    0
Pranav Karthik
Vikaasa School, Madurai
+Fave Message
 Home > pk25 >

Formatting page ...

COMPUTER SCIENCE ASSIGNMENT DONE BY, G Pranav Karthik XI-A Question 1 Write a program in Java to accept a Decimal number and convert that to a Binary number or Octal number as per user s choice. public class conversion { void main()throws IOException { InputStreamReader read=new InputStreamReader(System.in); BufferedReader ob=new BufferedReader(read); System.out.println( ENTER NUMBER TO BE CONVERTED ); int n=Integer.parseInt(ob..readLine()); System.out.println( ENTER 1 TO CONVERT INTO BINARY AND 2 TO CONVERT INTO OCTAL ); int i=Integer.parseInt(ob..readLine()); switch(i) { case 1: int d=0; String b= ; while(n!=0) { d=n%2; b=d+b; n=n/2; } System.out.println( BINARY VALUE= +b); obeak; case 2: int d; String o= ; while(n!=0) { d=n%8; o=d+o; n=n/8; } System.out.println( OCTAL VALUE= +o); obeak; Default: System.out.println( INVALID INPUT ); } } } QUESTION 2 Write a Java program to display the digits of the given number in words. The number should be less than 1000. import java.io.*; public class number_name { void main()throws IOException { InputStreamReader read=new InputStreamReader(System.in); BufferedReader ob=new BufferedReader(read); System.out.println( ENTER NUMBER WITHIN 1000 ); int n=Integer.parseInt(ob..readLine()); int p,r=0,k,s=0; while(n!=0) { p=n%10; s=(s*10)+p; n=n/10; r++; } if(r<=2) { while(s!=0) { k=s%10; switch(k) { case 1: System.out.print( ONE ); obeak; case 2: System.out.print( TWO ); obeak; case 3: System.out.print( THREE ); obeak; case 4: System.out.print( FOUR ); obeak; case 5: System.out.print( FIVE ); obeak; case 6: System.out.print( SIX ); obeak; case 7: System.out.print( SEVEN ); obeak; case 8: System.out.print( EIGHT ); obeak; case 9: System.out.print( NINE ); obeak; case 0: System.out.print( ZERO ); obeak; default: System.out.println( INVALID INPUT ); } s=s/10; } } else System.out.println( ENTER NUMBER WITHIN 1000 ); } } QUESTION 3 Write a program to print the reversal of a string using recursion. import java.io.*; public class reverse { int h=0; String S; void main()throws IOException { InputStreamReader read=new InputStreamReader(System.in); BufferedReader ob=new BufferedReader(read); System.out.println( ENTER STRING ENDING WITH FULLSTOP ); String S=ob.readLine(); System.out.println( REVERSED STRING: ); System.out.print( . ); print(h); } void print(int e) { h++; char ch=S.charAt(e); if(ch!= . ) { print(h); System.out.print(ch); } } } QUESTION 4 Write a program to declare a matrix A[ ][ ] of order (mxn) where m is the number of rows and n is the number of columns such that both m and n must be greater than 2 and less than 20. Allow the user to input positive integers into this matrix. Perform the following tasks on the matrix. a)Sort the elements of the outer row and column elements in ascending order using standard sorting technique and arrange them in an array. b)Calculate the sum of the outer row and column elements. EXAMPLE: Input: m=3 n=3 174 825 639 Output: ORIGINAL MATRIX: 174 825 639 REARRANGED MATRIX: 134 925 876 Sum of the outer row and column elements=43 import java.io.*; public class matrix { void main()throws IOException { int m,n,i,j,h,k,c=0,u,v,w,sum=0,temp,pos=0,small=0,x,y,g,p=0; InputStreamReader read=new InputStreamReader(System.in); BufferedReader ob=new BufferedReader(read); System.out.println( ENTER NUMBER OF ROWS ); m=Integer.parseInt(ob.readLine()); System.out.println( ENTER NUMBER OF COLUMNS ); n=Integer.parseInt(ob.readLine()); int A[ ][ ]=new int[m][n]; int a[ ]=new int[m*n]; System.out.println( ENTER ARRAY ELEMENTS: ); for(i=0;i<m;i++) { for(j=0;j<n;j++) A[i][j]=Integer.parseInt(ob.readLine()); } System.out.println( ORIGINAL MATRIX: ); for(i=0;i<m;i++) { for(j=0;j<n;j++) System.out.print(A[i][j]+ \t ); System.out.println(); } u=m-1; v=0; w=n-1; for(k=v;k<w;k++) { a[c]=A[v][k]; c++; } for(k=v;k<u;k++) { a[c]=A[k][w]; c++; } for(k=w;k<v;k++) { a[c]=A[u][k]; c++; } for(k=u;k<v;k++) { a[c]=A[k][v]; c++; } for(k=0;k<c;k++) sum=sum+a[k]; for(x=0;x<c;x++) { small=a[x]; pos=x; for(y=x+1;y<c;y++) { if(a[y]<small) { small=a[y]; pos=y; } } temp=a[pos]; a[pos]=a[x]; a[x]=temp; } for(k=v;k<w;k++) { A[v][k]=a[p]; p++; } for(k=v;k<u;k++) { A[k][w]=a[p]; p++; } for(k=w;k>v;k--) { A[u][k]=a[p]; p++; } for(k=u;k>v;k--) { A[k][v]=a[p]; p++; } System.out.println( REARRANGED MATRIX: ); for(h=0;h<m;h++) { for(g=0;g<n;g++) System.out.print(A[h][g]+ \t ); System.out.println(); } System.out.println( Sum of the outer row and column elements= +sum); } } QUESTION 5 Write a program to accept a number and check if it is a circular prime number or not. EXAMPLE: 197 is a prime number. 197, 719, 971 are prime numbers. import java.io..*; public class circular_prime { void main()throws IOException { Int t,n,m=0,r=0,d,c=0,n1,n2,f=0; InputStreamReader read=new InputStreamReader(System.in); BufferedReader ob=new BufferedReader(read); System.out.println( ENTER THE NUMBER TO BE CHECKED ); t=ob.readLine(); n=t; while(n=0) { n=n/10; c++; } while(r<=c) { d=t%10; n1=t/10; n2=d*(int)Math.pow(10,(-1))+n1; f=prime(n2); if(f>1) m=1; r++; t=n2; } if(m==1) { System.out..println( IT IS NOT A CIRCULAR PRIME ); } else { System.out.println( IT IS A CIRCULAR PRIME ); } } int prime(int n) { int c=0,i; for(i=2;i<n;i++) { if(n%i==0) { c++; } return c; } } } QUESTION 6 A Linked List is formed from the objects of the class: class node { int num; nodes next; } Write an algorithm or a method to print the sum of nodes that contain only odd numbers of an existing Linked List. The method declaration is as follows: void nodescount(nodes startptr) void nodescount(nodes startptr) { int sum=0; nodes p; p=startptr; while(p.next!=null) { if(p.num%2!=0) { sum=sum+p.num; } } } QUESTION 7 Write a program to store the names of 10 students in a text file. Sort the names and copy the contents into another text file. Display the content of both the text files. import java.io.*; import java.util.* public class files { String name[ ]=new String[10]; int i,j; String t,f1= file1.txt ,f2= file2.txt ; Scanner sc=new Scanner(System.in); void main()throws IOException { FileWriter fw=new FileWriter( file1.txt ); BufferedWriter bw=new BufferedWriter(fw); PrintWriter pw=new PrintWriter(bw); System.out.println( ENTER 10 NAMES: ); for(i=0;i<10;i++) { name[i]=sc.next(); pw.println(name[i]); } System.out.println( FILE 1: ); for(i=0;i<10;i++) { System.out.println(name[i]); } copy(f1,f2); fw.close(); bw.close(); pw.close(); } void copy(String f1,String f2) { FileReader fr=new FileReader(f1); BufferedReader ob=new BufferedReader(fr); FileWriter fw=new FileWriter(f2); BufferedWriter bw=new BufferedWriter(fw); PrintWriter pw=new PrintWriter(bw); for(i=0;i<10;i++) { name[i]=ob.readLine(); } for(i=0;i<9;i++) { for(j=(i+1);j<10;j++) { if(name[i].compareTo(name[j])>0) { t=name[i]; name[i]=name[j]; name[j]=t; } } } System.out.println( FILE 2: ); for(i=0;i<10;i++) { pw.println(name[i]); System.out.println(name[i]); } fr.close(); ob.close(); fw.close(); bw.close(); pw.close(); } } QUESTION 8 Write a program that accepts a paragraph and displays the following: a)Number of sentences in the paragraph. b)Number of vowels in each sentence of the paragraph. import java.io.*; import java.util.*; public class sentence { void main()throws IOException { InputStreamReader read=new InputStreamReader(System.in); BufferedReader ob=new BufferedReader(read); System.out.println( ENTER THE PARAGRAPH: ); String S=ob.readLine(); int v,i,j; StringTokenizer str=new StringTokenizer(S, . ); int no=str.countTokens(); System.out.println(NUMBER OF SENTENCES= +no); for(i=0;i<no;i++) { String sen=str.nextTokens(); v=0; for(j=0;j<sen.length();j++) { char c=sen.charAt(j); if(c== a ||c== e ||c== i ||c== o ||c== u ||c== A ||c== E || c== I ||c== O ||c== U ) v++; } System.out.println( SENTENCE: +sen); System.out.println( NUMBER OF VOWELS: +v); } } } QUESTION 9 Write a program to implement the operations of a stack using an array. import java.io.*; public class stack { int a[ ],size,top; stack(int s) { size=s; a[]=new int[size]; top=-1; } void push(int item) { if(top==(size-1)) System.out.println( STACK IS FULL ); else { top++; a[top]=item; } } int pop() { if(top==-1) { System.out.println( STACK IS EMPTY ); return(0); } else { int item=a[top]; top--; return(item); } } void main()throws IOException { InputStreamReader read=new InputStreamReader(System.in); BufferedReader ob=new BufferedReader(read); stack s=new stack[20]; System.out.println( ENTER STACK ELEMENTS, 0 TO TERMINATE ); int z; z=Integer.parseInt(ob.readLine()); while(z!=0) s.push(a); System.out.println( FINAL STACK: ); while(s.top!=-1) { int n=s.pop(); System.out.println(n); } } } QUESTION 10 A super class Detail has been defined to store the details of a customer. Define a subclass Bill to compute the monthly telephone charge of the customer as per the chart given below: Number of calls Rate 1 - 100 Only Rental Charge 101 - 200 60 paisa per call + rental charge 201 - 300 80 paisa per call + rental charge Above 300 1 rupee per call + rental charge The details of both the classes are given below: Class Name:Detail Data members/Instance variables: name:To store the name of the customer. address:To store the address of the customer. telno:To store the phone number of the customer. rent:To store the monthly rental charge. Member Functions: Detail(...):Parameterized constructor to assign values to data members. void show():To display the detail of the customer. Class Name:Bill Data members/Instance variables: n:To store the number of calls. amt:To store the amount to be paid by the customer. Member Functions: Bill(...):Parameterized constructor to assign values to data members of both classes and to initialize amt=0.0 void cal():Calculates the monthly telephone charge as per the charge given above. void show():To display the detail of the customer and amount to be paid. Specify the class Detail giving details of the constructor() and void show(). Using the concept of inheritance,specify the class Bill giving details of the constructor(), void cal() and void show(). The main function and algorithm need not be written. class Detail { String name,address; int telno; double rent; Detail(String n,String a,int t,double r) { name=n; address=ad; telno=t; rent=r; } void show() { System.out.println( NAME OF THE CUSTOMER: +name); System.out.println( ADDRESS OF THE CUSTOMER: +address); System.out.println( PHONE NUMBER OF THE CUSTOMER: +telno); System.out.println( RENT FOR THE CUSTOMER:Rs. +rent); } } class Bill extends Detail { int n; double amt; Bill(String na,String a,int te,double re,int c) { n=c; amt=0.0; super(na,a,te,re); } void cal() { if(n>=1&&n<=100) amt=rent; else if(n>=101&&n<=200) amt=rent+(0.60*(n-100)); else if(n>=201&&n<=300) amt=rent+((0.60*100)+(0.80*(n-200))); else amt=rent+((0.60*100)+(0.80*200)+(1*(n-300))); } void show() { super.show(); System.out.println( TOTAL COST=Rs. +amt); } } S.NO CONTENTS 1. Menu driven program to convert the given number into Binary and Octal. 2. Display the digits of a given number in words. 3. Reversal of a string using recursion. 4 Matrix manipulation. 5. Circular Prime. 6. To display the sum of odd numbers in a Linked List. 7. Sorting the records stored in the file in alphabetical order. 8. Display the number of sentences and vowels in each sentences of a paragraph. 9. Stack using Array. 10. Inheritance.

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

 

  Print intermediate debugging step

Show debugging info


 

 


© 2010 - 2026 ResPaper. Terms of ServiceContact Us Advertise with us

 

pk25 chat