Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

Good Earth School

Naduveerapattu
Date: 20.12.2019 Marks: 70
Class: XII Time: 3 hrs.
First Term Examination
Computer Science Answer Key
Candidates are allowed additional 15 minutes for only reading the paper.
They must NOT start writing during this time.
All working, including rough work should be done on the same sheet as the rest of the answer.
The intended marks for questions or parts of questions are given in brackets ( ).
Part – I
Answer all the questions
Question 1. [1 x 5 = 5]
Question 2. [2 x 5 = 10]

Question 3.
The following is a method/function of some class. Give the output of the function perform( ) when the
value of ‘n’ is 6579. [5]
void perform (int n)
{
int s=0, g;
while(n>0)
{
if(n%2==1)
n/=10;
g=n%10;
System.out.print(“\n g = \t” + g);
s=s+g;
n/=5;
}
System.out.print(“\n s = \t” + s);
}
Part – II
Answer six questions in this part, choosing two questions from Section A,
two from Section B and two from Section C
Section – A
Answer any two questions

Question 4.
Question 5.
(a) The Planning Committee of a particular town consists of a President, Secretary and a Treasurer.
Any decision taken on development plans of the town can be implemented only if:
 The President and either Secretary or Treasurer agrees
[OR]
 All three agree
The inputs are: P (denotes President), S (denotes Secretary), T (denotes Treasurer)

Output: X denotes development plan [1 indicates agreed and 0 indicates refused in all cases]

Draw the truth table for the inputs and outputs. Also, write the Boolean expression with conjunctive
operators for each of the true values (1’s) from the output column of the truth table. [5]
Question 6.
Section – B
Answer any two questions

Question 7. [10]
Design a class WordWise to separate words from a sentence and find the frequency of the vowels in each
word.
Some of the members of the class are given below:
Class name : WordWise
Data members/instance variables
str : to store a sentence
Member functions/methods
WordWise( ) : default constructor
void readsent( ) : to accept a sentence
int freq_vowel(String wd) : returns the frequency of vowels in the parameterized string
wd
void arrange( ) : displays each word of the sentence in a separate line along
with the frequency of vowels for each word by invoking the
function freq_vowel( )

Define the class WordWise giving details of the constructor( ), void readsent( ), int freq_vowel(String)
and void arrange( ). Define the main( ) function to create an object and call the functions accordingly to
enable the task. [10]
Question 8. [10]
Design a class PrimePalinGen to generate prime palindrome numbers. [A number is said to be prime
palindrome if the number is a prime as well as a palindrome number.]
Prime number is a number having only two factors i.e. 1 and itself and Palindrome number is a number
which is same as its reverse.
Example: 11 (where 11 is a prime number and a palindrome number)
Some of the members of the class are given below:
Class name : PrimePalinGen
Data members/instance variables
start : to store the start of range
end : to store the end of range
Methods/Member functions
PrimePalinGen(int a, int b) : parameterized constructor to initialize the data members
start=a and end=b
int isPrime(int i) : returns 1 if the number is prime otherwise, returns 0
int isPalin(int i) : returns 1 if the number is a palindrome otherwise, returns 0
void generate( ) : generates all prime palindrome numbers between start and end
by invoking the functions isPrime() and isPalin().

Specify the class PrimePalinGen giving details of the constructor( ), int isPrime(int), int isPalin(int)
and void generate( ). Deinfe a main( ) function to create an object and call the functions accordingly to
enable the task. [10]
Question 9 [10]
A class ArrayMax contains a square matrix which finds the largest element in each row.
Some of the members of the class are given below:
Class name : ArrayMax
Data members/instance variables
arr[ ][ ] : array to store integer elements
m : to store the order of the matrix
Member functions/methods
ArrayMax(int mm) : parameterized constructor to initialize the data member m=mm and
to declare the array
void readarray( ) : to accept the array elements
void large( ) : finds and displays the largest element in each row with an
appropriate message
void display( ) : displays the array elements in matrix form

Specify the class ArrayMax, giving the details of the constructor( ), void readarray( ), void large( ) and
void display( ). Define the main( ) function to create an object and call the functions accordingly to enable
the task. [10]
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.)

Question 10. [5]


Define a class BasePro and a derived class DervPro to find the product of two numbers.
The details of both classes are given below:
Class name : BasePro
Data members
n1, n2 : float cariables whose product is to be determined.
Member functions
void enter( ) : to enter values of n1 and n2.
void show( ) : to display the values of n1 and n2.
Class name : DervPro
Data members
result : float variable to store product member functions
void prod( ) : to accept values of n1 and n2 and to calculate their product using
the concept of inheritance.
void disp( ) : to display the values of n1, n2 and their product.

(a) Specify the class BasePro giving details of the function void enter( ) and void show( ).
(b) Using the concept of inheritance specify the class DervPro, giving details of the functions void
prod( ) and void disp( ). The main function need not be written.
Question 11. [5]

Question 12.
(a) A linked list is formed from the objects of the class: [3]
class Node
{
int info;
Node link;
}
Write an algorithm OR a Method for deleting the first node from a linked list. The method
declaration is given below:
void deletenode(Node start)
(b) Answer the following questions from the diagram of a Binary tree given below:

B C

D E

G H

(i) Write the postorder tree traversal.


(ii) Name the leaves of the tree.
(iii) Name the height of the tree.
(iv) Name the root of the tree. [2]

*****

You might also like