Monday, December 7, 2015

Solved ISC 2011 Computer Application Theory Paper



Only the java program related questions are answered here.





Question 1.

a)       State the two absorption laws. Verify any one of them using truth table.

b)       Reduce the following expression :

F(A,B,C)= ∑(0,1,2,3,4,5,6,7)

Also find the complement of the reduced expression.

c)  Name the logic gate for the following circuit diagram and write its truth table.







d)       Using truth table, verify whether the following is true or false: (p →q) = (q’→p’)

e)       If A=1, B=0, C=1 and D=1 find its

i)  maxterm

ii)  minterm

[2 x 5 =10]

Question 2.

a)       How can we override a method in inheritance?

Ans: Overriding of method is possible only in inheritance. Overriding means when any method of a super class is re-defined in a sub class with same prototype means same name, return type and argument list. Any final method of a super class can’t be overridden in sub class.


b)       A square matrix A[m x m] is stored in the memory with each element requiring 2 bytes of storage. If the base address A[1][1] is 1098 and the address at A[4][5] is 1144, determine the order of the matrix A[mxm] when the matrix is stored column majorwise.


Ans: Address calculating formula of a matrix when the matrix is stored in column major order is : Base Address + w*(E2*L1+E1) where E1 is the effective index of 1st dimension, E2 is the effective index of 2nd dimension, L1 is the length of 1st dimension and L2 is the length of 2nd dimension.

As the matrix is a square one, L1=L2.
As per formula 1098 + 2 * (4 * L1 + 3) = 1144
   1098 + 8L1 + 6=1144
8L1=1144-1098-6
8L1=40
L1=5

So value of ‘m’ is 5



c)       What is Big O Notation?

Ans: Big O notation is a mechanism to measure time complexity of a program.



d)       What is an exception?

Ans: Any type of run time abnormality occurred during execution of a program is known as exception. Exception is an abstract class in java.lang package and this package has number of sub classes. 


e)       Convert the infix expression to its postfix form:

A+B*C-D/E

Ans: ABC*+DE/-  Read: For Details

[ 2 x 5 =10]

Question 3.

a)   The following is a part of some class. What will be the output of the function mymethod( ) when the value of counter is equal to 3? Show the dry run/ working.

void mymethod(int counter)

{

if(counter= =0) System.out.println(“ “);

else

{

System.out.println(“Hello “+ counter); mymethod(- -counter); System.out.println(“ “+ counter);

}

}                                                                                                                    [ 5]


Ans: Hello3
       Hello2
       Hello1
       0
       1
       2



b)       The following function is a part of some class which computes and returns the greatest common divisor of any two numbers. There are some places in the code marked by ?1?, ?2?, ?3?, ?4?, and ?5? which must be replaced by statement/expression so that the function works correctly.

int gcd(int a, int b)

{

int r; while(?1?)

{

r=?2?;

b=?3?;

a=?4?;

}

if(a==0)

return ?5?;

else

return -1;

}

i)                    What is the expression or statement at ?1?

ii)                  What is the expression or statement at ?2?

iii)                 What is the expression or statement at ?3?

iv)                 What is the expression or statement at ?4?

v)                  What is the expression or statement at ?5?

[ 1 x 5 = 5]

Ans:  
 i) a >0 or a!=0
ii) r=b%a
iii) b=a
iv) a=r
v) b
Part II

Answer seven questions in this Part, choosing three questions from Section A and two questions from Section B and two questions from Section C.



Section A
Answer any three questions from this Section

Question 4.

a)  State the principle of duality. Give the dual of the following:
(A’B)+(C.1)=(A’+C)(B+C)                                                                                   [ 3 ]

b)  Reduce the following Boolean expressions to their simplest forms:-

i) {(CD)’+A} + A+ C.D + A.B

ii) A.{B+C(A.B + A.C)’}                                                                                       [ 4]

c)  Verify using a truth table if:
(A B C)’ = A  B C                                                                      [ 3 ]





2





Question 5.

a)       Given F(P,Q,R,S)= Ï€(2,3,6,7,9,11,12,13,14,15)

Reduce the above expression using four variable K-map. Draw the logic gate diagram of the

reduced expression using NOR gates only.                                                                     [ 5]

b)       Given F(A,B,C,D)= A’B’C’D’ + A’B’C’D + AB’C’D’+ AB’C’D + A’BC’D’ +A’BCD’.

