XII Cs
XII Cs
XII Cs
Computer Science
I Pre Board Exam (2023-24)
int check(int n)
{ if(n<=1)
return 1;
if( n%2==0)
return 1 + check(n/2);
else
return 1 + check(n/2 + 1);
}
(a) What will the value of return when n=25 and n=10? [2]
(b) What function does check() perform. apart from recursion? [1]
(iv) The following function is a part of some class which computes and check the number is
palindrome or not. There are some places in the code marked by ?1? , ?2? , ?3? which must be
replaced by an expression / a statement so that the function works correctly.
void palin(int n)
{
int d, num, rev=0;
1
num = ?1?;
while( ?2?)
{
d = n%10;
rev =?3?;
n=n/10 ;
}
if (rev==num)
System.out.println(num+'' is a Palindrome no'') ;
else
System.out.println(num+'' is not a Palindrome no'') ;
}
(a) What is the expression or statement at ?1? [1]
(b) What is the expression or statement at ?2? [1]
(c) What is the expression or statement at ?3? [1]
(b) (a) Given the Boolean function: F(A, B, C, D) = 𝝅 ( 3, 4, 6, 9, 11, 12, 13, 14, 15 ).
Reduce the above expression by using 4-variable Karnaugh map, showing various
groups (i.e. octal, quads and pairs). [4]
(b) Draw the logic gate diagram for the reduced expression. Assume that the
variables and their complements are available as inputs. [1]
Question 4
(i) (a) Draw a logic diagram for the given expression. [4]
AB(A + B) + ABC
(b) What do you mean by logic gate? [1]
(ii) (a) Draw the logic circuit encode the following Octal number(3) to its binary equivalents of
given numbers [5]
Question 5
(a) A company intends to develop a device to show the high status power load for a house hold
invertors depending on the criteria given below: [5]
If Air conditioner and Geyser are on
OR
If Air conditioner is off, but Geyser and Refrigerator are on
OR
If Geyser is off, but Air conditioner and Water purifier are on
OR
When all are on
The inputs are:
INPUTS
A Air conditioner is on
2
G Geyser is on
R Refrigerator is on
W Water purifier is on
(In all the above cases 1 indicates yes and 0 indicates no.)
Output : X [1 indicates high power, 0 indicates low power for all cases]
Draw the truth table for the inputs and outputs given above and write the SOP
expression for X(A,G,R,W).
(b) Draw the truth table and derive an SOP expression for sum and carry for a full adder.Also,
draw the logic circuit for the carry of a full adder. [3]
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 Algorithms are not required.)
The programs must be written in Java.
Question 6
A class Palindrome has been defined to check whether a positive number is palindrome number
or not. The number ‘N’ is palindrome if the original number and its reverse are same. Some of
details of the class are given below. [10]
Class name : Palindrome
Data members/ Instance Variables
num : integer to store the number
revnum : integer to store the reverse number.
Methods/Member functions
palindrome() : constructor to initialize the data members with legal initial
values.
void accept : to accept number.
int reverse(int n) : reverse the parameterized argument ‘n’ and store the
revnum using recursive technique.
void check : checks whether the number is palindrome or not by
invoking the function reverse() and display the result
with an appropriate message.
Specify the class Palindrome giving 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 task.
Question 7 [10]
Declare a matrix A[][] of order M× M where m is the number of rows and number of the
columns. Such that M must be greater than 2 and less than 10. Accept the value of M from the
user. Display an appropriate message for an invalid input. Allow the user to input integers into
the matrix. Perform the following task,
Display the original matrix
3
Rotate the matrix 900 clockwise as shown below
Question 8
A class Mix has been defined to mix two words, character by character, in the following manner:
The first character of the first word is followed by the first character of the second word and
so on. If the words are of different length, the remaining characters of the longer word are put at
the end.
Example: If the First word is “JUMP” and the second word is “STROLL”, then the requiredword
will be “JSUTMRPOLL”. [10]
Some of the members of the class are given below:
Class name : Mix
Data member/instance variable:
wrd1,wrd2 : to store a word
len : to store the length of the word
Member functions/methods:
Mix( ) : default constructor to initialize the data
members with legal initial values
void feedword( ) : to accept the word in UPPER case
void mix_word() : mix the two words into a single word.
void display( ) : displays the word
Specify the class Mix giving the details of the constructor( ), void feedword( ), void mix_word()
and void display( ). Define the main( ) function to create objects and call the functions
accordingly to enable the task.
SECTION – C
Answer any two questions.
4
Each program should be written in such a way that it clearly depicts the logic of the problem
stepwise.
Question 9 [5]
A queue is a linear data structure which works on the principle of FIFO, enables the user to enter
data from the rear end and remove data from the front end . .Define a classCirQueue with the
following details:
Class name : Queue
Data members / instance variables:
arr [ ] : array to store the integers
cap : stores the maximum capacity of the array
front : to point the index of the front end
rear : to point the index of the rear end
Member functions:
Queue (int max) : constructor to initialize the datamember
cap=max, front=-1 and rear=-1
void push(int n) : to add integer in the queue from the rear
end if possible, otherwise display the
message “QUEUE IS FULL”
int pop( ) : removes and returns the integer from the
front end of the queue if any, else otherwise
display the message “QUEUE IS UNDER FLOW”
void show( ) : displays the queue elements
Specify the class Queue giving details of the functions void push(int) and int pop( ). Assume
that the other functions have been defined.
Question 10 [5]
Write a class Sentence to store a sentence and another class Duplicate to replace the duplicate
characters. The details of the classes are given.
Class name : Sentence
Data members/instance variable
str : to store a sentence in the string variable of proteced type
Member function/methods
Sentence() : constructor to assign string variable.
void accept() : to accept a sentence in the variable str.
void display() : to display the sentence after performing the task.
5
For example : Ammmmiit Kuulkkkarnni iiiiss aa ssssttuudddeentt of ccclllassss
tttwwweellllvvvve
Output:- Amit Kulkarni is a student of class twelve.
Specify the class Sentence giving the details of the function void accept() and void display()
Using the concept of inheritance, specify the class \Duplicate giving the details of the function
void removeDuplicate().
The super class, main function and algorithm need NOT be written.
Question 11 [2]
(a) A linked list is formed the object of the class below.
class node
{
double sal;
node next;
}
Write an algorithm or a method to add a node at the end of an existing linked list.
The method declaration is as follows
void addnode(Node ptr, double ss)
(b) Answer the following questions from the diagram of Binary Tree given below.
F B
D G H
(i) Write the preorder traversal of the above tree structure. [1]
(ii) Name the parent of the Node D and B [1]
(iii) State the level of E and F when the root is at level zero(0). [1]