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]);
                }
            }
        }
    }

Read More

2014 ISC COMPUTER SCIENCE PRACTICAL SOLVED PAPER

1 comment
  1. Question 1

    A composite Magic number is a positive integer which is composite as well as a magic number. Composite number: A composite number is a number which has more than two factors. For example: 10 Factors are: 1,2,5,10 Magic number: A Magic number is a number in which the eventual sum of the digitd is equal to 1. For example: 28 = 2+8=10= 1+0=1 Accept two positive integers m and n, where m is less than n as user input. Display the number of composite magic integers that are in the range between m and n (both inclusive) and output them along with frequency, in the format specified below: 

    Example:
    Input: m=10
    n=100
    OUTPUT:
    The composite magic numbers are 10,28,46,55,64,82,91,100
    Frequency of composite magic numbers: 8

    Input: m=120
    n=90
    OUTPUT:
    Invalid input
import java.io.*;
public class CompositeMagicNumber
{
    public static void main(String args[])throws Exception
    {
        BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter the lower limit:");
        int m=Integer.parseInt(stdin.readLine());
        System.out.println("Enter the upper limit:");
        int n=Integer.parseInt(stdin.readLine());
        if(m<n)
        {
            int mag[]=new int[n];
            int count=0;
             for(int i=m;i<=n;i++) //checking for composite
             {
                 int flag=0;
                  for(int j=2;j<i;j++)
                   {
                       if(i%j==0)
                        {
                            flag=1;
                            break;
                        }
                    }
                    int num=i,sum=0;
                    while(num>0) //checking for magic number
                     {
                         sum=sum+(num%10);
                         num=num/10;
                          if(num<1&&sum>9)
                           {
                               num=sum;
                               sum=0;
                            }
                    }
                    if(flag==1&&sum==1)
                     {
                         mag[count]=i;
                         count++;
                     }
                    
              }
               if(count>0)
                {
                   System.out.println("THE COMPOSITE MAGIC NUMBERS ARE:");
                     for(int k=0;k<count-1;k++)
                      {
                        System.out.print(mag[k]+",");
                      }
                      System.out.print(mag[count-1]);
                       System.out.println();
                 }
                 System.out.println("FREQUENCY OF COMPOSITE MAGIC INTEGERS IS:"+count);
         }//closing of first if loop
          else
             System.out.println("INVALID INPUT");
    }
}

Question 2
Write a program to declare a square matrix A[][] of order MXM where M is an positive integer and represents row and column. M should be greater than 2 and less than 10.Accept the value of M from user. Display an appropriate message for invalid input.
Perform the following task:
a) Display the original matrix
b) Check if the given matrix is symmetric or not. If the element of the ith row and jth column is same as element of the jth row and ith column,.
c)Find the sum of the left and right diagonal of the matrix and display them

Example 1:
INPUT:
M=3
1 2 3
2 4 5
3 5 6
OUTPUT:
Original matrix
1 2 3
2 4 5
3 5 6
The given matrix is symmetric
Sum of the left diagonal=11
Sum of the right diagonal=10
Example 2:
INPUT: M=4
OUTPUT:
Original matrix:
7 8 9 2
4 5 6 3
8 5 3 1
7 6 4 2

The given matrix is not symmetric
Sum of the left diagonal=17
Sum of the right disgonal=20

Example 3:
INPUT: M=12
OUTPUT:
Matrix size is out of range

import java.io.*;
public class SymmetricMatrix
{
    public static void main(String args[])throws Exception
    {
        BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter the number of rows and columns:");
        int m=Integer.parseInt(stdin.readLine());
        if(m>2&&m<10)
         {
           int max[][]=new int[m][m];
           int flag=0;
           for(int i=0;i<m;i++)  //entering matrix elements
            {
                for(int j=0;j<m;j++)
                 {
                   max[i][j]=Integer.parseInt(stdin.readLine());  
                }
            }
           System.out.println("ORIGINAL MATRIX");
            for(int i=0;i<m;i++)  //displaying the original matrix
            {
              for(int j=0;j<m;j++)
                 {
                   System.out.print(max[i][j]+"\t");
                }
                System.out.println();
            }
            for(int i=0;i<m;i++)  //checking for symmetric matrix
            {
              for(int j=0;j<m;j++)
                 {
                     if(max[i][j]!=max[j][i])
                       {
                           flag=1;
                           break;
                        }
                    }
            }
            if(flag==0)
             System.out.println("THE GIVEN MATRIX IS SYMMETRIC");
            else
              System.out.println("THE GIVEN MATRIX IS NOT SYMMETRIC");
          int suml=0,sumr=0;
           for(int i=0;i<m;i++) //finding sum of left diagonal
             {
              suml+=max[i][i];
            }
            int j=m-1;
            for(int i=0;i<m;i++,j--)  //finding sum of right diagonal
             {
                 sumr+=max[i][j];
             }
             System.out.println( suml);
              System.out.println( sumr);
            }
        }
    }
             
              
              
            
            
            
Read More