Search This Blog

Loading...

Wednesday, February 23, 2011

ISC 2005 Computer practical solved paper

Question 1.


Write a program which takes a string (maximum 80 characters terminated by a full stop. The words in this string are assumed to be separated by one or more blanks.
Arrange the words of the input string in descending order of their lenghts. Same length words should be sorted alphabetically. Each word must start with an uppercase letter and the sentence should be terminated by a full stop.

Test your program for the following data and some random data.

SAMPLE DATA:
      INPUT:
      "This is human resource department."
    
     OUTPUT:
      Department Resource Human This Is. 

     INPUT:
      "To handle yourself use your head and to handle others use your heart."

     OUTPUT:
      Yourself Handle Handle Others Heart Head Your Your And Use Use To To.


Codes of the program

import java.io.*;
 import java.util.*;
 class Program1
 {
  String str,str2;
  StringTokenizer stk;
  String sr[];
  int i,j,x;
  int flag;
  BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  public void takeString()throws Exception
  {
  char ch;
   while(true)
   {
   System.out.println("\nEnter the sentence:");
   str=br.readLine().trim();
   if(str.length() >80)
   {
    System.out.println("\nString exceeds 80 characters.");
    continue;
    }
    if(str.charAt(str.length()-1)!='.')
   {
  
    System.out.println("\nString must terminate with full stop.");
    continue;
    }
   else
   break;
   }
   str=str.substring(0,str.length()-1);
   str2="";
   x=str.length();
   flag=0;
   for(i=0;i< x;i++)
   {
   ch=str.charAt(i);
   if(i==0)
   str2=str2+(char)(ch-32);
   else if(ch==' ')
   {
   flag=1;
   str2=str2+ch;
   }
   else if(flag==1)
     {
      flag=0;
      str2=str2+(char)(ch-32);
     }
     else
     str2=str2+ch;
     }
     str=str2;
   stk=new StringTokenizer(str);
   x=stk.countTokens();
   sr=new String[x];
   x=0;
   while(stk.hasMoreTokens())
   {
    str2=stk.nextToken().trim();
    sr[x++]=str2;
   }
   display();
  }
  private void display()
  {
   for(i=0;i< x-1;i++)
   {
    for(j=i+1;j< x;j++)
    {
    if(sr[i].length()< sr[j].length())
    {
     str2=sr[i];
     sr[i]=sr[j];
     sr[j]=str2;
     }
     }
     }
     for(i=0;i< x;i++)
     {
     if(i!=x-1)
      System.out.print(sr[i]+" ");
      else
      System.out.print(sr[i]);
      }
      System.out.print(".");
     }
     public static void main(String args[])throws Exception
     {
      Program1 ob=new Program1();
      ob.takeString();
      }
      }

Question 2.
A wondrous square is an n by n grid which fulfils the following conditions:
    (i) It contains integers from 1 to n2, where each integer appears only once.
    (ii) The sum of integers in any row or column must add up to 0.5 * n * (n2 + 1).

For example the following grid is a wondrous square where the sum of each row or column is 65 when n = 5 :

 17
24
 2
 8
 15
 23
 5
 7
 14
 16
 4
 6
13 
 20
 22
 10
 12
 19
 21
 3
 11
 18
 25
 2
 9

Write a program to read n (2 < = n < = 10) and the values stored in these n by n cells and output if the grid represents a wondrous square or not.
Also output all the prime numbers in the grid along with their row index and column index as shown in the output. A natural number is said to be prime if it has exactly two divisors. E.g. 2, 3, 5, 7, 11,.......
The first element of the given grid i.e. 17 is stored at row index 0 and column index 0 and the next element in the row i.e. 24 is stored at row index 0 and column index 1.

Test your program for the following data and some random data.

SAMPLE DATA:
      INPUT :        N = 4
                            

 16
 15
 1
 2
 6
 4
 10
 14
 9
 8
 12
 5
 3
 7
 11
 13

OUTPUT:
YES IT REPRESENTS A WONDROUS SQUARE.

 PRIME  
  ROW INDEX 
  COLUMN INDEX
 2
 0
 3
 3
 3
 0
 5
 2
 3
 7
 3
 1
11
3
2
13
3
3


import java.io.*;
  class Program1
 {
 int arr[][],arr1[];;
  int n,i,j,x=0,r,c;
  int flag;
  BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  public void take()throws Exception
  {
   System.out.println("\nEnter the size of array(row and column same):");
   n=Integer.parseInt(br.readLine().trim());
   arr=new int[n][n];
   arr1=new int[2*n];
   for(i=0;i< n;i++)
   {
   for(j=0;j< n;j++)
   {
     System.out.println("\nEnter the value:");
     arr[i][j]=Integer.parseInt(br.readLine());
     }
     }
   System.out.println("\nThe matrix is\n"); 
     for(i=0;i< n;i++)
     {
     r=0;
     c=0;
      for(j=0;j< n;j++)
      {
      System.out.print(arr[i][j]+" ");
       r=r+arr[i][j];
       c=c+arr[j][i];
       }
        System.out.println();
       arr1[x]=r;
       arr1[x+n-1]=c;
       x++;
       }
       for(i=0;i< x;i++)
       {
        if(arr1[i]!= 0.5 * n * (n*n + 1))
        break;
        }
        if(i==x)
        System.out.println("YES IT REPRESENTS A WONDROUS SQUARE.");
        else
        System.out.println("IT IS NOT A WONDROUS SQUARE.");
        System.out.println("PRIME  ROW  COLUMN");
        for(i=0;i< n;i++)
        {
         for(j=0;j< n;j++)
         {
         if(prime(arr[i][j]))
         System.out.println(arr[i][j]+ "   "+i+ "   "+j);
        }
        }
        }
        private boolean prime(int no)
        {
         int index;
         for(index=2;index< no;index++)
         {
          if(no%index==0)
          break;
         }
         if(index==no)
         return true;
         else
         return false;
        }
     public static void main(String args[])throws Exception
     {
      Program1 ob=new Program1();
      ob.take();
      }
      }


Question 3.
We would like to generate all possible anagrams of a word. For example if the given word is 'TOP', there will be 6 possible anagrams:
       TOP
       TPO
       OPT 
       OTP
       PTO
       POT

An anagram must be printed only once. You may output the anagrams in any order. Also output the total number of anagrams. You assume that the number of letter, n, in the word will be 7 at most, i.e. n<= 7
Test your program for the given data and some random data.

SAMPLE DATA:
     INPUT:
                       TO

OUTPUT:
                     TO
                     OT
Total number of anagrams = 2

INPUT :
                     LEAN
OUTPUT:
                     LEAN
                     LENA
                     LAEN
                     LANE
                     LNEA
                     LNAE
                     EALN
                     EANL
                     ELAN
                     ELNA
                     ENLA
                     ENAL
                     ALNE
                     ALEN
                     ANLE
                     ANEL
                     AENL
                     NLEA
                     NLAE
                     NELA
                     NEAL
                     NALE
                     NAEL
Total number of anagrams = 24


Codes of the program

import java.io.*;
 public class Anagrams
 {
String str;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int counter=0;
public void take()throws Exception
 {
   System.out.println("\nEnter the word:");
   str=br.readLine();
   show("", str);
   System.out.println(“Total number of anagrams =”+counter);
 }
   public void show(String s, String str)
  {
      if(str.length()< = 1)
     {
       counter++;
       System.out.println(s+str);
     }
    else
     {
        for(int i = 0; i< str.length(); i++)
       {
          String str1 = str.substring(i, i + 1);
          String str2 = str.substring(0, i);
          String str3 = str.substring(i + 1);
          show(s + str1, str2 + str3);
        }
     }
   }
public static void main(String args[])throws Exception
{
 Anagrams ob=new Anagrams();
ob.take();
}
}

 Related Posts: ISC Computer Practical Programs - 2006
ISC 2007 Computer Practical Paper
ISC Computer Practical Paper - 2008
ISC 2010 Computer Practical

16 comments:

  1. any last minute suggestions...??

    ReplyDelete
  2. Be relaxed and go through the logic of the practical paper programs of previous years. This will help you to solve any program.

    ReplyDelete
  3. thnks a lot for encouragement sir..

    ReplyDelete
  4. Sir....could u post the 2009 paper 2..thanx 4r ur help...

    ReplyDelete
  5. I think the programs of 2009 are posted as individual programs. Search those programs in my site.

    ReplyDelete
  6. sir please post the technical analysis of anagram of word program please sir............

    ReplyDelete
  7. sir coulnt find it will you lease give the link

    ReplyDelete
  8. Please specify the program, I 'll solve it.

    ReplyDelete
  9. is show(s+str) is used in place of system.out.println?

    ReplyDelete
  10. sir plz help me with function parsing..........

    ReplyDelete
  11. sir could you help me in doing a wonderous square

    ReplyDelete
  12. Good easy logic for the anagram program..thanks...

    ReplyDelete

CHECK HERE FOR PREVIOUS POSTS

Google+ Followers

Subscribe via email

Enter your email address:

Delivered by FeedBurner