Tuesday, 26 January 2016

ISC Computer Science Theory 2015 Part III (Solved)

Here goes the Group B questions on core Java language. I am sure you know you need to attempt any two questions . Flowcharts , algorithms nothing is required you just have to write the program and that is it. So let's start .

Question 8  :
A class Admission contains the admission numbers of 100 students . Some of the data members / member functions are given below :

Class Name                                                                                                       Admission 

Data member/Instance variable                                      

Adno[] :                                                           Integer array to store admission numbers

Member Functions/Methods :

Admission()               :                                  Constructor to initialize array elements
void fillArray()         :                      to accept elements of array in descending order
int binSearch(int l , int u , int v) : to search for particular admission number                                                                          (v) using binary search and recursive                                                                                      techniques and returns 1 if found otherwise                                                                        returns -1
Specify the class Admission giving details of constructor , fillArray() and binSearch(int,int,int). Define a main function to create an object and call functions accordingly to accomplish the task.


Sol :

import java.util.*;

public class Admission
{
   
    int Adno[] = new int [100];
    Admission()
   {}
   void fillArray()
   {
    Scanner s = new Scanner(System.in);
    System.out.println("enter elements");
    for (int  i = 0 ; i <100 ; i++)
    Adno[i]= s.nextInt();
    }
  
  int binSearch(int l,int u, int v)
  {
     int mid = (l+u)/2 ; 
     if(Adno[mid] == v)
        
        return 1;
     else if(l>u)
        return -1;
      else if (Adno[mid]>v)
        return binSearch(l,mid-1,v);
     else 
         return binSearch(mid+1, u , v);
   }

public static void main(String args[])
 {
    Admission obj = new Admission();
   obj.fillArray();
  System.out.println("Enter value to be searched :");
 Scanner s = new Scanner(System.in);
int v = s.nextInt();
int p = obj.binSearch(0,obj.Adno.length-1,v);
if(p==-1)
System.out.println("Object not found!");
else
System.out.println("Object found");
 }
}

Please note that the above question asks for implementing binary search using recursive technique . If you do not follow this instruction you will be penalized . Otherwise a simple program to write . 

Question 10 :

A class Merger concatenates two positive integers that are greater than 0 and produces a new merged integer.
Example : if the first number is 23 and second is 764 , the new number is 23764.

Some of the members of the class are given below 

CLASS                                                                                                Merger
Data Members/ Instance Variables :                                               

n1                                                         : long integer to store first number 
n2                                                          : long integer to store second number 
mergNum                                            :  long integer to store merged number 

Member Functions :

Merger()                                              : Constructor to initialize data members 
void readnum()                                   : Function to accept values of numbers n1 and n2 
void JoinNum()                                   : To concatenate numbers n1 and n2 to store it in                                                                                  mergNum
void show()                                          : To display the original numbers and merged number with                                                                  appropriate messages .   

Specify the class Merger , giving details of constructor , void readNum() , void JoinNum() and void show() . Define main () function to create an object and call the functions accordingly to enable the task . 

Sol :

import java.util.*;

public class Merger
{
  long n1 , n2 , mergNum;
  Merger(){}
  void readNum()
  {
    Scanner s = new Scanner(System.in);
    System.out.println("Enter First Number:");
    n1 = s.nextLong();
    System.out.println("Enter Second Number");
    n2 = s.nextLong();
  }
  
  void JoinNum()
  {
    if(n1>0 && n2>0)
  {
    String s1 = Long.toString(n1);
    String s2 = Long.toString(n2);
    String s3 = s1 + s2;
    mergNum = Long.valueOf(s3);
  }

  else 
          System.out.println("One or both the numbers are 0 or less than that , concatenation                                                     not possible !");

// It is better to use this if-else loop , since in the question it is mentioned that the class concatenates the string only if it finds out that the numbers are greater than 0 . 
    
  }
  
  void show()
  {
    System.out.println("First Number : "+n1);
    System.out.println("Second Number : "+n2);
    System.out.println("Merged Number : "+mergNum);
    
  }
  
  public static void main(String[] args)
  {
    Merger obj = new Merger();
    obj.readNum();
    obj.JoinNum();
    obj.show();
    
  }
}

Question 10 :

A class TheString accepts a string of a maximum 100 characters with only a blank space between the words . 
Some of the members of the class are given below 
 
Class Name     :                                                                       TheString
Data Member/Instance Variables : 
str                                                     : To store the string 
len                                                     :  integer to store length of string 
wordcount                                        :  integer to store number of words 
cons                                                   : integer to store number of consonants 

Member Functions / Methods 

