Code is copied!
CLASS 12 ISC - Java Question Paper 2017
PART I
(Attempt all questions)
Question 1
(a) State the law represented by the following proposition and prove it with the help of a truth table: P ∨ P = P
Solution
(a) The law represented by the given proposition is Idempotent law.
Truth Table:
(b) State the Principle of Duality
Solution
(b) The duality principle states that every algebraic expression deducible from the postulates of Boolean algebra remains valid if the operators and identity elements are interchanged.
(c) Find the complement of the follow ing Boolean expression using De Morgan’s law:
Solution
(c) ((b’ + c) + a)’
= (b’+c)’. a’
= ((b’)’ . c’) . a’
= bc’a’
(d) Draw the logic diagram and truth table for a 2 input XNOR gate.
Solution
(e)
If (~P => Q) then write its:
(i) Inverse
(ii) Converse
Solution
(e) (i) Inverse of the given statement
P => ~Q
(ii) Converse of the given statement Q => ~P
(a)
What is an interface? How is it different from a class?
Solution
(a) An interface in Java is a blueprint of a class. It has static constants and abstract methods. The interface in java is a mechanism to achieve abstraction. There can be only abstract methods in the Java interface, not the method body. It is used to achieve abstraction and multiple inheritances in Java.
It cannot be instantiated just like an abstract class.
A Java Interface is also a virtual construct in the programming world but is contrary to the Java Class, Interface cannot be instantiated or created as an object. An Interface denotes a group of logical entities. It can also act as a contract between two subsystems while communicating with each other.
(b)
Convert the following infix expression to postfix form:
P * Q/R + (S + T)
Solution
(b) PQ*R/ST++
(c) A matrix P[15] [10] is stored with each element requiring 8 bytes of storage. If the base address at P[0] [0] is 1400, determine the address at P[10] [7] when the matrix is stored in Row Major Wise
Solution
(c) Row Major Address Formula: M[i] [j] = B(A) + W[(i – Ir)*column + (j – Ic)]
In the given problem, Address of P[10][[7] is asked.
1400 is base address, column =10, W = 8 bytes, i = 10, j = 7, Ir = 0 and Ic = 0.
Address of P[10] [7]:
= 1400 + 8[(10 – 0)*10 + (7 – 0)]
= 1400 + 8[100 + 7]
= 1400 + 8*107
= 2256
(d)
(i) What is the worst-case complexity of the following code segment:
for(int x = 1; x<=a; x++)
{
statements;
}
for(int y = 1; y <= b; y++)
{
for (int z = 1; z <= c; z++)
{
statements;
}
}
(ii) How would the complexity change if all the three loops went to N instead of a, b and c?
Solution
(d) (i) O(a + bc)
(ii) O(n^2)
(e) Differentiate between a constructor and a method of a class
Solution
Method | Constructor |
---|---|
Method name cannot be same as of class name | Constructor name will be same as class name |
Method can have return type | Constructor doesn't have any return type not even void |
The following function magicfun() is a part of some class. What will the function magicfun() return, when the value of n=7 and n=10, respectively? Show the dry run/working:
At n = 7 ⇒ 111
int magicfun (int n) { if(n = = 0) return 0; else return magicfim(n/2) * 10 + (n%2); }
Solution
At n = 7 ⇒ 111
At n = 10 ⇒ 1010
Binary equivalent of N
PART II
SECTION A
(Attempt any two questions from this Section.)
Question 4
(a) Given the Boolean function F(A, B, C, D) = X (2, 3, 4, 5, 6, 7, 8, 10, 11).
(i) Reduce the above expression by using 4-variable Karnaugh map, showing the various groups (i.eoctal, 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(P, Q, R, S) = π(0, 1, 2, 4, 5, 6, 8, 10).
(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)
(a) A school intends to select candidates for an Inter-School Essay Competition as per the criteria are given below:
The student has participated in an earlier competition and is very creative.
OR
The student is very creative and has excellent general awareness, but has not participated in any competition earlier.
OR
The student has excellent general awareness and has won a prize in an inter-house competition.
The inputs are:
A - participated in a competition earlier
B - is very creative
C - won a prize in an inter-house competition
D - has an excellent general awareness
(In all the above cases 1 indicates yes and 0 indicates no).
Output: X [1 indicates yes, 0 indicates no for all cases]
Draw the truth table for the inputs and outputs given above and write the POS expression for X(A, B, C, D).
(b) State the application of a Half Adder. Draw the truth table and circuit diagram for a Half Adder.
(c) Convert the following Boolean expression into its canonical POS form:
F(A, B, C) = (B + C’).(A’ + B)
Solution
(a)
(b) Half adder is a combinational logic circuit with two inputs and two outputs. The half adder circuit is designed to add two single bit binary number A and B. It is the basic building block for the addition of two single-bit numbers. This circuit has two outputs carry and sum.
(c) X + YZ = (X + Y)(X + Z)
Now A.A’ = 0, Similarly, C.C’ = 0
Therefore, (B + C’) = (B + C’ + A.A’) = (B + C + A) (B + C + A’)
[Treating B + C’ as a single variable]
and(A’ + B) = (A’+B + C.C’) = (A’ + B + C)(A’ + B + C’)
[Treating A’ + B as a single variable]
F(A, B, C) = (B + C’).(A’ + B)
= (B + C’ + A)(B + C’ + A’)(A’ + B + C)(A’ + B + C’)
(a) What is & Multiplexer? How is it different from a decoder? Draw the circuit diagram for a 8 : 1 Multiplexer.
(b) Prove the Boolean expression using Boolean laws. Also, mention the law used at each step.
F = (x’ + z) + [(y’ + z).(x’ + y)]’ = 1
(c) Define maxterms and mm terms. Find the maxterm and mintenn when:
P = 0, Q = 1, R = 1 and S = 0
Solution
(a) Multiplexer is a special type of combinational circuit. There are n-data inputs, one output and m select inputs with 2m = n. It is a digital circuit which selects one of the n data inputs and routes it to the output.
The main function of multiplexer basically is to connect information from one point to another point through wires while on the other hand, decoders convert the outputs for several operations such as data collection and calculations.
(b) F =(x’ + z) + [(y’ + z).(x’ + y)]’
= x’ + z + (y’ + z)’ + (x’ + y)’
= x’ + z + (y’)’ z’ + (x’)’ y’ [De Morgan’s Law]
= x’ + z + yz’ + xy’ [Double Negation]
= x’ + xy’ + z + yz’ [a + a’b = a + b]
= x’ + y’ + z + y
= x’ + z + y’ + y [Complement Law: a + a’ = 1]
= x’ + z + 1
= 1
(c) Maxterm refers to the sum of all the literals with and without bar present within a logic system
Minterm product of all the literals without without bar present within the logic systems.
Here, we are given,
P = 0,Q = 1, R = 1 and S = 0
⇒ Minterm = P’QRS’
⇒ Maxterm = (P + Q’ + R’ + S)
SECTION B
(Answer any two questions)
Question 7
A class Palin has been defined to check whether a positive number is a Palindrome number or not.
The number ‘N’ is palindrome if the original number and it’s reverse are the same.Some of the members of the class are given below:
Class name: Palin
Data members/instance variables:
num: integer to store the number
revnum: integer to store the reverse of the number
Methods/Member functions:
Palin(): constructor to initialize data members with legal initial values
void accept(): to accept the number
int reverse(int y): reverses the parameterized argument ‘y’ and stores it in revenue using a recursive technique
void check(): checks whether the number is a Palindrome by invoking the function reverse() and display the result with an appropriate message
Specify the class Palin giving the details of the constructor (), void accept(), int reverse(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.*; class Palin { int num,revnum; public Palin() { num=0; revnum=0; } void accept() { Scanner sc=new Scanner(System.in); System.out.println("Enter a no."); num=sc.nextInt(); } int reverse(int y) { if(y!=0) { revnum=revnum*10+y%10; return(reverse(y/10)); } else { return revnum; } } void check() { int p=num; if(reverse(p) == num) { System.out.println("Palindrome"); } else { System.out.println("Not a Palindrome"); } } public static void main(String args[]) { Palin ob=new Palin(); ob.accept(); ob.check(); } }
Question 8
A class Adder has been defined to add any two accepted time.
Example:
Time A – 6 hours 35 minutes
Time B – 7 hours 45 minutes
Their sum is – 14 hours 20 minutes (where 60 minutes = 1 hour)
The details of the members of the class are given below:
Class name: Adder
Data member/instance variable:
a[ ]: integer array to hold two elements (hours and minutes)
Member functions/methods:
Adder (): constructor to assign 0 to the array elements
void readtime (): to enter the elements of the array
void addtime (Adder X, Adder Y): adds the time of the two parameterized objects X and Y and stores the sum in the current calling object
void disptime(): displays the array elements with an appropriate message (i.e., hours= and minutes=)
Specify the class Adder giving details of the constructor( ), void readtime( ), void addtime(Adder, Adder) and void disptime(). Define the main() function to create objects and call the functions accordingly to enable the task.
Solution:
import java.util.*; class Adder { int a[]; public Adder() { a = new int[2]; a[0]=0; a[1]=0; } void readtime() { Scanner sc=new Scanner(System.in); System.out.println("Enter hours"); a[0] = sc.nextInt(); System.out.println("Enter minutes :"); a[1] = sc.nextInt(); } void addtime(Adder X, Adder Y) { a[1]=X.a[1] + Y.a[1]; a[0] = a[1]/60; a[1] = a[1] %60; a[0]=X.a[0] + Y.a[0]; } void disptime() { System.out.println("hours =" + a[0] +" minutes =" + a[1]); } public static void main(String args[ ]) { Adder obj1 = new Adder(); Adder obj2 = new Adder(); Adder obj3 = new Adder(); obj1.readtime(); obj2.readtime(); obj3.addtime(obj1, obj2); obj3.disptime(); } }
Question 9
A class SwapSort has been defined to perform string related operations on a word input. Some of the members of the class are as follows:
Class name: SwapSort
Data members/instance variables:
wrd: to store a word
len: integer to store the length of the word
swapwrd: to store the swapped word
sortwrd: to store the sorted word
Member functions/methods:
SwapSort(): default constructor to initialize data members with legal initial values
void readword(): to accept a word in UPPER CASE
void swapchar(): to interchange/swap the first and last characters of the word in ‘wrd’ and stores the new word in ‘swapwrd’
void sortword(): sorts the characters of the original word in alphabetical order and stores it in ‘sortwrd’
void display(): displays the original word, swapped word and the sorted word
Specify the class SwapSort, giving the details of the constructor(), void readword(), void swapchar(), void sortword() and void display(). Define the main() function to create an object and call the functions accordingly to enable the task.
Solution:
import java.util.*; public class SwapSort { int len; String swapwrd,sortwrd,wrd; SwapSort() { wrd = ""; len = 0; swapwrd = ""; sortwrd = ""; } void readword() { Scanner sc=new Scanner(System.in); System.out.println("Enter a word in Upper Case"); wrd=sc.next(); len=wrd.length(); } void swapchar() { char ch1,ch2; ch1=wrd.charAt(0); ch2=wrd.charAt(len-1); swapwrd=ch2+wrd.substring(1,(len-1))+ch1; } void sortword () { for(int i=65;i< 90;i++) { for(int j=0;j< len; j++) { if(wrd.charAt(j) == i) { sortwrd=sortwrd + wrd.charAt(j); } } } } void display() { System.out.println("Original word :" + wrd); System.out.println("Swapped word :" + swapwrd); System.out.println("Sorted word :" + sortwrd); } public static void main(String args[]) { SwapSort obj = new SwapSort(); obj.readword(); obj.swapchar(); obj.sortword(); obj.display(); } }
Question 10
A superclass Product has been defined to store the details of a product sold by a wholesaler to a retailer. Define a subclass Sales to compute the total amount paid by the retailer with or without fine along with service tax.
Some of the members of both classes are given below:
Class name: Product
Data members/instance variables:
name: stores the name of the product
code: integer to store the product code
amount: stores the total sale amount of the product (in decimals)
Member functions/methods:
Product (String n, int c, double p): parameterized constructor to assign data members: name = n, code = c and amount = p
void show(): displays the details of the data members
Class name: Sales
Data members/instance variables:
day: stores number of days taken to pay the sale amount
tax: to store the sen ice tax (in decimals)
totamt: to store the total amount (in decimals)
Member functions/methods:
Sales(….): parameterized constructor to assign values to data members of both the classes
void compute(): calculates the service tax @ 12.4% of the actual sale amount.
calculates the fine @ 2.5% of the actual sale amount only if the amount paid by the retailer to the wholesaler exceeds 30 days calculates the total amount paid by the retailer as (actual sale amount + service tax + fine)
void show (): displays the data members of the superclass and the total amount
Assume that the superclass Product has been defined. Using the concept of inheritance, specify the class Sales giving the details of the constructor (…), void compute() and void show(). The superclass, main function and algorithm need NOT be written.
Solution:
import java.util.*; class Product { String name; int code; double amount; Product(String n, int c, double p) { name = n; code = c; amount = p; } void show() { System.out.println("Name is :"+ name); System.out.println("Code is :" + code); System.out.println("Total Sale Amount:" + amount); } } class Sales extends Product { int day; double tax; double totamt; double fine = 0.0; Sales(String n, int c, double p, int d) { super(n, c, p); day = d; } void compute() { if(day < 30) { tax = 12.4 * amount /100; totamt = amount + tax; } if(day > 30) { tax= 12.4 * amount /100; fine = 2.5 * amount /100; totamt = amount + tax + fine; } } void show () { super.show(); System.out.println("Total amount to be paid::"+ totamt); } } class base { public static void main(String args[]) { Sales obj = new Sales ("Anuj", 12345, 4567.90, 6); obj.compute(); obj.show(); } }
Question 11
A queue is an entity which can hold a maximum of 100 integers. The queue enables the user to add integers from the rear and remove integers from the front.
Define a class Queue with the following details:
Class name: Queue
Data members/instance variables:
Que[]: array to hold the integer elements
size: stores the size of the array
front: to point the index of the front
rear: to point the index of the rear
Member functions:
Queue(int mm): constructor to initialize the data size = mm, front = 0, rear = 0
void addele(int v): to add integer from the rear if possible else display the message “Overflow”
int delele(): returns elements from front if present, otherwise displays the message “Underflow” and return -9999
void display(): displays the array elements
Specify the class Queue giving details of ONLY the functions void addele(int) and int delete().Assume that the other functions have been defined.
The main function and algorithm need NOT be written.
Solution:
import java.util.*; class Product { String name; int code; double amount; Product(String n, int c, double p) { name = n; code = c; amount = p; } void show() { System.out.println("Name is :"+ name); System.out.println("Code is :" + code); System.out.println("Total Sale Amount:" + amount); } } class Sales extends Product { int day; double tax; double totamt; double fine = 0.0; Sales(String n, int c, double p, int d) { super(n, c, p); day = d; } void compute() { if(day < 30) { tax = 12.4 * amount /100; totamt = amount + tax; } if(day > 30) { tax= 12.4 * amount /100; fine = 2.5 * amount /100; totamt = amount + tax + fine; } } void show () { super.show(); System.out.println("Total amount to be paid::"+ totamt); } } class base { public static void main(String args[]) { Sales obj = new Sales ("Anuj", 12345, 4567.90, 6); obj.compute(); obj.show(); } }
Question 12