Reduce the above expression by using four variable K-map. Draw the logic gate diagram of the


reduced expression using NAND gates only.
[ 5]
Question 6.

a)
Show with the help of a logic diagram how a NAND gate is equivalent to an OR gate.
[ 3 ]
b)
Verify if the following is valid:


(A→B) ^ (A→C)= A→(B^C)
[ 3 ]
c)
What is a decoder? Draw the truth table and logic circuit diagram for a 2 to 4 decoder.
[ 4 ]
Question 7.

a)
What is a Full Adder? Draw the truth table for a Full Adder. Also derive SOP expression for the

Full Adder and draw its logic circuit.
[ 4 ]
b)
State how a decoder is different from a multiplexer. Also state one use of each.
[ 3 ]
c)
Convert the following cardinal expression into its canonical form and reduce it using Boolean

laws:   F(L,M,O,P) = Ï€(0,2,8,10)
[ 3 ]



Section B

Answer any 2 questions.

Each program should be written in such a way that it clearly depicts the logic of the problem. This can be achieved by using mnemonic names and comments in the program.

Question 8.

Input a sentence from the user and count the number of times, the words “an” and “and” are present in the sentence. Design a class Frequency using the description given below:

Class name
:
Frequency
Data Members


text
: stores the sentence
countand
: to store the frequency of the word and.
countan
: to store the frequency of the word an.
len
: stores the length of the string.


Member functions

Frequency()                                          : constructor to initialize the data variables.

void accept(String n)                             : to assign n to text where the value of the parameter should be

in lowercase.

void checkandfreq()                               : to count the frequency of and.

void checkanfreq()                                : to count the frequency of an.

void display()                                        : to display the frequency of “an” and “and” with suitable

messages.

Specify class Frequency giving details of the constructor(), void accept(String), void checkand freq() and void display(). Also define the main function to create an object and call methods accordingly to enable 
the task.


Ans: 

class Frequency
{
 String text;
 int countand, countan, len;
  Frequency()
 {
 text="";
 countand=0;
 countan=0;
 }

 void accept(String n)
 {
  text=n;
  len=text.length();
 }

 public void checkandfreq()
 {
  int i;
  String s1="";
  s1=text;
for(i=0;i< len;i++)
  {
   if(text.charAt(i)!=' ')
   s1=s1+text.charAt(i);
   else
   {
    if(s1.equals("and"))
    countand++;
    s1="";
   }
   }
    if(s1.equals("and"))
    countand++;
 }


 public void checkanfreq()
 {
  int i;
  String s1="";
  s1=text;
for(i=0;i< len;i++)
  {
   if(text.charAt(i)!=' ')
   s1=s1+text.charAt(i);
   else
   {
    if(s1.equals("an"))
    countan++;
    s1="";
   }
   }
    if(s1.equals("an"))
    countan++;
 }

 public void display()
 {
 System.out.println("Sentence = "+text);
 System.out.println("Word 'and' in the sentence:"+countand);
 System.out.println("Word 'an' in the sentence:"+countan);

 }
public static void main(String args[]) 
{
 Frequency one=new Frequency();
 one.accept("this is an example of an and and");
 one.checkandfreq();
  one.checkanfreq();
  one.display();
}

}

[ 10 ]

Question 9.

A class DeciOct has been defined to convert a decimal number into its equivalent octal number. Some of the members of the class are given below:

class name: DeciOct

n: stores the decimal number

oct: stores the equivalent octal number

DeciOct(): constructor to initialize the data members to 0

void getnum(int nn): assigns nn to n


void deci_oct():  calculates the octal equivalent of n and stores it in oct using the recursive technique

void show: displays the decimal number n
              calls the function deci_oct() and displays its octal equivalent

a) Specify the class DeciOct, giving details of the constructor(), void getnum(int), void deci_oct() and void show(). Also define a main function to create an object and call the functions 
accordingly to enable the task. [ 8 ]


b)  State any two disadvantages of using recursion. [ 2 ]




Ans:


import java.io.*;

class DeciOct
{
 int n,oct;


  DeciOct()
 {
 n=0;
 oct=0;
 }

 void getnum(int nn)
 {
  n=nn;
 }

 public void deci_oct()
 {
  if(n==0)
  return;
  oct=oct*10+n%8;
  n=n/8;
  deci_oct();
  }

