Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

Computer Science Paper 4

The document consists of a series of questions related to computer science concepts, specifically focusing on Java programming, recursion, data structures, and Boolean functions. It includes questions about recursion, string handling, class design, binary trees, employee management systems, and Karnaugh maps. Additionally, it covers topics such as encapsulation, inheritance, and converting infix notation to postfix notation.

Uploaded by

Ashish Rajput
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Computer Science Paper 4

The document consists of a series of questions related to computer science concepts, specifically focusing on Java programming, recursion, data structures, and Boolean functions. It includes questions about recursion, string handling, class design, binary trees, employee management systems, and Karnaugh maps. Additionally, it covers topics such as encapsulation, inheritance, and converting infix notation to postfix notation.

Uploaded by

Ashish Rajput
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

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

(i) Identify internal and external nodes of the tree.


(ii) Write down the post order traversal of the tree.

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

Data members/instance variables:

arr[ ] [ ] : stores the composite numbers column wise

m : integer to store the number of rows

n : integer to store the number of columns

Member functions/methods:

Composite(int mm, int nn ) : to initialize the size of the matrix m=mm and n=nn

int isComposite( int p ) : returns 1 if number is composite otherwise returns 0

void fill ( ) : to fill the elements of the array with the first (m × n)
composite numbers in column wise

void display( ) : displays the array in a matrix form

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.

(b) Given X (A,B,C,D) =Π (0, 2, 3, 4, 5, 11, 12, 13)


Using Karnaugh’s map to reduce the given function X using POS form. Draw a logic gate diagram for the
reduced POS form. You may use gate 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

The inputs are:


A Graduate in any discipline.
B Graduate in Mass Communication.
C Aggregate percentage of 75 & above.
D Record of literary skills.
(In all of the above cases 1 indicates yes and 0 indicates no)
Output: X – Denotes the win/draw criteria [1 indicates win/draw and 0 indicates defeat in all cases.]
(a) Draw the truth table for the inputs and outputs given above and write the SOP expression for X (A, B,
C, D).
(b) Reduce X (A, B, C, D) using Karnaugh’s Map.
Draw the logic gate diagram for the reduced SOP expression for X (A, B, C, D ) using AND & OR gates. You
may use gates with two or more inputs. Assume that the variable and their complements are available as
inputs.

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?

You might also like