## Wednesday, March 24, 2010

### ISC-2010 Computer Science practical examination programs

This is the solved page of 2010 ISC practical Computer Application paper on  BlueJ.

PROGRAM NUMBER 1

A bank intends to design a program to display the denomination of an
input amount, upto 5 digits. The available denomination with the bank are
of rupees 1000,500,100,50,20,10,5,2 and 1.

Design a program to accept the amount from the user and display the
break-up in descending order of denominations. (i,e preference should
be given to the highest denomination available) along with the total
number of notes. [Note: only the denomination used should be displayed].
Also print the amount in words according to the digits.

Example 1:
INPUT: 14836
OUTPUT: ONE FOUR EIGHT THREE SIX
DENOMINATION:
1000 X 14 =14000
500  X 1  =500
100  X 3  =300
50   X 1  =50
5    X 1  =5
1    X 1  =1

EXAMPLE 2:
INPUT: 235001
OUTPUT: INVALID AMOUNT

import java.io.*;
class Bank
{
int rev=0,amount,dummy;
public void intake() throws IOException
{
System.out.println("Enter the Amount:");
if(amount >99999)
{
System.out.println("Invalid Amount...");
return;
}
dummy=amount;
while(dummy >0)
{
rev=rev*10+dummy%10;
dummy=dummy/10;
}
System.out.print("Amount in words :");
while(rev >0)
{
switch(rev%10)
{
case 0:
System.out.print(" ZERO");
break;
case 1:
System.out.print(" ONE");
break;
case 2:
System.out.print(" TWO");
break;
case 3:
System.out.print(" THREE");
break;
case 4:
System.out.print(" FOUR");
break;
case 5:
System.out.print(" FIVE");
break;
case 6:
System.out.print(" SIX");
break;
case 7:
System.out.print(" SEVEN");
break;
case 8:
System.out.print(" EIGHT");
break;
case 9:
System.out.print(" NINE");
break;
}
rev=rev/10;
}
System.out.println("\nDENOMINATORS:\n");
rev=amount/1000;
if(rev!=0)
System.out.println("1000 X " + rev + " = " + rev*1000);
amount=amount%1000;
rev=amount/500;
if(rev!=0)
System.out.println("500 X " + rev + " = " + rev*500);
amount=amount%500;
rev=amount/100;
if(rev!=0)
System.out.println("100 X " + rev + " = " + rev*100);
amount=amount%100;
rev=amount/50;
if(rev!=0)
System.out.println("50 X " + rev + " = " + rev*50);
amount=amount%50;
rev=amount/20;
if(rev!=0)
System.out.println("20 X " + rev + " = " + rev*20);
amount=amount%20;
rev=amount/10;
if(rev!=0)
System.out.println("10 X " + rev + " = " + rev*10);
amount=amount%10;
rev=amount/5;
if(rev!=0)
System.out.println("5 X " + rev + " = " + rev*5);
amount=amount%5;
rev=amount/2;
if(rev!=0)
System.out.println("2 X " + rev + " = " + rev*2);
amount=amount%2;
rev=amount/1;
if(rev!=0)
System.out.println("1 X " + rev + " = " + rev*1);
}
}

### Detail study of the program

Here in this program, the amount is entered by user and stored in variable ‘amount’. While entering the amount, it is checked whether the amount is less than or equal to Rs. 99999. Firstly the amount is displayed in words. To perform this job the number is reversed and stored in another variable ‘rev’. Using a for loop the digits from the amount stored in ‘rev’ is retrieved and using switch statement, each digit is compared with starting from ‘0’ to ‘9’ and its matching word is displayed. In the next part of the program, the amount is divided the denomination available in descending order and the remainder is calculated by using modulo operator

PROGRAM NUMBER 2:

Given the two positive integers p and q, where p < q. Write a program to determine how many kaprekar numbers are there in the range between 'p' and 'q'(both inclusive )and output them.About 'kaprekar' number:
A posotive whole number 'n' that has 'd' number of digits is squared and split into
2 pieces, a right hand piece that has 'd' digits and a left hand piece that has
remaining 'd' or 'd-1' digits. If sum of the pieces is equal to the number then
it's a kaprekar number.

SAMPLE DATA:
INPUT:
p=1
Q=1000
OUTPUT:
THE KAPREKAR NUMBERS ARE:
1,9,45,55,99,297,999
FREQUENCY OF KAPREKAR NUMBERS IS:8