 public void show()
 {
  System.out.println("Decimal value="+n);
 deci_oct();
 n=oct;
 oct=0;
 while(n >0)
 {
  oct=oct*10+n%10;
  n=n/10;
  }// reversing the number
 System.out.println("Octal equivalent = "+oct);


 }

public static void main(String args[]) throws Exception
{
int a;
 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
DeciOct one=new DeciOct();
 System.out.println("Enter the number:");
 a=Integer.parseInt(br.readLine());
 one.getnum(a);
 one.show();
}
}

b) Recursive function increases time complexity and space complexity of a program.

Question 10.

You are given a sequence of n integers, which are called pseudo arithmetic sequences ( sequences that are in arithmetic progression).

Sequence of n integers : 2, 5, 6, 8, 9, 12 We observe that 2 + 12 = 5 + 9 = 6 +8 = 14

The sum of the above sequence can be calculated as 14 x 3 = 42

For sequence containing an odd number of elements the rule is to double the middle element, for example 2, 5, 7, 9, 12

=2 +12 = 5 +9 = 7 +7 = 14

14 x 3 = 42 [ middle element = 7]

A class pseudoarithmetic determines whether a given sequence is pseudo-arithmetic sequence. The details of the class are given below:-







Class name
:
Pseudoarithmetic
Data members


n
:
to store the size of the sequence
a[ ]
:
integer array to store the sequence of numbers
ans, flag
:
to store the status
sum
:
to store the sum of sequence of numbers
r
:
to store the sum of 2 numbers
Member functions
:

Pseudoarithmetic( )
:
default constructor
void accept(int nn )
:
to assign nn to n and to create an integer array. Fill in the


elements of the array.
boolean check( )
:
return true if the sequence is a pseudo-arithmetic sequence


otherwise return false.

Specify the class Pseudoarithmetic, giving details of the constructor(), void accept(int) and Boolean check(). Also define the main function to create an object and call methods accordingly to enable the

task.
[ 10]

Ans: 

import java.io.*;


class Pseudoarithmetic
{
 int n, a[ ], sum, r;
 boolean ans, flag;
 BufferedReader br1=new BufferedReader(new InputStreamReader(System.in));

Pseudoarithmetic()
 {
 ans=true;
 flag=true;
 n=0;
 sum=0;
 r=0;
 }  
void accept(int nn ) throws Exception
{
 n=nn;
 a=new int[n];
 for(int i=0;i< n;i++)
 {
  System.out.print("\nNumber:");
  a[i]=Integer.parseInt(br1.readLine());
  }
 }
 boolean check( )
 {
 int i,j;
  i=0;
  j=n-1;
  r=a[i++]+a[j--];
  sum+=r;
  while(flag)
  {
   if(i >j)
   {
   flag=false;
   break;
   }
   else if(i==j)
   {
   flag=false;
  sum+=a[i]+a[j];
  break;
  }
   else if (r!=a[i]+a[j])
   break;
   sum+=a[i]+a[j];
   System.out.println(sum);
   i++;
   j--;
  }
  if(flag)
  ans=false;
  return ans;
  }

public static void main(String args[]) throws Exception
{
  int x;
  Pseudoarithmetic one=new Pseudoarithmetic();
  System.out.println("How many elements to store:");
  x=Integer.parseInt(one.br1.readLine());
  one.accept(x);
  System.out.println("The series is Pseudo Arithmetic:"+ one.check());
  System.out.println("Sum of the elements="+one.sum);
 }

}

Section C Answer any 2 questions.

Each program/algorithm should be written in such a way that it clearly depicts the logic of the problem step wise. This can also be achieved by using pseudo codes.

(Flowcharts are not required)

The programs must be written in Java.

The algorithm must be written in general standard form wherever required.


Question 11.

A super class Record has been defined to store the names and ranks of 50 students. Define a sub class Rank to find the highest rank along with the name. The details of both classes are given below:

Class name
:
Record
Data members


name[]
:
to store the names of students
rnk[]
:
to store the ranks of students
Member functions:


Record()
:
constructor to initialize data members
void readvalues()
:
to store names and ranks
void display()
:
displays the names and the corresponding ranks
class name
:
Rank
Data members


index
:
integer to store the index of the topmost rank
Member functions


Rank()
:
constructor to invoke the base class constructor and to


initialize index to 0.
void highest()
:
finds the index location of the topmost rank and stores


it in index without sorting the array








