0% found this document useful (0 votes)
25 views8 pages

Set 3

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 8

COMPUTER SCIENCE

SET- 3

PART- 1

(THEORY)
Question 1

a) Using a truth table. verify the following expression:


X+( Y+Z)=(X+Y)+Z [2]
Also state the law.
b) Given, F (X, Y, Z) = (X' + y') . ( y + Z')

write the function in canonical product-of-sum form. [2]

c) Draw the truth table and logic circuit for a 2-input XNOR gate. [2]
d) Find the complement of the following expression: [2]
X' +XY'
e) If (X Y ) then write its: [2]
(i) Converse
(ii) Contra positive

Question 2

a) Differentiate between the keywords extends and implements. [2]


b) State how a binary tree is a recursive data structure. [2]
c) A matrix B[ I 0][7] is stored in the memory with each element requiring 2
bytes of storage. If the base address at B [x] [1] is 10] 2 and the address
at B [7][3 J is 1060, determine the value 'x' where the matrix is stored in
Column Major wise.
d) Convert the following infix notation to its postfix form: [2]
A+( (B+C) + (O+E) * F ) / G
e) What is a constructor? State one difference between a constructor and
any other member function of a class.

Question 3
a) The following function is a part of some class which computes and sorts
an array arr[ ] in ascending order using the bubble sort technique. There
are some places in the code marked by ?l '!, ?2?, ?3?, ?4?, ?S? which
must be replaced by a statement / expression so that the function works
properly:
Void bubblesort( i nt arr[ ])
{
int i, .j, k, tmp:
for(i= 0: ?l?; i++)
{
for(j = 0; ?2?; j++)
{
if(aJT[j] > ?3?)
{
tmp = arr[j]:
?4? = arr[j+ 1];
arr[j+1] = ?5?
}
}
}
}
(i) What is the expression or statement at ?1 ? [1]
(ii) What is the expression or statement at ?2? [1]
(iii) What is the expression or statement at ?3? [1]
(iv) What is the expression or statement at ?4? [1]
(v) What is the expression or statement at ?5? [1]
b) The following function witty( ) is a part of some class. What will be the
output of the function witty() when the value of n is "SCIENCE" and the
value or p is 5. Show the dry run I working:
void witty(String n, int p)
{
If (p<0)
System.ollt.printlnC");
else
{ System.out.println(n.charAt(p) + , .. " );
witty(n, p-l);
System.out.print(n.charAt(p ));
}
}
Question 6
a) Verify algebraically if,
X'Y'Z' + X'Y'Z + X'YZ + X'YZ' + XY'Z' + XY'Z = X'+Y' [2]
b) Represent the Boolean expression X+YZ' with the help of NOR gates [2]
only.
c) Define the terms Contingency, Contradiction and Tautology. [3]
d) Consider the following truth table where A and B are two inputs and X is
the output:
A B X
0 0 0
0 1 1
1 0 1
1 1 1
(i) Name and draw the logic gate for the given truth table. [2]
(ii) Write the POS of X(A,B). [1]

Question 7

a) Define Multiplexer and state one of its uses. Draw the logic
diagram for a 4: 1 Multiplexer. [4]
b) State how a Half Adder is different from a Full Adder. Also give
their respective uses. [3]
c) Minimize the following expression using Boolean laws:
Q . ( Q' + P) . R .( Q + R )
Also draw the logic gate for the reduced expression.

Question 8

A class Combine contains an array of integers which combines two arrays into
a single [101 array including the duplicate elements, if any, and sorts the
combined array. Some of the members of the class are given below:

Class name Combine


Data members / instance variables:

Com[ ] integer array

Size size of the array

Member functions/methods:

Combine (int nn) : parameterized constructor to assign size = nn

void inputarray( ) : to accept the array elements

void sort( ) :sorts the elements of combined array in

:ascending order using the selection sort

technique.

void mix(Combine A, Combine B) : combines the parameterized object arrays

and stores the result in the current object array

along with duplicate elements, if any

void display( ) :displays the array elements

Specify the class Combine giving details of the constructor( int ), void
inputarray( ), void sort(). void mix(Combine, Combine) and void display( ) .
Also define the main() function to create an object and call the methods
accordingly to enable the task.

Question 9

Design a class Vowel Word to accept a sentence and calculate the frequency of
words that (101 begin with a vowel. The words in the input string are
separated by a single blank space and tenninated by a full stop. The description
of the class is given below:

Class name Vowel Word

Data members / instance variables:

Str :to store a sentence


Freq :store the frequency of the words
beginning with a vowel

Member functions:

Vowel Word( ) :constructor to initialize data members


to legal initial value

void readstr() :to accept a sentence

void fre- vowel( ): counts the frequency of the words that

begin with a vowel

void display( ) to display the original string and the

frequency of the words that begin with a

vowel.

Specify the class VowelWord giving details of the constructor(), void readstr(),
void freq_ vowel( ) and void display( ). Also define the main( ) function to
create an object and call the methods accordingly to enable the task.

Question10

A happy number is a number in which the eventual sum of the square of the
digits of the number is equal to 1. [10]

Example: 28 =(2)2 +(8)2 =4+64=68

68=(6)2+(8)2=36+64=100

100=(1)2+(0)2+(0)2=1+0+0=1

Hence, 28 is a happy number.

Example: 12 =(1)2+(2)2=1+4=5

Hence, 12 is not a happy number.

Design a.class Happy to check if a given number is a happy number. Some of


the members of the class are given below:
Class name :Happy

Data members/instance variables: : stores the number

Member functions:

Happy( ) constructor to assign 0 to n

void getnum(int nn) to assign the parameter value to the number n


= nn

int sum_sCLdigits(int x) returns the sum of the square of the

digits of the number x, using the

recursive technique

void ishappy( ) checks if the given number is a happy

number by calling the function

sum_sq_digits(int) and displays an

appropriate message

Specify the class Happy gIvmg details of the constructor( ), void getnum(int),
int sum_sq_digits(int) and void ishappy( ). Also define a main( ) function to
create an object and call the methods to check for happy number.

Question 12

A super class Detail has been defined to store the details of a customer. Define
a ItO] sub class Bill to compute the monthly telephone charge of the customer
as per the chart given below: [10]

NUMBER OF CALLS RATE


1-100 Only rental charge
101-200 60 paisa per call + rental charge
201 -300 80 paisa per call + rental charge
Above 300 1 rupee per call + rental charge

The details of both the classes are given below:


Class name Detail

Data members / instance variables:

name : to store the name of the customer

address : to store the address of the customer

teLoo : to store the phone number of the

:customer

rent : to store the monthly rental charge

Member functions:

Detail( ... ) parameterized constructor to assign

values to data members

void show() to display the details of the customer

Class name Bill

Data members /instance variables:

n to store the number of calls

amt to store the amount to be paid by the

customer.

Member functions:

Bill( ... ) parameterized constructor to assign

values to data members of both classes

and to initialize amt = 0.0

void cal() calculates the monthly telephone

charge as per the chart given above

void show( ) displays the details of the customer and


amount to be paid

Specify the class Detail giving details of the constructor( ) and void show( ).
Using the concept of inheritance, specify the class Bill giving details of the
constructor( ), void cal( ) and void show( ).

THE MAIN( ) FUNCTION AND ALGORITHM NEED NOT BE WRITTEN.

You might also like