import java.io.*;
class Bank
{
int i,p,q,c=0;
int num;
public void take() throws IOException
{

System.out.println("Enter the Lower Range:");
System.out.println("Enter the Upper Range:");
if(p >=q)
{
System.out.println("Wrong Entry...");
return;
}
System.out.println("THE KAPREKAR NUMBERS ARE:");
for(i=p;i< =q;i++)
{
show(i);
}
System.out.println("FREQUENCY OF KAPREKAR NUMBERS IS:"+c);
}
public void show(int x)
{
int digit,rev=0;int no;num=x*x;digit=0;no=x;
while(no >0)
{
digit++;
no=no/10;
}
no=num;
while(digit > 0)
{
rev=rev*10+no%10;
no=no/10;
digit--;
}

// 'rev' holds the right part in reverse order and 'no' holds the left part
rev=reverse(rev);
if((rev+no)==x)
{
System.out.print("  "+x);
c++;
}
}
private int reverse(int n)
{
int r=0;
while(n > 0)
{
r=r*10+n%10;
n=n/10;
}
return r;
}
}
PROGRAM NUMBER 3

Input a paragraph containing ‘n’ number of sentences where (1<=n<=4). The words are to be separated with single blank space and are in upper case. A sentence may be terminated either with a full stop (.) or question mark (?).

Perform the followings:(i) Enter the number of sentences, if it exceeds the limit show a message.
(ii) Find the number of words in the paragraph
(iii) Display the words in ascending order with frequency.

import java.io.*;
import java.util.*;
class Bank
{
String s,str,sarr[],strarr[];
StringTokenizer st;
int i,j,n,c,index=0,fre[],index1=0;
public void take() throws IOException
{
System.out.println("Enter the Number of sentences:");
if(n< 1 || n >4)
{ System.out.println("Wrong Input...");
return;
}
System.out.println("Enter the Paragraph:");
st=new StringTokenizer(str,",.? ");
n=st.countTokens();
System.out.println("Number of Words in the paragraph="+n);
sarr=new String[n];
strarr=new String[n];
fre=new int[n];
while(st.hasMoreTokens())
{
sarr[index++]=st.nextToken();
}
for(i=0;i< index-1;i++)
{
for(j=i+1;j< index;j++)
{
if(sarr[i].compareTo(sarr[j]) > 0)
{
s=sarr[i];
sarr[i]=sarr[j];
sarr[j]=s;
}
}
}

c=1;
s=sarr[0];
for(i=1;i< index;i++)
{
if(!s.equals(sarr[i]))
{
strarr[index1]=s;
fre[index1++]=c;
c=1;
s=sarr[i];
}
else
c++;
}
strarr[index1]=s;
fre[index1++]=c;
for(i=0;i< index1-1;i++)
{
for(j=i+1;j< index1;j++)
{
if(fre[i] > fre[j])
{
n=fre[i];
fre[i]=fre[j];
fre[j]=n;
s= strarr[i];
strarr[i]=strarr[j];
strarr[j]=s;
}
}
}
System.out.println("WORD          FREQUENCY");
for(i=0;i< index1;i++)
System.out.println(strarr[i]+"    "+fre[i]);
}
}

Detail study of the program.

This is a program based on String array in java. The paragraph is entered and using StringTokenizer class of java.util package, the text is broken into tokens in such a manner that each token contain only word. The words are stored in a String array. After that the String array is sorted in ascending order. A second String array object is used to store the unique words and another integer array is used to store their frequency.

1. thanks a lot...........

2. suggest som questions for pract 2011

3. String and array ( both numeric and string) are more important.

4. sir Any Guess for Computer Science 2011 of isc

5. String class and 2 d numeric array related programs.

6. give any sample viva questions

7. can u suggest some similar prgrams please??

8. Viva questions mainly depends on the practical program. Questions may be from the classes used in the program. Suppose you have used StringTokenizer class in your program, the external may ask you about the overloaded versions of the constructors of the same class and the differences.
Questions may be from throws clause used in program.
Difference between IOException and Exception class. What would happen if we use ‘throws Exception’ instead of ‘throws IOException’.

In practical examination programs sorting and searching would be required. Study the differences between bubble sort and selection sort. In my experience I have seen that most of the students do not use break statement in bubble sort. If we do not use break in bubble sort, output will be alright but it is a must to use break in bubble sort. The examiner may ask the reason of using break in bubble sort.
For searching which one better searching technique between linear search and binary search and why? There are some preconditions for binary search, The examiner may ask the preconditions.

9. In my blog there are so many programs of different types. Please go through the blog.

10. sir, i'll be appearing for my isc computer practical examination scheduled for 25th feb 2011. i'll be highly grateful to you if you could suggest a few programs related to the same as soon as possible.

12. sir , in 2D array programs do we need to pay heed to the input format in the question paper....or can Accept the 2D array in any way we like...following the input format means It makes the program way way longer!!

13. I think you asking about whether to use BufferedReader object to enter values in 2 d array or simply passing the values to function as argument. If it is so, it is better to use BufferedReader object. If you are passing values as function argument, it creates trouble for the actual user who will execute your program. BlueJ is not the only editor for Java. It is used only in school level. In future if you work on Java you have to work on other editors and in those editors there is no short cut method like BlueJ editor to pass values directly to functions. So it is always better to be accustomed with the actual style of entering values, specially for ISC students.