void display()                                        :           displays the name and ranks along with the name

having the topmost rank.

Specify the class Record giving details of the constructor(), void readvalues(), void display(). Using the concept of inheritance, specify the class Rank giving details of constructor(), void highest() and void display(). The main function and algorithm need not be written.


Ans:


import java.io.*;


class Record
{
 int i;
String name[];
int rnk[];
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

Record()
 {
 name=new String[50];
rnk=new int[50];
 }  
void readvalues( ) throws Exception
{

for(i=0;i< 50;i++)
{
System.out.print("\nName:");
name[i]=br.readLine();
System.out.print("\nRank:");
rnk[i]=Integer.parseInt(br.readLine());
}
}
void display()
{
System.out.println("Name wise ranks of all students.");
 for(i=0;i< 50;i++)
 System.out.println("Name:" + name[i] + " Rank="+rnk[i]);
}
}
 class  Rank extends Record
{
 int index;
Rank()
{
 super();
index=0;
}
void highest()
{
 for(int i=1;i< 50;i++)
{
 if (rnk[i]>rnk[index])
index=i;
}
}
void display()
{
 System.out.println("Name of highest rank student:" + name[index] + " Rank="+rnk[index]);
 super.display();
}
public static void main(String args[]) throws Exception
{

  Rank one=new Rank();
one.readvalues();
one.highest();
one.display();
 }

}



Question 12.

Stack is a kind of data structure which can store elements with the restriction that an element can be added or removed from the top only. The details of class Stack are given below:

Class name
:
Stack
st[]
:
the array to hold names.
size
:
the maximum capacity of the string array
top
:
the index of the topmost element of the stack
ctr
:
to count the number of elements of the stack
Member functions


Stack()
:
default constructor
Stack(int cap)
:
constructor to initialize size=cap and top=-1
void pushname(String n)
:
to push a name into the stack. If the stack is full, display


the message “overflow”.
String popname()
:
removes a name from the top of the stack and returns


it. If the stack is empty, display the message


“underflow”.
void display()
:
Display the elements of the stack.

a)       Specify class Stack giving details of the constructors(), void pushname(String n), String popname() and void display(). The main function and algorithm need not be written.

b)       Under what principle does the above entity work?



Ans:

class Stack
{
 int size,top,ctr;
String st[];

Stack()
 {
 size=0;
 top=-1;
 }
 Stack(int cap)
 {
  size=cap;
  top=-1;
  }

void pushname(String n )
{
 if(top==size)
 System.out.println("Stack Overflow...");
 else
 st[++top]=n;
 }
void popname( )
{
 if(top==-1)
 System.out.println("Stack Underflow...");
 else
 System.out.println("Deleted Name:"+st[top--]);
 }
 void display()
 {
 System.out.println("Names in the stack:");
  for(int i=top;i >=0;i--)
   System.out.println(st[i]);

  }

}


b) LIFO technique.

Question 13.

a) A linked list is formed from the objects of the class, class Node

{

int info; Node link;

}

Write an algorithm OR a method for deleting a node from a linked list. The method declaration is given below:

void deletenode(Node start)

b)       Distinguish between worst-case and best-case complexity of an algorithm.


Ans:

Algorithm

Step 1: start and x are two objects of the linked list Node. start holding the first node while x is holding the 2nd node
Step 2: Take the value of the node to be deleted and store in a variable n.
Step 3: Repeat the steps 4, 5 and 6 until x becomes null
Step 4: Compare n with x.info and if match is found go out of step 6
Step 5: Move x to the next location
Step 6: Move start to the next location
Step 7: If x is null then display 'node not found' otherwise set start.link=x.link and remove x


Method 

void deletenode (Node start)
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n;
Node x;
x=start.link
 System.out.print("\nEnter the value of the node to be deleted:");
n=Integer.parseInt(br.readLine());
while(x!=null)
{
 if(x.info==n)
break;
x=x.link;
start=start.link;
}
if(x==null)
 System.out.println("\nNode not found");
else
 start.link=x.link;
}

Best complexity is when the execution is minimum and worst complexity is when execution is maximum.



c)       Answer the following from the diagram of a Binary tree given below:


























i)                    Write the postorder tree traversal

Ans:BDGHFECA

ii)                   Name the leaves of the tree

Ans:  B D G H

iii)                 Height of the tree

Ans:4

iv)                 Root of the tree

Ans: A









































7

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner