You are on page 1of 2

UNIT TEST – 4

Class XII (ISC)


COMPUTER SCIENCE – SET A

Time: 40 minutes Maximum Marks: 15


Instructions:
 Attempt all questions.
 The intended marks for the questions or parts of questions are given in brackets [ ].

Question 1
A super class Number is defined to calculate the factorial of a number. Define a sub class Series to
find the sum of the series S = 1! + 2! + 3! + .......+ n! The details of the members of both the classes
are:
Class name Number
Data members/instance variables:
n to store an integer
Member functions/methods:
Number(int nn) parameterized constructor to initialize n
int factorial(int a) returns the factorial of a number
void display( ) displays the data
Class name Series
Data members/instance variables:
sum to store the sum of the series
Member functions/methods:
Series(...) parameterized constructor to initialize data
members of both the classes
void calsum( ) : calculates the sum of the given series
void display( ) displays the data members of the classes

Assume that super class Number has been defined. Using the concept of inheritance, specify the
sub class Series giving details of the constructor and methods. You need not write the main ( )
function. [5]

Question 2
Bag is an entity which can store a maximum of 20 items. The bag enables the user to add or remove
items from one end only. The details of the class are given below:
Class name Bag
Data members/instance variables:
item[ ] array to hold the names of the items
cap integer to store the maximum capacity of the array
top integer to point to the index of the topmost element
Member functions/methods:
Bag (int c) constructor to assign cap to c, top to -1 and create the
Bag
void pushItem(String value) adds an item on the top of Bag, if possible, otherwise
outputs a message “Bag is full”
char popItem( ) removes and returns the item from the top of the bag if
possible, otherwise outputs a message “Bag is empty”
and returns “$$”

Page 1 of 2
Specify the class Bag giving details of the constructor and methods. The main function need not be
written. [5]

Question 3
a) Convert the following infix expression into prefix form: (A + B  C)  (E  F / H) + J [2]
b) Answer the following question from the binary given below:

i) Write the in-order traversal of the above tree structure. [1]


ii) State the degrees of E and H. [1]
iii) Mention the internal nodes of the right sub tree. [1]

Page 2 of 2

You might also like