Isc Semester 2 Examination Specimen Question Paper Computer Science Paper 1 (Theory)
Isc Semester 2 Examination Specimen Question Paper Computer Science Paper 1 (Theory)
SECTION A -7 MARKS
Question 1
(i) The keyword used by a class to acquire the properties of an interface is: [1]
(a) import
(b) implements
(c) extends
(d) include
(ii) The ability of an object to take many forms is known as: [1]
(a) inheritance
(c) overriding
(d) polymorphism
1
(iii) int Toy(int n) [1]
{ return (n<=0)? 1: n%10 + Toy(n/10); }
With reference to the program code given above, what will the function Toy()
return when the value of n=56 ?
(a) 65
(b) 12
(c) 651
(d) 11
(iv) Write the statement in Java to extract the word “MISS” from the [1]
word “SUBMISSION”.
(v) State the principle by which the stack data structure works. [1]
(vii) Give one reason, why iteration is better than recursion. [1]
SECTION B - 8 MARKS
Question 2 [2]
Question 3 [2]
Question 4
Answer the following questions on the diagram of a Binary Tree given below:
2
(i) State the degree of the nodes C and G. Also, state the level of these nodes [2]
when the root is at level 0.
(ii) Write the pre order and post order traversal of the above tree structure. [2]
SECTION C - 20 MARKS
Each program should be written in such a way that it clearly depicts the logic of the problem.
This can be achieved by using mnemonic names and comments in the program.
(Flowcharts and Algorithms are not required.)
The programs must be written in Java.
Question 5 [6]
Methods/Member functions:
Specify the class Check giving details of the constructor, void acceptword( ),
boolean palindrome( ) and void display( ). Define the main( ) function to create
an object and call the functions accordingly to enable the task.
OR
3
(ii) Design a class Toggle which toggles a word by converting all upper case
alphabets to lower case and vice versa.
Example: The word “mOTivATe” becomes “MotIVatE”
The details of the members of the class are given below:
Methods/Member functions:
Specify the class Toggle giving details of the constructor, void readword( ),
void toggle( ) and void display( ). Define the main( ) function to create an
object and call the functions accordingly to enable the task.
4
Question 6 [6]
(i) A class Fibo has been defined to generate the Fibonacci series 0, 1, 1, 2, 3, 5,
8, 13,……. (Fibonacci series are those in which the sum of the previous two
terms is equal to the next term).
Some of the members of the class are given below:
OR
(ii) A class Gcd has been defined to find the Greatest Common Divisor of two
integer numbers. Some of the members of the class are given below:
Class name : Gcd
Data member/instance variable:
num1 : integer to store the first number
num2 : integer to store the second number
Member functions/methods:
Gcd( ) : default constructor
void accept( ) : to accept the numbers
int gcd(int x,int y) : return the GCD of the two number x
and y using recursive technique
void display( ) : displays the result with an appropriate
message
Specify the class Gcd, giving details of the Constructor, void accept( ), int
gcd(int,int), and void display( ). Define the main() function to create an object
and call the functions accordingly to enable the task.
5
Question 7 [4]
A super class Godown has been defined to store the details of the stock of a retail
store. Define a subclass Update to store the details of the items purchased with the
new rate and update the stock. Some of the members of both the classes are given
below:
Class name : Godown
Data members/instance variables:
item : to store the name of the item
qty : to store the quantity of an item in stock
rate : to store the unit price of an item
amt : to store the net value of the item in stock
Member functions/methods:
Godown( …) : parameterized constructor to assign value to
the data members
void display( ) : to display the stock details
Class name : Update
Data members/instance variables:
pur_qty : to store the purchase quantity
pur_rate : to store the unit price of the purchased item
Member functions / methods
Update(…) : parameterized constructor to assign values to
the data members of both the classes
void update( ) : to update the stock by adding the previous
quantity by the purchased quantity and
replace the rate of the item if there is a
difference in the purchase rate. Also update
the current stock value as:
(quantity * unit price )
void display( ) : to display the stock details before and
after updating
Assume that the super class Godown has been defined. Using the concept of
inheritance, specify the class Update giving details of the constructor, void update
( ) and void display( ).
The super class, main function and algorithm need NOT be written.
6
Question 8 [4]
A Queue is a linear data structure in which the operations are performed based on
FIFO (First In First Out).
Define a class Queue with the following details:
Member functions/methods:
Specify the class Queue giving the details of void add_dat(int) and int pop_dat( ).
Assume that the other functions have been defined.
The main( ) function and algorithm need NOT be written.
7
Answers
Section-A
Answer 1.
(i) (b) implements
(ii) (d) polymorphism
(iii) (b) 12
(iv) “SUBMISSION”.substring(3,7)
(v) Last In First Out (LIFO)
(vi) FANA
(vii) Recursion takes more memory and more time to execute than its iterative counterpart.
Section-B
Answer 2.
Direct recursion Indirect recursion
In this case the function calls itself within In this case function A calls function B and
its body. in turn, function B calls function A again.
Answer 3.
ABCD/+*EF/–
Answer 4.
(i) Degree of C
= 2 Degree
of D = 0
Level of C =
1 Level of D
=2
(ii) Pre order traversal: A B D C E
F G Post order traversal: D B
EGFCA
Answer 5.
(i) import
java.util.Scanner;
class Check
{
String wrd;
int len;
public Check( )
{
wrd=””;
len=0;
}
public Toggle( )
{
str=newstr=“
”; len=0;
}
public Update(int ai, int qt, double rt, double am, int pqt, double prt)
{
super(ai, qt, rt, am);
pur_qty=pqt;
pur_rate=prt;
}