1. sir i am appearing for 2012 computer science practical paper(isc) could you please suggest programs which are likely to come!! plz sir

2. Please follow the previous year papers and similar programs are expected.

3. is this year sorting of 2d array very important

4. Not that much important

14. Sir,
i am from dehradun an i want to know where can i get sample practical paper questions and the solution of ISC 2005 practical Q3//the //combinations program

15. sir m getting confused.. regarding my comp practical.. its on 25th.. you said
String class and 2 d numeric array related programs.
can you specify some of them??
n give the solved programme of that??

16. You must be in relaxed mood just before the examination. You go through the solved programs of previous years posted in this blog and best of luck.

17. Regarding ISC 2005 practical paper, check my post on February 22, 2011

18. nIC blog sir and very helpful

19. sir anagram ka program ??

20. thanks for all detail............sir.

21. Posted in ISC 2005 Computer practical examination.

22. program 3 doesn't work.

23. sir in every practical paper is it requisite to make programs by using functions or simply using "BufferedReader" class?sir wat is "STRING TOKENIZER"?

24. You can use any one, either BufferedReader or function if not specified. StringTokenizer is a class of java.util package

25. I am sure that you have compiled the program in your computer. Now copy the program from your computer and paste here with your input value and the output you received.

26. Sir, can u plz hlp me wid dis program...

Design a class convert which accepts any positive Decimal integer and a base between 2 and 16 and convert the Decimal Integer number into that base number system.
Details:
class: convert
data members: N-store any +ve int no.
b-to store the base
member functions:
convert()://constructor
void Getans(int x,int y)//to convert x into base y using RECURSIVE TECHNIQUE.

27. Please check my post on 15 September.

28. This is shoerter and works equally good:
public void money(int m)
{
int ctr,n=m,i=0 ;

int a[]= {1000,500,100,50,20,10,5,2,1};

while (n != 0)
{

ctr=n/a[i];
n=n%a[i];
if (ctr != 0)
System.out.println("No. of notes of "+ a[i] + " : " + ctr );
i++;

}
}

29. write a program to input natural number less than 1000 and display it in words

30. Please check my post on 12 November 2011.

31. Sir please post a program to find the total number of days between two dates

32. Please check my post on 15th November 2011.

33. There are 8 kaprekar numbers between 1 and 1000 as you have mentioned but you missed out to put 703

34. sir i want to take tution from you, how can i contact you??

1. Normally I do not take private tuition. If you have any problem, utilize this site, I am here to help.

35. sir what are the expected practical programs for isc 2012 practicals??

1. Please go through the ISC practical papers starting from 2005 to 2011, posted in this site. Programs in 2012 will be similar to those programs.

36. SIR WHAT IS THE Difference between IOException and Exception class. What would happen if we use ‘throws Exception’ instead of ‘throws IOException’ SIR PLZZZZZZ REPLY MY PRACTCAL IS ON 24TH OF FEB
AND ALSO TELL ME :
WHY it is a must to use break in bubble sort? WHY DO WE USE BREAK IN BUBBLE SORT.

37. Exception is an abstract class and super class of all Exception related classes including IOException class. Actually writing throws IOException is not required, we can write throws Exception and normally it is written but in your ICSE or ISC books and some of the school teachers normally write 'throws IOException'.

Main difference between bubble sort and selection sort is that in bubble sort not a single unnecessary iteration is allowed when the elements become sorted. To terminate the iteration break is a must in bubble sort.

38. For searching which one better searching technique between linear search and binary search and why? There are some preconditions for binary search, The examiner may ask the preconditions.

1. Linear search is better than binary search for number of reasons:

The elements must be in sorted order for binary search which is not required for linear search.
Binary search can be applied on array while linear search can be carried out in array, linked list etc.
Linear search can perform both unique value search as well as category-wise search but binary search can perform only unique value search.

The preconditions of binary search:

Elements must be in sorted order.
Middle location of the array can be accessed directly.

39. SIR WE ALL ARE VERY THANKFUL TO YOU AND RECEIVING GERAT HELP FROM U ON BEHALF OF ALL SITE LINKERS I THANK U FOR UR HELP

40. sir in theory exam why it is necessary to make programs using function

1. In java you can not do any program without using function.

2. hehe what a stupid question....

41. sir, ur programs are really helpful for ne kind of practical exams be it isc or school level.....
thank u sir....

hrishagni

42. A very very Good website sir.

44. sir can you pls suggest some ques for the viva for dis year...

1. Already posted. Search it in this site.

45. Sir, plz can u tell me function the line while(st.hasMoreTokens())???

1. Prototype of the function is 'boolean hasMoreTokens()'. This is a function of StringTokenizer which returns true is there is any token in the StringTokenizer class object otherwise returns false.

46. Thnks Sir.. for ur help ..i got my answer