Full Range

Call me (USA Free)

Saturday 14 February 2015

2010 ISC COMPUTER SCIENCE PRACTICAL SOLVED

12 comments

Question 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.*;
public class Denomination
{
    public static void main(String args[])throws Exception
     {
         BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
         System.out.print("Enter the amount:");
         int amt=Integer.parseInt(stdin.readLine());
         String s=""+amt;
         int l=s.length();
         if(l>5)
           System.out.println("INVALID AMOUNT");
           else
           {
               int n=amt;
               int rev=0,total=0,totaln=0,div;
               String word[]={"ZERO","ONE","TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE"};
               int notes[]={1000,500,100,50,20,10,5,2,1};
               while(n>0) //reverses the number
               {
                   rev=(rev*10)+(n%10);
                   n=n/10;
                }
                while(rev>0) //to print the number in words
                {
                    System.out.print(word[rev%10]+" ");
                    rev=rev/10;
                }
               System.out.println();
                System.out.println("DENOMINATION:");
                for(int i=0;i<9;i++) //to display denomination
                 {
                     div=amt/notes[i];
                     amt=amt%notes[i];
                     if(div>0)
                      {
                        System.out.println(notes[i]+"\tX\t"+div+"\t=\t"+(notes[i]*div));
                        total+=notes[i]*div;
                        totaln+=div;
                    }
                }
                 System.out.println("TOTAL="+total);
                  System.out.println("TOTAL NUMBER OF NOTES="+totaln);
          }
    }
 }
     
  1. Question 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.*;
public class Kaprekar 
{
    public static void main(String args[])throws Exception
     {
         BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
         System.out.print("Enter the lower limit:");
         int p=Integer.parseInt(stdin.readLine());
         System.out.print("Enter the upper limit:");
         int q=Integer.parseInt(stdin.readLine());
         if(q<p)
           System.out.println("INVALID INPUT");
           else
            {
                int count=0;
                System.out.println("THE KAPREKAR NUMBERS ARE:-");
                for(int i=p;i<=q;i++) //checking between the limits
                  {
                      String s=""+i;
                      int d=s.length();
                      int sq=i*i;
                      int rd=(int)(sq%(Math.pow(10,d))); //finding right-hand piece
                      int ld=(int)(sq/(Math.pow(10,d))); //finding left-hand piece
                      if(i==(rd+ld))
                       {
                           if(count==0)
                             System.out.print(i);
                             else
                              System.out.print(","+i);
                               count++;
                       }
                    }
                    System.out.println();
                     System.out.println("FREQUENCY OF KAPREKAR NUMBERS IS:"+count);
           }
    }
}

Question 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.

Example 1:

INPUT:
Enter number of sentences:
1
Enter sentences:
TO BE OR NOT TO BE.
OUTPUT:
Total number of words: 6
       WORD        FREQUENCY
        OR              1
        NOT             1
        TO              2
        BE              2
        


Example 2:

INPUT: Enter number of sentences:
3
Enter sentences:
THIS IS A STRING PROGRAM. IS THIS EASY? YES, IT IS.
  1. OUTPUT:
    Total number of words: 11
           WORD        FREQUENCY
            A              1
            STRING         1
            PROGRAM        1
            EASY           1
            YES            1
            IT             1
            THIS           2
            IS             3
            
    import java.io.*;
    public class FrequencyWord
    {
      public static void main(String args[])throws Exception
      {
      BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
      System.out.println("Enter the number of sentences:");
      int n=Integer.parseInt(stdin.readLine());
      if(n<1||n>3)
       System.out.println("INVALID INPUT");
        else
         {
            System.out.println("Enter the paragraph");
            String s=stdin.readLine();
            char ch;
            String word[]=new String[30];
            int v=0,count=0;
            for(int i=0;i<s.length();i++) //extract each word to array
            {
                ch=s.charAt(i);
                if(ch==' '||ch=='.'||ch=='?') 
                {
                    word[count]=s.substring(v,i);
                     v=i+1;
                    count++;
                }
            }
            int freq[]=new int[count];
           System.out.println("Total number of words:"+count);
           
           for(int j=0;j<count;j++)//counting frequency of each word
             {
                 freq[j]=0;
                 for(int k=0;k<count;k++)
                 {
                  if(word[j].equals(word[k]))
                  {
                   freq[j]+=1;
                  }
                }
            }
            
            String word1[]=new String[count];
            int freq1[]=new int[count];
            int count1=0,temp;
            String temp1;
            for(int i=0;i<count-1;i++)
              {
                for(int m=i+1;m<count;m++)
                 {
                     if(word[i].equals(word[m]))
                      freq[m]=0;
                    }
             }
             
              for(int m=0;m<count;m++)
               {
                   if(freq[m]!=0)
                    {
                      word1[count1]=word[m];
                      freq1[count1]=freq[m];
                      count1++;
                    }
                }
                for(int i=0;i<count1;i++)
                 {
                     for(int m=0;m<count1-i-1;m++)
                      {
                          if(freq1[m]>freq1[m+1])
                           {
                             temp=freq1[m+1];
                             freq1[m+1]=freq1[m];
                             freq1[m]=temp;
                             temp1=word1[m+1];
                             word1[m+1]=word1[m];
                            word1[m]=temp1;
                          }
                    }
                }
               System.out.println("WORD\tFREQUENCY");
                for(int i=0;i<count1;i++)
                 {
                  System.out.println(word1[i]+"\t"+freq1[i]);
                }
            }
        }
    }

If You Enjoyed This, Take 5 Seconds To Share It

12 comments:

  1. thanks a lot u saved me from my comp sir..............

    ReplyDelete
  2. MC BC beta maar maar ke tera keema bana dubg madar chood

    ReplyDelete
  3. Madar Chios Make laude Saale teri Gand maar lunga

    ReplyDelete
  4. Tumi amar bokachoda.darao magi k pathachi tomar chuse chuse mal ber kore tomar ma bou bon er mukhe debe.ar tomar dhon khule niye asbe.dudh tepa beria jbe

    ReplyDelete
  5. Thank you. All programs are compiled.No errors

    ReplyDelete
  6. Program 2 of kaprekar number is wrong.their should be d/2 when the square of number is divisible by 2.

    ReplyDelete
  7. If condition is wrong 😑😑

    ReplyDelete