TheString()                                      : default constructor to initialize data members 
TheString( String ds)                      : parameterized constructor to assign str = ds
void countFreq()                              : to count the number of words and number of consonants                                                                  and store them in wordcount and cons respectively.
void Display()                                   : to display the original string , along with number of words                                                                and number of consonants 

Specify the class TheString giving the details of constructor , countFreq()  , Display() . Define the main function . create an object of the class and call the member functions accordingly to enable the task . 

import java.util.*

public class TheString
{
 String str;
  int len, wordcount, cons;
  TheString(){}
  TheString(String ds)
  {
    str = ds;
    len = str.length();
  }
  void countFreq()
  {
    char c ;
    String str1 = str.toLowerCase(); //lower case conversion simplifies the string handling to find the                                                         consonants. You can change to uppercase also . But semantics will                                                          change a bit to count the consonants.
    for (int i = 0 ; i<len; i++)
    {
      c = str1.charAt(i);
      if(c==32 || i==len-1) // 32 denotes space, || i=len-1 is used to mark the end of string input 
        wordcount++;
      if(c!='a' && c!='e' && c!='i' && c!='o' && c!='u' && c!=32)  //if c!32 is not mentioned blank                                                                                                     spaces will be counted as consonants
      cons++;
     
    }
  }
 
 
 
  void Display()
  {
    System.out.println("Original String : "+str);
    System.out.println("Number of words : "+wordcount);
    System.out.println("Number of consonants : "+cons);
   
  }
 
  public static void main(String[] args)
  {
    TheString obj = new TheString("Today is Republic Day.");
    obj.countFreq();
    obj.Display();
   
  }
}

Synopsis 
Nothing much needs to be mentioned . The first two questions are pretty straight forward and should not consume much time to write . The third one has two points to keep in mind :
 1) To count the number of words , you have to consider the spaces . But what about the sentence that does not end with a space ? So you have to check where the string ends too otherwise you will end up getting a word less than the actual number of words in original string.

2) We usually check if a character is a vowel to count the consonants , but here the string contains spaces , so if we do not mention it in the condition checking not to consider the space as a consonant , the number of spaces present also gets added to the number of consonants. 

So in my opinion in the examination hall you might not get adequate time to think on these points and also you cannot avail yourself of the compiler to find out where you have gone wrong  so it is better to avoid the third program or Question no 10. 

Tuesday, 12 January 2016

ISC Computer Science Class XII 2015 Theory Part II (Solved)

Question 4
a) Given Boolean Function F(A,B,C,D) = π(0,1,2,3,5,7,8,9,10,11)
        i) Reduce the above expression using 4-variable Karnaugh Map , showing the various groups (i.e. octal , quad and pair)                                                                              [4]
       ii) Draw the logic gate diagram for the reduced expression . Assume that the variables and the complements are available as inputs.                                                             [1]

Sol i)


From the above Karnaugh Map we get a octet (M0M1M2M3M8M9M10M11 ) that gives reduced                                                                                                                                          expression : B
                                The quad (M1M3M5M7)  gives expression :A+D'
Therefore, the reduced expression for the Boolean Function is B.(A+D')

ii)

b) Given Boolean Function
                P(A,B,C,D)= ABC'D'+ A'BC'D' + A'BC'D + ABC'D+A'BCD + ABCD
      i) Reduce the above expression using 4-variable Karnaugh Map , showing the various groups (i.e. octal , quad and pair)                                                                              [4]
       ii) Draw the logic gate diagram for the reduced expression . Assume that the variables and the complements are available as inputs.                                                                  [1]

Sol i)

    From the first quad ( m4m5m12m13)  we get  :     BC'
    From the second quad (m5m7m13m15)we get : BD
   Therefore the reduced expression of the above Boolean Sum of Products expression is : BC'+BD

ii)


Question 5. 
A person is allowed to travel on a reserved coach on train , if he/she satisfies the criteria below

  • Person has a valid reservation ticket and a valid ID proof               OR
  • The person does not have a valid reservation ticket , but holds a valid pass issued by Railway department with a valid ID proof.                                                     OR
  • The person is disabled and holds a valid pass issued by the Railway department along with a valid ID proof.
The inputs are :
Input

R
Person has valid reservation ticket
P
Person holds a valid pass from Railway Department
D
Person has a valid ID proof
H
Person is disabled
 (In all the above cases 1 indicates YES and 0 indicates NO.)
Output : T - Denotes allowed to travel. 1 indicates YES and 0 indicates NO

a) Draw the truth table for the inputs and outputs given . Write the POS expression for T(R,P,D,H). [5]

b) Reduce T(R,P,D,H) using Karnaugh map. Draw the logic gate diagram for the reduced POS using only NOR gates
assuming that the variables and their complements are allowed as inputs.           [5]

