Only
computer programming related question and answers are posted here.
Question
2.
a) Differentiate
between throw and throws with respect to exception handling. [ 2 ]
Ans: throw clause is used to throw manually created
exception to the caller of the function and throws clause throws the java
created exception to the caller of the function.
b) Convert the following
infix notation to its postfix form:
E*(F / (G-H) * I) + J [
2 ]
Ans: E F G H - /I * *
J +
c)
|
Write the algorithm for push operation (to add elements ) in
an array based stack.
|
[ 2
]
|
|
|
d)
|
Name the file stream classes to :
|
|
|
|
|
i)
|
Write data to a file in binary form.
|
[ 2
]
|
|
|
ii)
|
Read data from a file in text form.
|
|
e)
A square matrix M[][] of size 10 is stored in the memory
with each element requiring 4 bytes of storage. If the base address at M[0][0]
is 1840, determine the address at M[4][8] when
the matrix is stored in row major wise. [ 2 ]
Question 3.
a)
The
following function Recur() is a part of some class. What will be the output of
the function Recur() when the value of n is equal to 10. Show the dry
run/working.
public
void Recur(int n)
{
if(n>1)
{
System.out.print(n+"
"); if(n%2!=0)
{
n=3*n+1;
System.out.print(n+" ");
}
1
}
}
b)
The
following function is a part of some class. Assume n is a positive integer.
Answer the given questions along with dry run / working.
int
unknown(int n)
{
int
i,k; if(n%2==0)
{
i=n/2;
k=1;
}
else
{
k=n;
n--; i=n/2;
}
while(i>0)
{
k=k*i*n; i--;
n--;
}
return
k;
}
Section B
Answer any
2 questions.
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.
Question 8.
An emirp number is a number which is prime backwards and forwards.
Example: 13 and 31 are both prime numbers. Thus 13 is an emirp number.
Design a class Emirp to check if a given number is Emirp number or nt.
Some of the members of the class are given below:
Class Name
|
:
|
Emirp
|
|
Data Members
|
|
|
|
n
|
:
|
stores
the number
|
|
rev
|
:
|
stores
the reverse of the number
|
|
f
|
:
|
stores the divisor
|
|
Member functions
|
|
|
|
Emirp(int nn)
|
:
|
to assign
n=nn, rev=0, and f=2
|
|
int isprime(int x)
|
:
|
check if
the number is prime using the
|
|
recursive
|
|
technique
and return 1 if prime otherwise
|
|
|
|
|
|
|
|
return 0.
|
|
void isEmirp()
|
:
|
reverse the given number and check if both
|
|
the
|
|
original number ad the reverse number are
|
|
|
|
|
|
|
|
prime, by invoking the
function isprime(int)
|
|
|
|
and
display the result with an appropriate
|
|
|
|
message.
|
|
|
|
4
|
|
Specify the class Emirp giving details of
the constructor(int), int isprime(int) and void isEmirp(). Define the main
function to create an object and call the methods to check for Emirp number.
[ 10]
Question 9.
Design a class Exchange to accept a sentence and interchange the first
alphabet with the last alphabet for each word in the sentence, with single
letter word remaining unchanged. The words in the input are separated by a
single blank space and terminated by a full stop.
Example:
|
Input:
|
It is a warm day.
|
|
|
Ouput:
|
tI si a marw yad
|
|
Some of the data members and member functions
are given below:
|
|||
Class Name
|
|
:
|
Exchange
|
Data members
|
|
|
|
sent
|
|
:
|
stores
the sentence
|
rev
|
|
:
|
to store
the new sentence
|
size
|
|
:
|
stores
the length of the sentence
|
Member functions
|
|
|
|
Exchange()
|
|
:
|
default
constructor
|
void readsentence()
|
:
|
to accept
the sentence
|
|
void exfirstlast()
|
:
|
extract each word and interchange the first and last
|
|
|
|
|
alphabet
of the word and form a new sentence.
|
void display()
|
|
:
|
display
the original sentence along with the new
|
|
|
|
changed
sentence.
|
Specify the class
Exchange giving details of the constructor(), void readsentence(), void
exfirstlast() and void display(). Define the main() function to create an
object and call the functions accordingly to enable the task.
[ 10]
Question 10.
A class Matrix contains a two dimensional integer array of order [ m x
n ]. The maximum value possible for both m and n is 25. Design a class Matrix
to find the difference of the two matrices. The details of the members of the
class are given below:
Class name
|
:
|
Matrix
|
|
Data members
|
|
|
|
arr[][]
|
:
|
stores
the matrix element
|
|
m
|
:
|
integer
to store the number of rows
|
|
n
|
:
|
integer to store the number of columns
|
|
Member functions:
|
|
|
|
Matrix(int mm, int nn)
|
:
|
to
initialize the size of the matrix m=mm
|
|
and
|
|
n=nn
|
|
|
|
|
|
void fillarray()
|
:
|
to enter
the elements of the matrix
|
|
Matrix
SubMat(Matrix A)
|
:
|
subtract the current object
from the matrix
|
|
of
|
|
|
|
5
resulting
object.
void display() : display the matrix elements.
Specify the class Matrix giving details of the constructor(int,int),
void fillarray(),Matrix SubMat(Matrix) and void display(). Define the main()
function to create an object and call the functions accordingly to enable the task.
[ 10]
Section C Answer any 2 questions.
Each
program/algorithm should be written in such a way that it clearly depicts the
logic of the problem step wise. This can also be achieved by using comment in
the program and mnemonic names or pseudo codes for algorithms.
(Flowcharts
are not required)
The
programs must be written in Java.
The
algorithm must be written in general standard form wherever required/specified.
Question 11.
A super
class Perimeter has been defined to calculate the perimeter of a parallelogram.
Define a sub class Area to compute the area of the parallelogram by using the
required data members of the super class. The details are given below:
Class name
|
:
|
Perimeter
|
|
Data Members
|
|
|
|
a
|
:
|
to store
the length in decimal
|
|
b
|
:
|
to store
the breadth in decimal
|
|
Member functions:
|
|
|
|
Perimeter(…)
|
:
|
parameterized constructor to assign values to data
|
|
|
|
Members
|
|
double Calculate()
|
:
|
calculate
and return the perimeter of a
|
|
parallelogram as
|
|
2
*(length +breadth)
|
|
|
|
|
|
void show()
|
:
|
to
display the data members along with the
|
|
perimeter
|
|
of the
parallelogram.
|
|
|
|
|
Class name
|
:
|
Area
|
Data Members
|
|
|
h
|
:
|
to store
the height in decimal
|
b
|
:
|
to store
the area of the parallologram
|
Member functions:
|
|
|
Area(…)
|
:
|
parameterized constructor to assign values to data
|
|
|
Members of both classes.
|
void doarea()
|
:
|
computes
the area( breadth * height).
|
6
:
|
to
display the data members of both the classes
|
|
|
along
|
|
with the area and perimeter of the parallelogram.
|
|
|
|
|
Specify the class Perimeter giving details of the constructor(…),
double Calculate() and void show(). Using the concept of inheritance, specify
the class Area giving details of he constructor(…), void doarea() and void
show(). The main function and algorithm need not be written.
[ 10 ]
Question 12.
A doubly queue is a linear data structure which enables the user to
add and remove integers from either ends, i.e. from front or rear. Define a
class Dequeue with the following details:
Class name
|
:
|
Dequeue
|
|
Data members
|
|
|
|
arr[]
|
:
|
array to
hold upto 100 integer elements
|
|
lim
|
:
|
stores
the limit of the dequeue
|
|
front
|
:
|
to point
to the index of front end
|
|
rear
|
:
|
to point
to the index of rear end
|
|
Member function
|
|
|
|
Dequeue(int l)
|
:
|
constructor
to initialise the data members lim=l;
|
|
|
|
front=rear=0
|
|
void addfront(int val)
|
:
|
to add integer from the front if possible else display
|
|
the
|
|
message
(“Overflow from front”)
|
|
|
|
|
|
void addrear(int val)
|
:
|
to add
integer from the rear if possible else display
|
|
the
|
|
message
(“Overflow from rear”)
|
|
|
|
|
|
int popfront()
|
:
|
returns
element from front, if possible otherwise
|
|
|
|
returns
-9999.
|
|
int poprear()
|
:
|
returns
element from rear, if possible otherwise
|
|
|
|
returns
-9999.
|
|
Specify class Dequeue giving details of the constructor(), void
addfront(int), void addrear(int), int popfront(), and int poprear().
The main function and algorithm need not be
written.
|
[ 10 ]
|
Question 13.
a)
A linked list is
formed from the objects of the class, class Node
{
int item; Node
next;
}
7
{
for(int
q=0;q
{
Sequence
of statements
}
}
for(int
r=0;r
{
Sequence
of statements
}
[ 2 ]
ii) How
would the complexity change if all the loops went up to the same limit N?
c)
Answer
the following questions from the diagram of the binary tree given below:
No comments:
Post a Comment