Computer 12th 2017
Computer 12th 2017
Computer Science-XII
Time : 3 hrs Max. Marks : 100
General Instructions
1. Answer all questions in Part I (compulsory) and seven questions from Part II.
2. Attempt any seven questions from Part II, choosing three questions from Section A, two
from
Section B and two from Section C.
3. The intended marks for questions or parts of question are given in brackets [ ].
1. (a) State the law represented by the following proposition and prove it with
the help of a truth table
PVPP
(b) State the Principle of Duality.
(c) Find the complement of the following Boolean expression using De
Morgan’s law.
F(a, b, c) (b c) a
(d) Draw the logic diagram and truth table for a 2 input XNOR gate.
(e) If (~ P Q) then write its
(i) Inverse
(ii) Converse
Ans. (a) P V P = P proposition represents the idempotent law.
Truth table for P VP = P
P P P=PVP
0 0 0
1 1 1
Hence, P = P V P Proved
(b) Principle of Duality
It is states that a boolean relation can be derived by
(i) changing every OR (+) by AND (.)
(ii) changing every AND (.) by OR (+)
(iii) changing every 0 by 1 and 1 by 0
(c) Given expression is, F (a, b, c) =(b + c) + a
The complement of F i.e. F
F = [(b + c) + a] = (b + c) . a
= (b) . c . a = b.c.a
= a b c
(d) Logic diagram for a 2 input XNOR gate :
A
Y
B
Y = A B = AB + AB
Truth table for a 2 input XNOR gate
A B Y
0 0 1
0 1 0
1 0 0
1 1 1
(e) (i) To form the inverse of the statement, take the negation of both the antecedent and the
consequent.
So, ~ P Q
Here, P is a antecedent and Q is a consequent
Hence, inverse would be ~ (~ P) ~ Q
P ~Q
(ii) To form the converse of the statement, interchange the antecedent to consequent.
Hence, converse would be Q ~ P
3. 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:
int magicfun(int n)
{
if (n==0)
return 0;
else
return magicfun(n/2) * 10 + (n % 2);
}
Ans. When n=7 then,
Return 111
magicfun (3) 10 + (1)
Return 11
Call magicfun (1) * 10+(1)
Return 1
Call magicfun (0) * 10 + (1)
Return 101
Call magicfun (2)*10+(1)
Return 10
Call magicfun (1)*10+(0)
Return 1
Call magicfun (0)*10+(1)
Answer six questions in this part, choosing two questions from Section A,
two from Section B and two Section C.
Section - A
Answer any three questions
AB 1 1
0 1 3 2
AB 1 1 1 1
4 5 7 6
AB
12 13 15 14
AB 1 1 1
8 9 11 10
AAB B C C D D
AB
BC
F=AB + BC + ABD
ABD
P+Q 0 0 0
0 1 3 2
P+Q 0 0 0
4 5 7 6
P+Q
12 13 15 14
P+Q 0 0
8 9 11 10
P Q R S
P+R
P+S
F= (P+R) . (P+S) . (Q+S)
Q+S
5. (a) A school intends to select candidates for an Inter-School Essay
Competition as per the criteria 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 prize in
an inter-house competition.
The inputs are
INPUTS
A participated in competition earlier
B is very creative
C won prize in an inter-house competition
D has excellent general awareness
Sum (S ) XY XY X Y
Carry (C ) XY
Logic/Circuit diagram
X
S=X+Y
Y
C=XY
I
0
I
1
I
2
I3
F
I
4
I
5
I
6
I
7
Multiplexer Decoders
A digital multiplexer is a combinational A decoder is a combinational circuit that
circuit that selects binary information from coverts binary information from ‘n’ input
one of many input lines and directs it to a line to a maximum of 2n unique output
single output line. lines.
It is called as data selector, since it selects This decoder is called n-to-m line decoder
one of many inputs. where m 2n.
A multiplexer is used to share several Decoders are used to keep abstraction and
signals to one device like A/D convertor. modularity in hardware design.
e.g.4-to-1 line multiplexer. e.g. 3-to-8 decoder.
Section - B
Answer any two 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. (Flowcharts and Algorithm are not required)
The programs must be written in Java
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.
Ans. import java.io.*;
class Palin
{
int num;
int revnum;
int reverse = 0;
Palin()
{
num=0;
revnum=0;
}
void accept() throws IOException
{
InputStreamReader IR=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(IR);
System.out.println(“Enter the number”);
num=Integer.parseInt(br.readLine());
}
int sum=0,rem;
int reverse(int y)
{
if(y>0)
{
rem=y%10;
sum=sum*10+rem;
reverse(y/10);
}
else
return sum;
return sum;
}
void check()
{
revnum=reverse(num);
if(num==revnum)
System.out.println(num+" is a palindrome number");
else
System.out.println(num+" is not a palindrome number");
}
public static void main(String args[]) throws IOException
{
Palin P = new Palin();
P.accept();
P.check();
}
}
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.
Ans. import java.io.*;
class Adder
{
int a[] = new int[2];
Adder()
{
a[0]=0;
a[1]=0;
}
void readtime() throws IOException
{
InputStreamReader IR=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(IR);
System.out.println("Enter the Time in Hours and Minutes");
a[0]=Integer.parseInt(br.readLine());
a[1]=Integer.parseInt(br.readLine());
}
void addtime(Adder X, Adder Y)
{
a[0]=X.a[0]+Y.a[0];
a[1]=X.a[1]+Y.a[1];
if(a[1]>=60)
{
a[0]=a[0]+a[1]/60;
a[1]=a[1]%60;
}
}
void disptime()
{
System.out.println(a[0]+" hours "+a[1]+" minutes");
}
public static void main(String args[]) throws IOException
{
Adder A = new Adder();
Adder B = new Adder();
Adder C = new Adder();
A.readtime();
B. readtime();
C. addtime(A, B);
System.out.print("Time A - ");
A.disptime();
System.out.print("Time B - ");
B.disptime();
System.out.print("Their sum is - ");
C.disptime();
}
}
Section - C
Answer any two questions
Each program should be written in such a way that it clearly depicts the
logic of the problem stepwise.
This can be achieved by using comments in the program and mnemonic
names or pseudo codes for algorithms. The programs must be written in
Java and the algorithms must be written in general/standard form,
wherever required/specified.
(Flowcharts are not required)
10. A super class Product has been defined to store the details of a product sold by
a wholesaler to a retailer. Define a sub class Sales to compute the total amount
paid by the retailer with or without fine along with service tax.
Some of the members of both the 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 services tax (in decimals)
totamt to store the total amount (in decimals)
Member functions/methods
Sales (…) paramaterized constructor to assign values to
data members to both the classes
void compute( ) calculates the services 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 super class and the
total amount
Assume that the super class 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 super class, main function and algorithm need NOT be written.
Ans. class Sales extends Product
{
int day;
double tax;
double totamt;
Sales (String n, int c; double p, int d)
{
Super (n, c, p);
day = d;
tax = 0.0;
totamt = 0.0;
}
void compute( )
{
tax = (amount*12.4)/100;
int fine = 0;
if (day > 30)
fine = (amount * 2.5)/100;
totamt = amount + tax + fine;
}
void show( )
{
System.out.println("Name of the product:" + name);
System.out.println("Product code :" + code);
System.out.println("Sale amount of the product :" +amount);
System.out.println("Total amount :" + totamt);
}
}
11. 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 Product
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 delele ( ). Assume that the other functions have been
defined.
The main function and algorithm need NOT be written.
Ans. class Queue
{
void addele (int v)
{
if (rear = = 1)
{
front = 0;
rear = 0;
Que [rear] = v;
}
else if (rear + 1 < Que.length)
Que [++rear] = v;
else
System.out.println("Overflow");
}
int delele ( )
{
int element;
if (front = = 0)
{
System.out.println("Underflow");
return 9999;
}
else if (front = = rear)
{
element = Que [front];
front = rear = 0;
return element;
{
else
return (Que [front ++]);
}
};
12. (a) A linked list is formed from the objects of the class Node. The class
structure of the Node is given below :
class Node
{
int num;
Node next;
}
Write an Algorithm OR a Method to count the nodes that contain only
odd integers from an existing linked list and returns the count.
The method declaration is as
follows : int CountOdd(Node
startPtr)
(b) Answer the following questions from the diagram of a Binary Tree
given below
N G
W Y Z D
F R
(i) Write the postorder traversal of the above tree structure.
(ii) State the level numbers of the nodes N and R if the root is at 0 (zero)
level.
(iii) List the internal nodes of the right sub-tree.
Ans. (a) Algorithm
CountOdd (Node startPtr)
Step 1 Set count = 0 (Initialise counter)
Step 2 Set num = startPtr (Initialise pointer)
Step 3 Repeat steps 4 and 5 while num ! = NULL
Step 4 If num % 2 ! = 0 then
count = count + 1
Step 5 num = next [num]
/* updates pointer to point to next node */
Step 6 Return count
Or
Method
int CountOdd(Node startPtr)
{
int count = 0 ;
num = startPtr;
while (num ! = NULL)
{
if (num%2 != 0_
{
count = count + 1;
}
num = next [num];
}
return count;
}
(b) (i) Post order traversal of tree is
= NGM
=WYNZDGM
=WFYNRZDGM
(ii)
M Level 0
N G Level 1
W Y Z D Level 2
F R Level 3