Adobe Scan Dec 06, 2023
Adobe Scan Dec 06, 2023
void display(){
System.out.printin("NAME : "+Name) :
System.out.printin("BASIC : "+Basic) :
double overtime () {
return hrs "rate :
void display() {
super.display() :
wage overtime() +8asic ; :
System,out. printin("Hoursworked : "+hrs)
System.out.printtn("Rate: '+rate) :
System.out.pnnttn("Wage : mage) :
m 22 (Progran 12.10) A library isshesbwks u vghtulbe ub 4 chdr ge vn the cost prce of the bok ner
bwk can etuined fur days witheut ay rine tf the book is
day. As per the rules of the library, a
returned after 7 davs, a fine will also be huár ged jur the ekces duy > er the chart gien bel.
(ISC 2009)
COMPUTER SCIENCE-XIl (1SC)
600
lEMLz1, 2 v2 z2 be the oordinates of the two points, then the
plane is given by the
formula
V(12-x1)' +(y2- yl)?
distance between he
and the distane between the points in space is given by the
2-l)' +(y2 -y1l)' + (z2 -z1)?
formul,
poinS
the two
Saah the class D2Point giving the details of
distance2d(D2Point b). Using the concept of inheritance constructors
specify and
details ot the two constructors and function
wite the main function.
double the class D3P
function
distance3d(D3Point b). You Roit donble
do n¡tgvIng the
30. Adas Personal contains employee details andanother class Retire calculates
the need ts
Fund and Gratuity. The details of the two classes are given below :
Data Members :
Name stores the employee name
Pan stores the employee PAN number
basic_pay stores the employee basic salary (in decimals)
acc_no stores the employee bank account number
Member functions :
Personal( ...) parameterized constructor to assign value to data
members
catch(Exception e) {
}
System.out.println(e):
Newjob - id;
if (rear -1)(
front rear 0;
job[rear] - id;
else if( rear+1 < job. length)
job[++rear] - id;
}
public void removeJob () {
int elem;
if( isEmpty( ) )
System.out.println("Printjob is empty");
else {
elem - job[front] :
if ( front = rear)
front = rear = -1;
else
front ++;
System.out.println("The print job removed is :" + elem) :
}
(0) The common name of the entity described is : Print Seroer.
Simple Data Structures 707
Proble.n21. (Program 14.14) Define a class Repeat which alloUs the user to add elements from one end (rear)
and remove clements from the other end (front) onty. (1SC2010)
The following details of the class Repeat are given below :
Class name Repeat
Data Menmbers / instance variables:
st[ ] an array to hold a maximum of 100 integer
elements
cap stores the capacity of the array
to point the index of the front
to point the index of the rear
Member functions :
Repeat(int m) constructor to initialize the data members cap = m,
f=-1r=-l and to create the integer array.
void pushvalue(int v) to add integers from the rear index if possible else
display the message("OVERFLOW")
int popvalue( ) to remove and return element from the front. If
array is empty then return-9999.
void disp() Displays the elements present in the list
Specify the class Repeat giving details of the constructor(int), member function void
pushvaluetint), int popvalue( )and void disp(). The main( )function need not be written.
Solution. import java.util.Scanner;
public class Repeat {
protected int str[ 1; /array to hold values
protected int f, r ; I/ to point to first &last element in the job
protected int cap;
public Repeat( int m) {
cap = m;
f= -1;
r= -1;
str = new int[cap]:
boolean isEmpty( )
return f == -1;
Member funthons
Chainint max) constructor to initlalize the data cap max, front
rear - 0and to create the inteyer array.
vold puahfrontint v) to add integers from the front index if possible else
display the message("lull from Iront"),
int poptront() to remove the return elements from front. If array is
empty then return-999.
possible else
vold pushrear(int v) to add integers from the front Index lf
display the mesage("full from rear")
If the array
int poprear) to remove and return elements from rear.
Is empty then return-9.
the class Chain gving details of the constructor and member function vold pushfront(int),
Spify poprear( ). The main function need not be written.
Int popfront), vold pushreartlnt) and int
boolean isEmpty( ) (
return front --1;
else if (front - 0)
System.out.println("Insertion from front end not possible."):
else // if ((rear-front + 1)< ele.length)
ele{ --front) v;
System.out.println("oVERFLOW!!"):
-1;
-1:
ele[front): : =
rear
ele(rear]
rear)
rear
-rear) return
elemnt
;
-vele[++rear]
; popfront(){
int
public ++; :elemnt
frontreturn (){ = rear--
;
-999;
return
- return - front
-999;
isEmpty())
if( frontfront poprear)) - front
elemnt int isEmpty( elemnt
elemnt:
elemnt:
int ( ( else
if else else
{
if
{else int
else } public if(
}
}
710
Arrays And Strings
427
Iplement acass Fnyptiom nith the folloeing seratime
Class Name Encrvption
Data MembersTnstance Variablee
Meseage a string
EncMsg encrypted message
Methods
voidreadMessage) :reads the Message from user
String Rotl3(String s): encrypts the passed string using Rot13 logic
void Encrypt) invokes Rot13( ) to encrypt message and
store in EncMsg
void display) displays the encrypted message
Constructor method initialises data members
Method main) creates an object of Encryption and invokes
appropriate methods.
importjava.util.Scanner:
Solution class Encryption {
String Message :
String EncMsg :
Encryption() {
Message =
EncMsg=
void readMessage() {
Scanner in new Scanner(System.in) ;
:
System.out. println("Enter message to be encrypted :")
Message = in.nextLine() :
String Rot13(String s ) {
String emsg=;
for (int i - 0;i<s.length() ; i+) {
char c= s.charAt(i):
if (c >= 'a' && c< 'm)ct= 13 ;
C- 13 ;
else if (c >= n &&c< Z) c -
c+= 13;
else if (c>= 'A &8& c <= 'M)
-= 13 ;
else if (c >= 'A' && c c= Z) C
emsg = emsg + C
return emsg ;
void Encrypt() {
EncMsg Rot13(Message) :
428
The
output
}
produced
public
ssage
Bevtvany
Zrffntr Enter
Message
Original
Message EnterOptions enc.display() ; Encryption
enc.Encrypt()
Z enc.readMessage(): static
Buel:
message message
by
now now
Temina!
above void
enc
mes becomes
to Window
main(String[
; SCIENCE-XIl
COMPUTER
(|SC)
to program =
be be new
encrypted
:: encrypted
2: Encryption()
nal Bevtvany
is args) ]
:
: {
ge Zrffntr :
functionsDesign
10
(rogram
Subsets
are class a
that11.20)object.display() : ubic
girven object.recchange(0) : : Change
object.inputword()
System.out.println("Enter
Combination can static
The
below
= found be
C(n,k) Combination object void
: main(Sting)
in =
to k!(nk)! - giien a new
implement n!function Lharnged
Sting
Change()
set
ofn word args){
C
this elements. (n, "):
: :
k) :
formula. gis
The the newstr):
functionniunber
Some
of can of
the different
be
data computed
members (unordered)
from
and the K
formula
elenents -
member
:
COMPUTER SCIENCE-XIl (ISC)
546 Comblnatlon
/instance variables integer number
Data mCmbers
integer number Rocu
6, Is i
void read()
Scanner in = new Scanner(System.in) ; 7, W
n= in.nextInt() : 8. H
k= in.nextInt() :
9, G
int fact(int n) { 10,
if (n <= 1) return 1;
else return (n * fact(n -1) ):
void compute()
Cmb =(double)fact(n) / (double)fact(k) * fact (n - k) ):
void display() {
System.out.printin ("Combination of "*n+" -c- "+k+" is :"+ Cmb) :
public static void
main(String[] args ){
Combination object = new Combination() :
System.out.println("Entervalue of nand k:");
object.read() :
object.compute() :
object.display() :
SECTION - C
Answer any tw0 questions
Program/Algorithmshould be written in such a way that it pseudo codes
theEach
logic of the problem step wise. This can also achieved by using clearly depicts
(Flowcharts are not required)
The Programs to be written in Java,
The Algorithm must be written in general/standard foe
(xvii)
Specify the class Record giving details of the constructor(), votd readvalues( )and void
display ). Using the concept of inheritance, specify the class Rank giving details of
constructor( ), void highest()and void display).
NOT BE WRITTEN
THE MAIN() FUNCTION AND ALGORITHM NEED
Ans.
import java.util.Scanner ;
public class Record
{ String [ ]names ;
int [ ] rnk :
Record( ) {
names = new String 5] :
rnk = new int [5] :
}
void readvalues() {
Scanner kb = new Scanner(System.in) ;
for (int i =0;i<5; i+) {
System.out.println ("Name of student "+(i+1) :
names[i] =kb.next(0:
System.out.println("Rank of student "+(i+1)) :
rnk[i] = kb.nextInt() :
}
void display( ) {
for (int i = 0;i<5;i+) {
System.out.println ("Name "+ names[i] + " Rank :"+ rnk[i]) ;
}
class Rank extends Record
int index ;
Rank( ){
super( ) :
index = 0 ;
void highest( ){
int max= nk[o]: index 0;
for (int i =1 ;i<5; i+)
if (max < rnk[i])
index =i ;
}
void display( ) {
super.display( ):
System.out.println("Name of topmoster ranker is "+ names[index]) :
}
(xix)
12. Stack is a kind of data structure which can store elements wnth
the restriction that an element cou
be added or removed from the top only.
The details of the class Stack is given below :
Class nome Stack
Data Members / instance variables:
st[ ] the array to hold the names
size the maximum capaity of the string array
top the index of the topmost element of the stack
ctr to count the number of elements of the stack
Member functions:
Stack( ) default constructor
Stack(int cap) constructor to initialize size =cap and top -1
void pushname (String n) to push aname into the stack. If the stack is tull
display the message "OVERFLOw"
String popname( ) : removes a name from the top of the stack and
returns it. If the stack is empty, display the
message "UNDERFLOw"
Void display( ) display the elements of the stack.
(a) Specify the class Stack giving details of the constructor(int), void pushname(String n),
String popname( ) and void display ). 13. (4)
THE MAINOFUNCTION AND ALGORITHM NEED NOT BE WRITTEN.
(b) Under what Principle does the aboe cntity uork? [21
Ans. public class Stack
{
String [] st ; W,
int size ;
The
int top ;
int ctr :
Stack( ) { b) Dis
size - 0 ; top = -1; ctr -0 ; I) Anst
Stack(int cap) {
size = cap ;
top = 1;
st =newString[cap]:
void pushname(String n) {
if (top -= st.length -1) {
System.out.println("0VERFLOW"):
else{
1/assetion: there is room for one more element
top++ ;
(x)
st[top] -n;
}
String popname( ){
String result
if (top -- -1) {
System.out. printin ("UNDERFLOW"):
else {
result st[top]:
top-- ;
}
return result :
void display( ){
System.out.println(st[top]+"<- top"):
for ( inti- top -1 ; i 0; i--){
System.out.println(st[i]) :
41
13. (a) Alinked list is formed from the objects of the class,
class Node
int info;
Node link;
Write an algorithm OR aMethod for deleting a node from a linked list.
The method declaration is given below :
void deletenode (Node start)
SECTION - C
1. Link is an entity which can hold a maximum of 100integers. Link enables the user to add
elements from the rear end and remove integers from the front end of the entity.
Define a class Link with the following details :
12. Asuper class Detail has been defined to store the details of a customer. Define a 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 |80paisa per call + rental charge
Above 300 lrupee per call + rental charge
(vi)
The details ot vth the classes are given below:
int p
String n :