Computer Science Paper 4
Computer Science Paper 4
Question 1.
(i) What is Recursion in Java?
(a) Recursion is a class.
(b) Recursion is a process of defining a method that calls other methods repeatedly
(c) Recursion is a process of defining a method that calls itself repeatedly
(d) Recursion is a process of defining a method that calls other methods which in turn call
again this
method
(ii) Which of the following statement is incorrect about String?
(a) String is a class.
(b) Strings in java are mutable.
(c) Every string is an object of class String
(d) Java defines a peer class of String, called StringBuffer, which allows string to be altered
(iii) int compute (int n)
{
if (n = = 1)
return 1;
return compute (n– 1);
}
With reference to the program code given above, what will the function compute() returns
when the value of n=5?
(e) 0 (g) 120
(f) 1 (h) Error is the code
(iii) Write the statement in Java to swap the first letter with the last letter for the given string
“WELCOME”.
(iv) What is recursive data structure?
(v) What is the output of the statement given below?
System.out.print(“INDIA”.substring(0,2)+
“INDIA”.substring(4));
(vi) Give one point of difference between interface and abstract class.
Question 2.
Define:
(i) Encapsulation
(ii) Inheritance
Question 3.
Convert the following infix notation to postfix notation:
(A+B)*(C–D)/E^2
Question 4.
Answer the following questions on the diagram of a Binary Tree given below:
A
B C
D E I
F J G
Question 5.
A class Composite contains a two dimensional array of order [m x n]. The maximum value
possible for both ‘m’ and ‘n’ is 20. Design a class Composite to fill the array with the first (m x n)
composite numbers in column wise. The details of the members of the class are given below:
Class name : Composite
Member functions/methods:
Composite(int mm, int nn ) : to initialize the size of the matrix m=mm and n=nn
void fill ( ) : to fill the elements of the array with the first (m × n)
composite numbers in column wise
Specify the class Composite giving details of the constructor(int,int), int isComposite(int), void
fill( ) and void display( ). Define a main( ) function to create an object and call the functions
accordingly to enable the task.
Question 7.
A class Personal contains employee details and another class Retire calculates the employee’s
Provident Fund and Gratuity. The details of the two classes are given below:
Class name : Personal
Instance variables:
Name : stores the employee name
Pan : stores the employee PAN
basic_pay : stores the employee basic salary ( in decimals )
Member methods:
Personal(….) : parameterized constructor to assign value to data
members
void display( ) : to display the employee details
Class name : Retire
Instance variables:
yrs : stores the employee years of service
pf : stores the employee provident fund amount (in decimals)
grat : stores the employee gratuity amount (in decimals)
Member methods:
Retire (…….) : parameterized constructor to assign value to data
members of both the classes.
void provident( ) : calculates the PF as (2% of the basic pay) * years of service.
void gratuity( ): calculates the gratuity as 12 months’ salary, if the years of
service is > 10 years else the gratuity amount is nil.
void display ( ) : Display the employee details along with the Provident
Fund and gratuity amount.
Specify the class Personal giving details of the constructor and member functions void
display( ). Using the concept of inheritance, specify the class Retire giving details of
constructor, and the member functions void provident( ), void gratuity( ) and the void
display( ).
The super class, main function and algorithm need NOT be written
Question 8.
(a) Given the Boolean function: F(A, B, C, D) = Σ (1, 6, 7, 8, 9, 10, 14, 15).
Using Karnaugh’s map to reduce the given function F using SOP form. Draw a logic gate diagram for the
reduced SOP form. You may use gates with more than two inputs. Assume that the variables and their
complements are available as inputs.
Q. The national college of Journalism is offering courses in three different categories of journalism, which
are the prints, the web & the broadcasting media.
A student is eligible to apply, if he/she satisfies any one of the following conditions.
The student is a graduate in any discipline with an aggregate percentage of 75 or above & with
record of literary skills.
OR
The student is a graduate in Mass Communication with aggregate percentage of 75 or above
Question 9
The following function trial() & perform() are a part of some class. Answer the following parts given
below. Show the dry run/working.
static int trial(int n)
{
if(n==1)
return 2;
else if (n==2)
return 3;
else
return trial(n-2)+trial(n-1);
}
static void perform(int p)
{
int x;
for(int i=1; i<=p; i++)
{
x=trial(i);
System.out.println(x+" ");
}
}
public static void main(String args[])
{
System.out.println(trial(4));
perform(5);
}
(i) what will the function trial() return when the value of n is 4?
(ii) what will the function perform () return when the value of p is 5?
(iii) in one line state what the function trial() is doing, apart from recursion?