You are on page 1of 7

First Model Exam 2021-22 – Semester 2

COMPUTER SCIENCE
PAPER 1
(THEORY)
Maximum Marks: 35
Time allowed: One and a half hours
Candidates are allowed an additional 10 minutes for only reading the paper.
They must NOT start writing during this time.
----------------------------------------------------------------------------------------------------------------
Answer all questions in Section A, Section B and Section C.
While answering questions in Sections A and B, working and reasoning may be indicated
briefly.
The intended marks for questions or parts of questions are given in brackets. [ ]
All working, including rough work, should be done on the same sheet as the rest of the answer.

SECTION A (7 MARKS)

Question 1

(i) Which of this keyword must be used to invoke a base class constructor? [1]
a) super
b) this
c) super()
d) this()
(ii) Which polymorphism concept is applied to inheritance relationship in java
programming? [1]
a) Method overloading
b) Constructor overloading
c) Method overriding
d) None

(iii) int recursive(int p, int q){ [1]


return(( p==0)? q: recursive(q%p,p));
}

With reference to the program code given above what will the function recursive()
return when the value of q=3 and p=27?
a) 1
b) 3
c) 0
d) 27
(iv) Name the data type that is used by operating system to manage the Recursion
in Java? [1]
(v) What is the output of the statement given below: [1]
System.out.println(“Computer Knowledge”.substring(0,8).concat(“Computer
Applications”.substring(9)));
(vi) Write a Java statement to check if the second character of a string str is in
upper case. [1]
(vii) Name the principle by which interruptions are handled by operating systems. [1]
SECTION B (8 MARKS)

Question 2 [2]
A recursive method should have a base case. Explain the reason.

Question 3 [2]

Convert the following infix notation to Reverse Polish Notation: [2]

A *N-T+H/E/R

Question 4

Answer the following questions on the diagram of a Binary Tree given below:

(i) Draw the left sub tree. [2]


(ii) Write inorder and preorder (Polish Notation) of the above tree structure. [2]
SECTION C (20 MARKS)

Question 5 [6]

(i) A class Order has been defined to arrange all the letters of string in an
alphabetical
order. Now, insert the missing letters in the sorted string to complete all the
letters between first and last characters of the string.
Sample Input:
computer
Alphabetical order:
cemoprtu
Sample Output:
cdefghijklmnopqrstu
Some of the members of the class are given below:

Class name : Order


Data members/instance variables:
str : to store a word.
apstr : to store the alphabetically arranged word.
newstr : to store the new word.
l : to store the length of the word.
Member functions/methods :
Order () : default constructor to initialize the data
members with legal initial values.
void getStr() : to accept the String
void alphabeticalStr() : to arrange all the letters of the string in the
alphabetical order.
void compeleteStr() : to complete the string by inserting the
missing
alphabets in the order.
void display() : displays the alphabetically arranged string
and the completed string.
Specify the class Order giving details of the constructor, void getStr(), void
alphabeticalStr(), void compeleteStr() and void display(). Define the
main() function to create objects and call the functions accordingly to enable
the task.
OR

(ii) A class Arrange has been defined to arrange all the letters of string such that
all the lower case characters are followed by the upper case characters.
Sample Input:
Computer Science
Sample Output:
omputercienceCS
Some of the members of the class are given below:

Class name : Arrange


Data members/instance variables :
wrd : to store a word.
len : to store the length
Member functions/methods :
Arrange () : default constructor to initialize the data
members with legal initial values.
void feedWord() : to accept the word in both cases.
void arrangeWord() : to arrange all the letters of the word in the
pattern given.
void display() : displays the word.
Specify the class Arrange giving details of the constructor, void
feedWord(), void arrangeWord() and void display(). Define
the main() function to create objects and call the functions accordingly to
enable the task.

Question 6 [6]

(i) The factorial of a number 'n' is calculated as:


n!=n"(n-1)*(n-2)*(n-3)* ………. * 1.
A class Factorial is declared with the following details:
Class name : Factorial
Data members/Instance variables:
n : To store a number greater than zero.
f : To store the factorial of a number entered by
the user.
Member functions/methods:
Factorial() : A constructor to assign 0 to n.
int fact(int num) : To find and return the factorial of num
(num>0) using recursive technique
otherwise, it should return 1 if num=0.
void get(int x) : To assign x to n and by invoking function
fact() store factorial of n into f. Display the
result with a suitable message.
Specify the class Factorial giving details of the constructor, int fact(int
num) and void get(int x). Define the main() function to create objects and
call the functions accordingly to enable the task.

OR

(iii) A happy number is a number in which the eventual sum of the square of the
digits of the number is equal to 1.
Example: 28 = (2)2 + (8)2 = 4 +64 +68
68 = (6)2 + (8)2 = 36 +64 = 100
100 = (1)2 + (0)2 + (0)2 = 1+0+0 =1
Hence, 28 is a happy number.
Example : 12 =(1)2 + (2)2 =1+4 = 5
Hence, 12 is not a happy number.
Design a class Happy to check if a given number is a happy number. Some of
the members of the class are given below.
Class name :Happy
Data members / instance variables :
n :stores the number
Member functions :
Happy() :constructor to assign 0 to n
void getnum(int nn) : to assign the parameter value to the number
n = nn
int sum sq digits(int x) : returns the sum of the square of the digits of
the number using the recursive technique.
void ishappy() : checks if the given number is a happy
number by calling function
sum_sq_digits(int) and displays an
appropriate message
Specify the class Happy, giving details of the constructor(), void getnum(int), and
int sum_sq_di(int) and void ishappy(). Also define a main() function to create an
object and call the methods to check number.

Question 7 [4]

A super class Employee has been defined to store the details of an employee. Define
a subclass Overtime to calculate the amount paid for working more than the normal
hours.
The details of the classes are given below:
Class name : Employee
Data members/instance variables :
empc : To store employee code.
bpy : To store basic salary in double type.
Member functions/methods :
Employee() : Constructor to assign 0 to empc and bpay.
Employee (int c, double b) : Constructor to assign 'c’ to empc and 'b'
bpay.
void show() : To display empc and bpay after performing
the task.
Class name : Overtime
Data members/instance variables:
nd : To store number (int) of days extra worked.
rate : To store rate (float) per day.
Member functions/methods :
Overtime(int n, float r) : Constructor to assign 'n' to nd and 'r' to rate.
double calculate() : To calculate gross salary (basic salary +
salary paid for extra hours).
void show() : To display the amount paid for extra hours.

Assume that the super class Employee has been defined. Using the concept of
inheritance, specify the class Overtime giving the details of the constructor,
double calculate() and void show() functions. The main() function need not be
written.
Question 8 [4]

WordPile is an entity which can hold maximum of 20 characters . Restriction is


that characters can be added or removed from only one end . Some of the
members of the class are given below :

Class Name : WordPile


Data Members/ Instance variables:
ch[ ] : character array to hold character elements
capacity : Integer variable to store maximum capacity
top : to point to the index of topmost element
Methods/Member Functions :
WordPile(int cap) : Constructor to initialise data members
capacity to cap and top to -1.
void pushChar(char v) : adds character to the top of the WordPile if
possible otherwise outputs a
message "Word Pile is full".
char popChar() : Returns the deleted character from WordPile
if possible otherwise returns "//".

Specify class WordPile giving details of the constructor and member functions.
The main function and algorithm need not be written .
***********************

You might also like