Code is copied!

# CLASS 12 ISC - Java Question Paper 2016

### PART I

###### (Attempt all questions)

__Question 1__

#### (a) State Involution law and prove it with the help of a truth table.

#### Solution

#####
Involution law states that : X̄̄ = X

#### (b) Show that X ∨ ~ (Y ∧ X) is a tautology.

#### Solution

#### (c)
Find the dual of

YX + X’ + 1 = 1

#### Solution

#####
(c) Y.X+X'+1= 1

(Y + X) . (Y' )= 1

#### (d) Write the maxterm and minterm, when the inputs are A = 0, B = 1, C = 1 and D = 0.

#### Solution

#####
(d) A = 0, B = 1, C = 1, D = 0

Minterm = A' B C D'

Maxterm = A+ B' + C' +D

#### (e) Draw the logic circuit of a NAND gate using NOR gates only.

#### Solution

__Question 2__

#### (a)
Define the term fall through the condition with reference to switch () case.

#### Solution

##### (a) Fall through is prevented with a break keyword at the end of the matching body, which exits execution of the switch block, but this can cause bugs due to unintentional fall through if the programmer forgets to insert break statemen

#### (b)
Convert the following infix expression into postfix form:

A + B / C * (D/E * F)

#### Solution

#####
(b) A + B/C * (D/E * F)

= A + B/C * (DE/*F)

= A + B/C * (DE/F*)

= A + BC/ * DE/F*

= A + BC/DE/F**

= ABC/DE/F**+

#### (c) A matrix A[m] [n] is stored with each element requiring 4 bytes of storage. If the base address at A[1] [1] is 1500 and the address at A [4] [5] is 1608, determine the number of rows of the matrix when the matrix is stored in Column Major Wise.

#### Solution

#####
(c) A [m] [n]

i = 4, B = 1500

j = 5, w = 4

B [i][j] = 1608

#### (d)
From the class declaration given below, state the nature of the identifiers A, B, C and D:

class A extends B implements C, D

#### Solution

##### Class A is the superclass of B which in turn is the superclass of subclass C and D

#### (e) State one advantage and one disadvantage of using recursion over iteration.

#### Solution

#####
(e) In iteration, the statement is executed repeatedly using the same memory space which is allocated once.

In recursion, the statement is executed repeatedly by invoking the same function within itself and for each recursive call, a fresh memory is allocated. The recursive function runs slower as compared to iteration.

__Question 3__

The following function Check() is a part of some class. What will the function Check() return when the values of both ‘m’ and ‘n’ is equal to 5? Show the dry run/working.

#####
Check(5,5)

int Check (int m, int n) { if(n = = 1) return - m --; else return + + m + Check (m, -- n); }

#### Solution

#####
Check(5,5)

(Step-1) 6 + Check (6,4)

(Step-2) 7 + Check(7,3)

(Step-3) 8 + Check(8,2)

(Step-4) 9 + Check (9,1)

(Step-5) -9

Hence the output = -9 + 9 + 8 + 7 + 6 = 21

### PART II

### SECTION A

###### (Attempt any two questions from this Section.)

__Question 4__

####
(a) Given the Boolean function F (A, B, C, D) = Σ (1, 3, 5, 7, 8, 9, 10, 11, 14, 15).

(i) Reduce the above expression by using 4-variable Karnaugh map, showing the various groups (i.e. octal, quads and pairs).

(ii) Draw the logic gate diagram for the reduced expression. Assume that the variables and their complements are available as inputs.

(b) Given the Boolean function:

F (A, B, C, D) = π (4, 6, 7, 10, 11, 12, 14, 15)

(i) Reduce the above expression by using the 4-variable Karnaugh map, showing the various groups (i.e., octal, quads and pairs).

(ii) Draw the logic gate diagram for the reduced expression. Assume that the variables and their complements are available as inputs.

#### Solution

#####
(a) (i)

(ii)

(b) (i)

(ii)

__Question 5__

####
(a) What is a decoder? Draw the logic diagram for a binary to octal (3 to 8) decoder.

(b) How is a half adder different from a full adder? Draw the truth table and derive the SUM and CARRY expression for a full adder. Also, draw the logic diagram for a full adder.

(c) State whether the following expression is a Tautology, Contradiction or a Contingency, with the help of a truth table:

(X=>Z)∨~[(X=>Y)∧(Y=>Z)]

#### Solution

#####
(a) A decoder is a combinational circuit that converts binary information from n coded inputs to a maximum of 2^{n} unique outputs

(b) Half adder is a digital electronic circuit which is used to add 2 bits whereas full adder is used to add 3 bits.

Half adder perform partial addition where as full adder performs total addition

(c)

Hence it is a tautology

__Question 6__

####
(a) A passenger is allotted a window seat in an aircraft if he/she satisfies the criteria given below:

The passenger is below 15 years and is accompanied by an adult.

or

The passenger is a lady and is not accompanied by an adult.

or

The passenger is not below 15 years but is travelling for the first time.

The inputs are:

A - The passenger is below 15 years age.

C - The passenger is accompanied by an adult.

L - The passenger is a lady.

F - The passenger is travelling for the first time.

(In all the above cases 1 indicates yes and 0 indicates no).

Output: W – Denotes the passenger is allotted a window seat (1 indicates yes and 0 indicates no)

Draw the truth table for the inputs and outputs given above and write the SOP expression for W(A, C, L, F).

(b) State the complement properties. Find the complement of the following Boolean expression using De Morgan’s law:

AB’ + A’ + BC

(c) Differentiate between Canonical form and Cardinal form of expression.

#### Solution

#####
(a)

(b) The complement property says that any value AND the compliment of that value equals the OR identity and that any value OR the compliment of that value equals the OR identity

AB' + A' + BC

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

(c)

Canonical form | Cardinal form |
---|---|

Any Boolean function that is expressed as a sum of minterms or as a product of max terms is said to be in its canonical form. | Cardinal form of an expression is a complete system which clearly depicts the input and output in return the cardinal number where output has occurred. |

F(P, Q, R) = π(1, 3)

Example canonical form.

= (P + Q + R’). (P + Q’ + R’)

### SECTION B

###### (Answer any two questions.)

__Question 7__

######
A disarium number is a number in which the sum of the digits to the power of their respective position is equal to the number itself.
Example: 135 = 1^{1} + 3^{2} + 5^{3}
Hence, 135 is a disarium number.
Design a class Disarium to check if a given number is a disarium number or not. Some of the members of the class are given below:
Class name: Disarium
Data members/instance variables:
int num: stores the number
int size: stores the size of the number
Methods/Member functions:
Disarium (int nn): parameterized constructor to initialize the data members n = nn and size = 0
void countDigit(): counts the total number of digits and assigns it to size
int sumofDigits (int n, int p): returns the sum of the digits of the number(n) to the power of their respective positions (p) using recursive technique
void check(): checks whether the number is a disarium number and displays the result with an appropriate message
Specify the class Disarium giving the details of the constructor(), void countDigit(), int sumofDigits(int, int) and void check(). Define the main() function to create an object and call the functions accordingly to enable the task.

^{1}+ 3

^{2}+ 5

^{3}Hence, 135 is a disarium number. Design a class Disarium to check if a given number is a disarium number or not. Some of the members of the class are given below: Class name: Disarium Data members/instance variables: int num: stores the number int size: stores the size of the number Methods/Member functions: Disarium (int nn): parameterized constructor to initialize the data members n = nn and size = 0 void countDigit(): counts the total number of digits and assigns it to size int sumofDigits (int n, int p): returns the sum of the digits of the number(n) to the power of their respective positions (p) using recursive technique void check(): checks whether the number is a disarium number and displays the result with an appropriate message Specify the class Disarium giving the details of the constructor(), void countDigit(), int sumofDigits(int, int) and void check(). Define the main() function to create an object and call the functions accordingly to enable the task.

###### Solution:

import java.util.*; public class Disarium { int num,size; public Disarium(int nn) { num=nn; size=0; } void countDigits() { int t=num; while(t!=0) { ++size; t=t/10; } } int sumOfDigits(int n,int p) { if(n!=0) { return (int)Math.pow(n%10,p)+sumOfDigits(n/10,p-1); } else { return 0; } } void check() { countDigits(); if(sumOfDigits(num,size) == num) { System.out.println("Disarium No."); } else { System.out.println("Not a Disarium No."); } } public static void main(String args[]) { Scanner sc=new Scanner(System.in); System.out.println("Enter a number"); int n=sc.nextInt(); Disarium ob=new Disarium(n); ob.check(); } }

__Question 8__

######
A class Shift contains a two-dimensional integer array of order (m×n) where the maximum values of both m and n are 5. Design the class Shift to shuffle the matrix (i.e. the first row becomes the last, the second row becomes the first and so on). The details of the members of the class are given below:
Class name: Shift
Data member/instance variable:
mat[][]: stores the array element
m: integer to store the number of rows
n: integer to store the number of columns
Member functions/methods:
Shift(int mm, int nn): parameterized constructor to initialize the data members m=mm and n=nn
void input(): enters the elements of the array
void cyclic(Shift p): enables the matrix of the object (P) to shift each row upwards in a cyclic manner and store the resultant matrix in the current object
void display(): displays the matrix elements
Specify the class Shift giving details of the constructor(), void input(), void cyclic(Shift) and void display(). Define the main() function to create an object and call the methods accordingly to enable the task of shifting the array elements.

###### Solution:

__Question 9__

######
A class ConsChange has been defined with the following details:
Class name: ConsChange
Data members/instance variables:
word: stores the word
len: stores the length of the word
Member functions/methods:
ConsChange(): default constructor
void readword(): accepts the word in lowercase
void shiftcons(): shifts all the consonants of the word at the beginning followed by the vowels (e.g. spoon becomes spnoo)
void changeword(): changes the case of all occurring consonants of the shifted word to uppercase, for e.g. (spnoo becomes SPNoo)
void show(): displays the original word, shifted word and the changed word
Specify the class ConsChange giving the details of the constructor (), void readword ( ), void shiftcons (), void changeword() and void show(). Define the main() function to create an object and call the functions accordingly to enable the task.

###### Solution:

import java.util.*; class ConsChange { String word; int len; public ConsChange() { word = ""; len =0; } public void readword () { Scanner sc=new Scanner(System.in); System.out.println ("Enter the word in lowercase"); word = sc.next(); len=word.length(); } public void shiftcons() { String c="",v=""; for (int i= 0; i < len; i++) { char ch = word.charAt (i); if(ch=='a' || ch=='e' || ch == 'i'||ch=='o' || ch=='u') { v=v+ch; } else { c=c + ch; } } word = v+c; System.out.println ("Shifted Word is:" +word); } public void changeword() { int pos = -1; char ch; String s=""; for (int i = 0; i < len; i++) { ch = word.charAt (i); if(ch != 'a' && ch != 'e' && ch!='i' && ch!='o' && ch != 'u') { s+= (char)(ch -32); } else{ s=s+ ch; } } System.out.println("changed word is:"+ s); } public void show() { System.out.println("Original word:"+word); shiftcons(); changeword(); } public static void main (String args[]) { ConsChange ob = new ConsChange(); ob.readword(); ob.show(); } }

### SECTION C

###### (Attempt any two questions.)

__Question 10__

######
A superclass Bank has been defined to store the details of a customer. Define a sub-class Account that enables transactions for the customer with the bank. The details of both the classes are given below:
Class name: Bank
Data members/instance variables:
name: stores the name of the customer
accno: stores the account number
P: stores the principal amount in decimals
Member functions/methods:
Bank(….): parameterized constructor to assign values to the instance variables
void display (): displays the details of the customer
Class name: Account
Data member/instance variable:
amt: stores the transaction amount in decimals
Member functions/methods:
Account(…): parameterized constructor to assign values to the instance variables of both the classes
void deposit(): accepts the amount and updates the principal as p=p+amt
void withdraw(): accepts the amount and updates the principal as p=p-amt
If the withdrawal amount is more than the principal amount, then display the message “INSUFFICIENT BALANCE”.If the principal amount after withdrawal is less than 500, then a penalty is imposed by using the formula. p=p-(500-p)/10
void display(): displays the details of the customer
Assume that the superclass Bank has been defined.Using the concept of Inheritance; specify the class Account giving details of the constructor(…), void deposit(), void withdraw() and void display().
The superclass and the main function need not be written.

###### Solution:

class Bank { String name; int accno; double p; Bank(String nm,int nu,double pr_amt) { name=nm; accno=nu; p=pr_amt; } public void display() { System.out.println("Name of the customer is:"+name); System.out.println("Account number"+accno); System.out.println("principal amount"+p); } } import java.util.*; class Account extends Bank { double amt; Scanner sc =new Scanner(System.in); public Account(String n, int a, double pr) { super(n, a, pr); amt = 0.0; } public void deposit () { System.out.println("Enter Amount : "); amt = sc.nextDouble(); p = p - amt; } public void withdraw() { System.out.print("Enter Amount : "); amt = sc.nextDouble(); if(amt > p) System.out.println("INSUFFICIENT BALANCE"); else { p=p - amt; if(p < 500) p = p - (500 - p) / 10.0; } } public void display() { super.display(); System.out.println(amt); } }

__Question 11__

######
A bookshelf is designed to store the books in a stack with LIFO(Last In First Out) operation. Define a class Book with the following specifications:
Class name: Book
Data members/instance variables:
name[]: stores the names of the books
point: stores the index of the topmost book
max: stores the maximum capacity of the bookshelf
Methods/Member functions:
Book(int cap): constructor to initialise the data members max = cap and point = -1
void tell(): displays the name of the book which was last entered in the shelf. If there is no book left in the shelf, displays the message “SHELF EMPTY”
void add(String v): adds the name of the book to the shelf if possible, otherwise displays the message '‘SHELF FULL”
void display(): displays all the names of the books available on the shelf
Specify the class Book giving the details of ONLY the functions void tell() and void add(String). Assume that the other functions have been defined.
The main function need not be written.

###### Solution:

import java.util.*; class Diff { public static void main (String args[]) { double a[]=new double[20]; Scanner sc = new Scanner(System.in); for(int i=0; i< 20; i++) { System.out.println("Enter the "+(i+1)+" element:"); a[i]=sc.nextDouble(); } double max=a[0], min=a[0]; for (int i=0; i < a.length; i++) { if(a[i]>max) max=a[i]; if(a[i]< min) min=a[i]; } System.out.println("The largest element in the array is :" + max); System.out.println("\nThe smallest element of the array is :" + min); System.out.println("\nThe range of array is : " + (max-min)); } }

__Question 12__