CMS FIRSTComparative 2020-2021 (2)
CMS FIRSTComparative 2020-2021 (2)
(b) The following is a function/method of some class. Give the output of the function demo( ).
Show the dry run/working. [3]
void demo( )
{
String y = “SCROLL”;
int x = 0;
char c[ ] = new char[y.length( )];
for(int j = 0; j < c.length; j++)
c[j] = y.charAt(j);
while(true)
{
if(x < c.length/2)
{
char t = c[x];
c[x] = c[c.length – x – 1];
c[c.length – x – 1] = t;
x++;
System.out.println(c);
}
else break;
}
}
C–6 (2)
Question 5
(a) A person is allowed in a reserved coach in a train, if he/she satisfies the following
conditions:
The person has a valid reservation ticket and a valid ID proof.
OR
he person does not have a valid reservation ticket, but holds a valid pass issued by
the Railway department and has a valid ID proof.
OR
he person is disabled and holds a valid Railway pass issued by the Railway
department and has a valid ID proof.
The inputs are:
INPUTS:
R: the person has a valid reservation ticket
P: the person has a valid pass issued by the Railway department
D: the person has a valid ID proof
H: the person is a disabled person
(In all the above cases 1 indicates yes, 0 indicates no.)
OUTPUT: T- Denotes allowed to travel. (1 indicates yes, 0 indicates no in all the cases.)
Draw the truth table for the given inputs and outputs and write the POS expression for
T(R, P, D, H). [5]
(b) Verify using Boolean laws whether ABC = A.B.C + A.B.C + A.B.C + A.B.C
Mention laws at each step. [3]
(c) Using a truth table state whether the following expression is a Tautology, Contradiction,
or a Contingency. (P Q) (P ˅ Q) [2]
Question 6
(a) State the difference between a decoder and a multiplexer. Draw the truth table
and logic circuit for a 3 to 8 decoder. [5]
(b) Simplify the expression (A + B) . (B + C.D) using Boolean laws. [3]
(c) Draw the logic circuit diagram for (P + Q) . (P + Q) using NAND gates only. [2]
Question 8
The distance and the coordinates of the midpoint between two points (x1, y1) and (x2, y2) are
given as:
distance d x1 x 2 y1 y 2
2 2
coordinate x ( x1 x 2 ) / 2 and y ( y1 y 2 ) / 2
A class Point represents a point on a 2D plane. The details of the class are:
Class name : Point
Data member / instance variable:
cord[ ] : stores the x and y coordinates of a point.
Member functions / methods:
Point(double m, double n) : constructor to assign m to x coordinate and n to y
coordinate
void display( ) : displays the coordinates of a point
void distance(Point B) : displays the distance between Point B and the current
Point object
void midpoint(Point A, Point B) : stores the coordinates of the midpoint between Point A
and Point B, in the current Point object.
Specify the class Point giving details of the constructor and methods. Write the main( )
method to create objects of the class and call the methods accordingly. [10]
Question 9
A class Magic enables the user to accept a sentence and print its Magic words. A Magic
word is one which has consecutive letters within itself at any position. For example the
word MYSTERY has consecutive letters ST and hence is a magic word.
Class name : Magic
Data member / instance variable:
str : to store a sentence.
Member functions / methods:
Magic( ) : constructor
void input( ) : accepts a sentence in UPPER case
boolean check(String n) : checks and returns true if the word in n is a Magic
word otherwise returns false
void display( ) : using the method check( ) displays all the Magic words
of the sentence.
Specify the class Magic giving details of the constructor and methods. Define the
main( ) method to create an object of the class and call the functions accordingly. [10]
C–6 (4)
SECTION C [10 marks]
Answer any two questions.
Each program/algorithm should be written in such a way that it clearly depicts the logic of the
problem step wise. This can be achieved by using pseudo codes.
Flowcharts are not required.
Question 10
Write an algorithm to store 10 numbers in a single dimensional array and print the numbers
in sorted (ascending order) form using insertion sort technique. [5]
Question 11
A library issues books on rental basis at a 2% charge on the cost price of the book per day.
As per the rules of the library, a book can be retained for 7 days without any fine. If the
book is returned after 7 days, a fine will also be charged for the excess days as per the chart
given below:
Number of excess days Fine per day ( ` )
up to 5 2.00
above 5 up to 10 3.00
above 10 days 5.00
Design a class Library to perform the task. Details of the class are given below:
Class name : Library
Data members / instance variables:
name : name of the book
author : author of the book
p : price of the book in decimals
d : number of days taken in returning the book
f : stores the fine.
Member functions / methods:
Library(…) : parameterized constructor to assign values to data
members
void fine( ) : calculates the fine for the excess days
void display( ) : displays the book details along with the number of
days, fine and the total amount to be paid
Total amount is calculated as:
(2% of price of book total no. of days) + fine.
Specify the class Library giving details of void fine( ) and void display( ) only.
Assume that the constructor is already defined. You need not write the main( )
function. [5]
Specify the class Check and write the methods int sumalp(String) and void display( )
only. You need not write rest of the methods and main( ) function. [5]
C–6 (6)