[go: up one dir, main page]

0% found this document useful (0 votes)
18 views6 pages

Question Is C 12

The document outlines the specifications for several classes in Java, including StringOp for string manipulation, Mixarray for combining arrays, and LCM for calculating the lowest common multiple. It also describes a ReCycle class for managing a collection of integers and a Library class for calculating book rental fines. Each class includes data members, methods, and constructors, with instructions for implementing them in a main function.

Uploaded by

it2021037
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views6 pages

Question Is C 12

The document outlines the specifications for several classes in Java, including StringOp for string manipulation, Mixarray for combining arrays, and LCM for calculating the lowest common multiple. It also describes a ReCycle class for managing a collection of integers and a Library class for calculating book rental fines. Each class includes data members, methods, and constructors, with instructions for implementing them in a main function.

Uploaded by

it2021037
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Question 6

Given are two strings, input string and a mask string that remove all the characters of the [10]
mask string from the original string.
Example: INPUT: ORIGINALSTRING: communication
MASK STRING: mont
OUTPUT: cuicai

A class StringOp is defined as follows to perform above operation.

Some of the members of the class are given below:

Class name : StringOp


Data members/instance variables:
str : to store the original string
msk : to store the mask string
nstr : to store the resultant string
Methods / Member functions:
StringOp() : default constructor to initialize the data
member with legal initial value
void accept( ) : to accept the original string str and the mask string
msk in lower case
void form() : to form the new string nstr after removal of
characters present in mask from the original string

void display( ) : to display the original string and the newly formed
string nstr
Specify the class StringOp giving details of the constructor( ), void accept( ),
void form() and void display( ). Define a main( ) function to create an object and call all
the functions accordingly to enable the task.
Question 7 [10]
A class Mixarray contains an array of integer elements along with its capacity (More than or
equal to 3). Using the following description, form a new array of integers which will contain
only the first 3 elements of the two different arrays one after another.

Example: Array1: { 78, 90, 100, 45, 67 }


Array2: {10, 67, 200, 90 }
Resultant Array: { 78, 90, 100, 10, 67, 200}

The details of the members of the class are given below:

Class name : Mixarray

Data members/instance variables:

arr[] : integer array

cap : integer to store the capacity of the array

Member functions/methods:

Mixarray (int mm ) : to initialize the capacity of the array cap=mm

void input( ) : to accept the elements of the array

Mixarray mix(Mixarray P, Mixarray Q) : returns the resultant array having the first 3
elements of the array of objects P and Q

void display( ) : to display the array with an appropriate


message.

Specify the class Mixarraygiving details of the constructor(int), void input( ), Mixarray
mix(Mixarray,Mixarray) and void display( ). Define a main( ) function to create objects
and call all the functions accordingly to enable the task.
Question 8 [10]
A class LCM has been defined to find the Lowest Common Multiple of two
integers.
Some of the data members and member functions are given below:
Class name : LCM

Data members/instance variables:

n1 : to store an integer number

n2 : to store an integer number

large : integer to store the largest from n1,n2

sm : integer to store the smallest from n1,n2

l : to store lcm of two numbers

Methods / Member functions:

LCM( ) : default constructor to initialize data members


with legal initial values

void accept( ) : to accept n1 and n2

int getLCM( ) : returns the lcm of n1 and n2 using the


recursive technique

void display( ) : to print the numbers n1, n2 and lcm


Specify the class LCM giving details of the constructor( ), void accept( ), int getLCM()
and void display( ). Define a main ( ) function to create an object and call the member
functions accordingly to enable the task.
SECTION – C
Answer any two questions.
Each program should be written in such a way that it clearly depicts the logic of the problem
stepwise.
This can be achieved by using comments in the program and mnemonic names or pseudo codes
for algorithms. The programs must be written in Java and the algorithms must be written in
general / standard form, wherever required / specified.
(Flowcharts are not required.)

Question 9
Recycle is an entity which can hold at the most 100 integers. The chain enables the user to
add and remove integers from both the ends i.e. front and rear.
Define a class ReCycle with the following details:
Class name : ReCycle

Data members/instance variables:


ele[ ] : the array to hold the integer elements

cap : stores the maximum capacity of the array

front : to point the index of the front

rear : to point the index of the rear

Methods / Member functions:


ReCycle (int max) : constructor to initialize the data cap = max,
front = rear = 0 and to create the integer array.
void pushfront(int v) : to add integers from the front index if possible
else display the message(“full from front”).
int popfront( ) : to remove the return elements from front. If
array is empty then return-999.
void pushrear(int v) : to add integers from the front index if possible
else display the message(“full from rear”).
int poprear( ) : to remove and return elements from rear. If
the array is empty then return-999.
(i) Specify the class ReCycle giving details of the functions void pushfront(int) and [4]
int poprear( ). Assume that the other functions have been defined.
The main( ) function and algorithm need NOT be written.
(ii) Name the entity described above and state its principle. [1]
Question 10 [5]
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 (Rs.)
1 to 5 2.00
6 to 10 3.00
Above 10 5.00
A super class Library has been defined. Define a sub class Compute to calculate the fine and
the total amount. The details of the members of both the classes are given below:

Class name : Library

Data members/instance variables:

name : to store the name of the book

author : to store the author of the book

p : to store the price of the book (in decimals)

Methods / Member functions:

Library( ... ) : parameterized constructor to assign values to the


data members
void show( ) : displays the book details

Class name Compute

Data members/instance variables:

d : number of days taken in returning the book

f : to store the fine (in decimals)

Methods / Member functions:

Compute( ... ) :parameterized constructor to assign values to the


data members of both the classes
void fine( ) : calculates the fine for the excess days as given in
the table above
void show( ) : displays the book details along with the number
of days, fine and the total amount to be paid. Total
amount is (2% of price of book * total no of days)
+ fine
Assume that the super class Library has been defined. Using the concepts of Inheritance,
specify the class Compute giving the details of constructor, void fine ( ) and void show ( )
functions.
The super class, main function and algorithm need NOT be written.
Question 11

(i) A linked list is formed from the objects of the class Node. The class structure of the [2]
Node is given below:
class Node
{
int n;
Node link;
}
Write an Algorithm OR a Method to search for a number from an existing linked list.
The method declaration is as follows:
void FindNode( Node str, int b )
(ii) Answer the following questions from the diagram of a Binary Tree given below:

B F

D C G

E H

(a) Name the root of the left sub tree and its siblings. [1]

(b) State the size and depth of the right sub tree. [1]
(c) Write the in-order traversal of the above tree structure. [1]

You might also like