Sol, 
a)

R
P
D
H
T
0
0
0
0
0
0
0
0
1
0
0
0
1
0
0
0
0
1
1
0
0
1
0
0
0
0
1
0
1
0
0
1
1
0
1
0
1
1
1
1
1
0
0
0
0
1
0
0
1
0
1
0
1
0
1
1
0
1
1
1
1
1
0
0
0
1
1
0
1
0
1
1
1
0
1
1
1
1
1
1

The POS expression for the above truth table is : 
                           T(R,P,D,H) = π(0,1,2,3,4,5,8,9,12,13)


b)  



From the quad (M0M1M2M3)  : R+P
From the octal (M0M1M4M5M8M9M12M13) : D

Therefore , the reduced POS of T(R,P,D,H) = (R+P).D




Question 6.

a) Draw the truth table and logic diagram for an octal to binary encoder.                                  [4]

Sol.
Octal No.
                            Truth Table
       Output

   D0
   D1
   D2
   D3
  D4
   D5
   D6
   D7
   a
   b
   c
   0
   1
   0
   0
   0
   0
   0
   0
   0
   0
   0
   0
   1
   0
   1
   0
   0
   0
   0
   0
   0
   0
   0
   1
   2
   0
   0
   1
   0
   0
   0
   0
   0
   0
   1
   0
   3
   0
   0
   0
   1
   0
   0
   0
   0
   0
   1
   1
   4
   0
   0
   0
   0
   1
   0
   0
   0
   1
   0
   0
   5
   0
   0
   0
   0
   0
   1
   0
   0
   1
   0
   1
   6
   0
   0
   0
   0
   0
   0
   1
   0
   1
   1
   0
   7
   0
   0
   0
   0
   0
   0
   0
   1
   1
    1
   1


 b) What is Multiplexer? State an application of Multiplexer. Also, draw the logic diagram of 4:1 Multiplexer. [4]

Sol. 
A multiplexer is a combinational circuit that selects binary information from one or many lines and directs it to a single output line.
It is used for bandwidth utilization so finds it's application in data transmission , routing of signal , telephone exchange.
The Logic circuit is as follows;

c) Verify the following expression using Boolean Laws. Also, mention the laws used at each step of simplification.
                         X.Y.Z+X.Y'.Z+X.Y.Z' = X.(Y+Z)                                                       [2]

Sol.
 L.H.S.= X.Y.Z+X.Y'.Z+X.Y.Z'
           =X.Y.Z+X.Y.Z'+X.Y'.Z
           =X.Y.(Z+Z') + X.Y'.Z
           = X.Y+ X.Y'.Z            (Since by Complementary Law Z+Z'=1)
           =X.(Y+Y'Z)
           =X.(Y+Y')(Y+Z)         (Since by Distributive Law A+B.C=(A+B).(A+C))
           =X.(Y+Z)                   (Since by Complementary Law Y+Y'=1)
           = R.H.S.


Question 7:

a) Derive a Boolean expression for the logic circuit given below and reduce the derived expression using Boolean Laws.         [3]



Sol.  
1. A'
2. B'
3. C'
4. A'.B'.C'
5 (A'.B'.C')'
6. (A'.B'.C')'.C
7. X =  (A'.B'.C')'.C+(A'.B'.C')'

(A'.B'.C')'.C+(A'.B'.C')'
=( A+B+C).C+(A+B+C)
= A.C+B.C+C.C+A+B+C
= A.C+B.C+C+A+B+C
=(A.C+A) +( B.C+ B) + C
=A+B+C

b) What are universal gates ? Construct a logic circuit using NAND gates only for expression          A.(B+C) .                                                                                                                 [4]

Sol. When any digital system can be implemented by a logic gate , the gate is said to be universal . Eg : NAND gates . 


c) Define Half Adders. Draw circuit diagram and truth table for a Half Adder .    [4]

Sol,
c)  Half Adder is an example of a simple functional digital circuit built from two logic gates . The half adder adds two one-bit binary numbers (A, B) .  The output is the sum of two bits (S) and the carry (C). The truth table of the half adder is as follows 



                            The logic diagram of half adder is given below,

[Note :  You are to solve any three questions from this part . As I have mentioned in a post earlier , it is better to attempt the two questions on Karnaugh Map . Question No 6 involves truth tables , diagrams that are quite time consuming . Question 4 is pretty straight as expected. Question 5 is easy, only you have to be patient while computing the truth table. Questions 7b and 7c are again nothing tricky . Attempt 7a step by step . Write the output for each gate on the diagram of your question paper and you are good to go .]