Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
uwpo!'tL
l*n*hl'x;
v111"Yrba*Q
dAA
11
ebi, qatnurt1;
$rI 'vd*'Prwmil;
qu
)
uetd- $clruemf)
t
S(Anna..gc:
rt,etug}en:at {cgek'n'r'id;
0v* trarn)
pubttt int $neCk
F
'
f.:0 ,'
ft'*
;eq
1 4 1 {:A i
in"t"t=liazh;i+r 1
t_
s+ = uj
4 Lt==vumv)
L c4 +,,
btcuk;
a
( ( sl * )
LOnfrf\jJ,{,/
t ((> r,l*r,da
bxnat";
i 4 C c == f)
yet wn 7.)
ekt
n*ktun A;
fusPum()
vaLd,
Pu,talM
L r r uu
x' xi.{
L 6 (y==l )
r tl
;
Ll.,r.u/'"t
t\4'4"4f
t
c*'b
7o /^( " nattntb
okt
n N 0T ht'Lrrfld"a^"))
sop|n('' rwrnbc',-
3
1
DataMembers:
Str: To store a string.
l: * j.,:t ri'i.'},ri!
l.t,{,
l: r-t.L
t
l.
L Lwx"C.d-, iw n *)
t nt A ? L | J { 3 t , &&,3 6 . "
9eannP'^tt''rd Cn:0.
tl.tl t r0;
*t {rr"m>l}
{
L- _ D )
uJt;tU,( t,< mm*l)
i
7'
d,n*=atI iJ;
L++)
?
J
$s = dn r#d;
3
lr
L, (( n m : : i )
I
dnrdC;
l,
s*l',;r*{,#n}r
L
dfiA Fin^dJrta>o
{. Lrrhn, *
Fit't^atWt 0
L tn=-D,n*D;3
fy egetlvt*x{.W*x,ivt't'V}
t
M :Tt
l l =l { ,
_ ttdhuttth
ki
.d
t"twL
I
q
)
lL=% tV=^z=E
,
'6brff
d8x)
z)
W&exh1L;
,vg
,t!'&Wa1*z-;
t
,*A*grruird"dJ;
o
L,
m
/3'S"v.
fs
{
@
t &&,& &
f'N&
a lV ) W
?'g;'
ny* .7 &)
,u
\J
.{
v,
*
#. s{1.qe*ak L^lin{i
r ''
ti,lefudwaAefo1. tnau.l
fiw&.{Fucet{);
L^.rL -- oto6,qq.L/nary
(nt tnfu nS);
v .,
gopt*
talu
tr)ate:
QU ES T I O Ns
Number of excessdaYs
1to5
6 to1 0
above l0 daYs
Design a classLibrary and anotherclass
Class name
Data memberVinstance Yariables
name,author
p
Member functions/methods
Library( String n, String a, double np)
void show( )
Class name
Data members/instance variables
d
r
-givctt:
l,ibrary
string variablesto storename of book and authorsname'
price of the book in decimals.
n to nanlc.
parameterizedconstructorto assigl the paratnete.rs
a to author and nP to P.
displaysthe book details.
Compute
number of days taken in returning the book.
to store the fine.
I
Member functions/methods
Compute(........)
void fine( )
void display( )
--i .*
u
the concept of
Specify the class Library giving the details of the constru .tor and void show( ). Using
void
display( )
and
Inheritance, specify the classCompute giving the details of constructor, void fine( )
IISC 2009]
function.You do not needto write the main( ) function.
E rTTl
lIiFF
r,F.X-.Ff,lfltllG,r.:L.
A.S,
FG
i
t
II
l
t
149,,."
fw?t
r t - ji
lr
'^qrd ,f
-:
. ll o] Iro
,{r-:u.i.rf.*
ft,
.)
ivrt t, 1;
,
\
, lz-. //*\J
c n ' )i +\' 1 )
--4,
- i-rx (3C',
J++)
nL/'
J - ,/ J 1t7c)
n
,y,,b
,t, 2 ,
. rr:l
6eaq r J\ I
D{11
'
= l;
D-fv
7. t
A fz
(j"l/
f
f
l?
$^-- 3 ;
nr 3;
ttl l
)j
lr
I
t,
t2
i-
'
-
\
1
J
i f r, t
ir f it '
'
i
I
'Lr
I l,
tr^t,
r-i"!i
lt\n ,
i
a
lf,'.
[-
1
, - r','j L . l- n -t ' ,lt + )
\
J-'
a
i
{-,
^^a
0nyti
rl
r-\
\ r
\r
r J' i
\ Ii
b.re{\'f#*(t
I
3
i
! o,t*t"
l\
'
r\*.Sl1.1\
)
\{ f^'tu*\
\0r,L {" :o 1
\
'
r\, ; d n ' ,
.,
-i'
r 41 ' {
i1
'bt*,1',
"
L to\10'4,,( ct"t:"t'rl'rrl\
Y"'s p t t " nI\ \ ll
I
J
't
Y.t
ca"L(\
r\
Q-{Mj L*+\
(
L=ui
I 0r
t
{
* 3" 0t$d^,1 * a \
tr$L
rl
.n
r'
v
u{LL:= i)
to ' w w t oL't
z++\
,b fr L " = L'; <= As\ f lt t l\ i),
,{ [ru*tti]til
ol,L==m\
t&-Ufr\*,* * I
!
t
=* s ")
{ ffi"1"4'4^L,
S\I Yra-":
[s*
! \) copfi*
gi;.r,ru,t'
{4
3 ,*
q -I:
4 rt'tm!
4n\ulns"L:
\
l e t I L- t ; Lz - r n- \ i L + + )
,^, ri-t.
rrfiA;Jt-'
) '-t-\
tg "{l'ti3{Y}- t
I]
t \-N-*[-z
\t:
8 l'U
1r!:**:*.
i,,Jt]
'3
'ii rltl
tcl
]-{r-0*
+ ax':'[ilLj1j
o'
:
urvt\
s(Irv\r
$
1n'n-\
nfit ntn*
^A,', W-, dfuL,\.,w"u$!
cdp
Lvrttlu
.\.
E
\
'-,f 'opvvr-a-,.*
=
+\vl\^\y
J-,'-'(ilJu^^"
QL
Vex,,wW1
c.xie-x"{i-A,
Ps u f ^( )
'/
(\ i
rurts'P
LLa-Q,
vtr-u
-n r\,
,\ phl
$ .. c'eu"
w a L q*r t - [ ;ob!
P =
t4
()',,
qcli) ;
r^'Utr'
.J.i
obi-':Lr-rotrr
t'
where (x1, y1) and.(x2, y2) are the coordinates of the first straight liire.
v4-v3
and rn2 :
x{x3
. where (x3, y3) and (x4, y4) arc the coordinates of the second str;right line.
If slope of both the lines is same, then the lines are parallel to each other arr,l
if the product of the slope is -1, then they are perpendicular to each other.
The details of both the classes are as:
Class name
Data members/Instance variables:
Point
To store coorclinates in double typt,
To store the slope of the line in doul'1,,
type.
-D
(a) Specify the class Point giving details of constructor, function void Show$, declar,. I
void acceptPoint$.
(b) Using the concept of inheritance, specify the class Slope by giving the details of tlrt'
functions void findSlope$, void DisplayQ and void Check$. The classSlope is clerivc,l
frorn the class Point.
-, r/.1;...
ltr
f
i I:!
W,,
UnderstandinglsCConputerScience
I SZ0
Prog.
Tl-reciistance benveen
J t- l - . 2 ) r + ( \ ' 1 - " f t
An alrstractclass Point representsa poit"ttt-,tra 2D plane while another cl:rss
distance is declared to help in firrding ciistatrcebetrveen two points ancl mid
ooint. The details of both the classesare as:
Class name : Point
Data rnembers/ Instance variables:
x7, y1, x2, y 7 :
y2.
Class name
Data members/Instancevariables:
midx, midy
Distance
To store midx and midY coordinates
in double type.
Cill
^/vL
yf Il o-;
:--:
ct I
\
fl r*'-*
bJry
4 J Lrttr
---2
4-'-'
Date :
Q t i t , ) s ' t ' to N4
A hlrrk intends to design
digits.
Example I :
Input :
14856
\Lic;6
Output : ONE FOUR
EIGHT
i*
Denominations:
FTVE SIX
1000 x
5 0 0x1
1 0 0x3
50xl
5 xl
l xl
L4
TOTAL
TOTAL NUMBER OF NOTES
Example2 :
Input :
6043
Output :
SIX
ZERO
Denominations:
FOUR
FIVE
1 0 0 0x6=
2 0 "x
2
xl xl -
=
=
14000
s00
300
50
5
I
14856
2l
THREE
2
l
=
-
TOTAL
6000
40
2
I
6043
TOTAL NUIVTBER
oF NOTES
l0
Example3 :
Input : 2?5001
Output : tNVeLm AMOUNT
lrsc 20101
2 t4
.*'.:..:i;-+rrr="oiri;,i.?.-r.l'*i*.;..i
: j:'i,
QUESTTON5
Thc cornputcrdepartment
of the agencyof International
Espionage
is trying to decode intercepted
mcssilgcs.
The agency'sspieshavedetermined
that the enemyencodesmessagesby first convertingall
chur;rclcrs
lo theirASCII valuesand then reversingthe string.
Frrr cxanrple,considerA_z (the underscoreis just to highlight the space).The ASCII values of A,
<spircc>,r. are 65, 32. 122 respectively.Concatenatethem to get 6532122, then relerse this to set
2212356as the codedmessase.
Writc a programwhich readsa coded messageand decodesit. The coded messagewill not exceed200
chitr i tclcrs.
Itwillcontainonlyalpha b e t s (A. . . Z , a n d a . . . . 2 ) a n d s p a c e s . A S Cllv a lu e s oAf. . . . Z a r e
65 ....9 0 andthoseof a... zare9l . . . . 1 2 2 .
'lbst your programfor the following data anil somerandom
data.
Sample data :
In p u t:
FlncodedMessage:
2 3 t2 t7 98623 t0 I 9950
Output:
THE DECODED NIESSAGE :
llave A Nice Day
****
Input:
llncoded
2 . 15 l l 0 l 1 5 0 t7 8 2 -? 5 I 1 t2 L799r |801
Output:
.I'IIE DECODED
MESSAGE:
'l'ruth Always Wins
'i **
*18
;:-rt;.ir;:it:
: rr,,,.,,,::r
lrsc 2fi)41
utEslor.r+
imPot"tt4*o uti(. *;
elass*enarniYqat(on
d
Voi& .fi4&|n()
u'^1'Yr,o0j
| $Y\,.e
t vt L0&[1 3 | tOOo,bo q^l?O
lo' 6 ) L) t t ' ^
' lb) f r ) '
ouN\N9"}
swi^fla$2[]={";tr^H'5-rw0",1"fHltLY"t*.
U
{frg*txrvJt
{rfinne^
*
wtlr.
kanrw rc
?i.^,
S
'
&to3rurnn'ban"!
0(JJ'Px'tv\*0t\( " Er'&zu
6sre'''ge
LnX ??:
'n-cx"t'$*tt();
s +}
i*
L4'"Mirur.r#I'|^t
fiot { bn* b*0J
gdhr\*ro
Lnt fi = wf a*tLilt
(trrrr = gnrnt"6)
Lbt$\.=F)
V\
+ b *" = " +
(oPa,;.
tusdl \l+" -)p'"
?r:. h "1,nPt[iJ
o"1ilrrb)'i
-tC
/r(b*
.3
/*-)
j
BopQJ^lt r*rw)
\g)
*P*
!*Y
sf Pu!\q L --
cd;
'6 Nk'fl^T
tt + )
\'
('tp Vo ;'r, r' $'enAtt'(
\a
+" ')
[" "+ t" Lh,oeoAtt])]
,[ar"*Ls
&on*.-]- 'u*
sop',ra"
,i
. l Cl l
c i l i cl i d r i !
; ii<
I io 26 ir.,l!,,:r:lr.lu",
.,1*, li"".,rO
F o r e x a i n pl e, S hi ft 7 means
that A = U , B = V , C = !V ancl
so on________
Text: A B C D E F G H f
I K L M N O p e R S T Li V vV Xy
Z
Code: U V !V XY z A B C D
EFG H I JK L M N o P
Q R ST
An extra space is added to the
end of the.string. To
thi.gs a Iittle more
difficult, spaceswithinthe otigi";ri"*t
ur"."pru"ed 'rake
with ee before th-etext
(aai;"'
ffi$itft[oouble a
'"r".,"ail;';o
i.,grir],wordends
frsc 20031
Input :
Output :
6043
SIX
ZERO
Denominations:
1000
20
2
I
FIVE
X
.x.
x
x
THREE
6
2
I
I
TOTAL
TOTAL NUMBER OF NOTES
Example3 :
Input : 235001
Output : INVALID AMOUNT
.2is
FOUR
=
6000
= 40
=2
=l
=
6A43
= 10
[rsc 2010]
Qu e sti on 1
"
Giventwo positivenumbersM and N, such that M is between
100 and 10000and N is less
than 100' Find the smallestinteg6r that is greatertfran
M and whose digitsadd up to N.
For example,if M=100 and N=1 1, then the lmallest integer
greater tnai t oo whosedigits
ad d u p to11is119.
write a programto accept the numbersM and N from the
user and print the smallest
requirednumberwhosesum of all its digitsis equal to
N. Also, print the total numberof
digitsplesentin the required number. T1e programshould
check for the validity of the
inputs and disprayan appropriatemessagefor an invalid
input.
Test your programwith the sampledatalnd somerandom
oata:
Example1
IN PUT:M =100
N=11
OUTPU T:
The requirednumber =119
Total numberof digits= 3
Example2
INPU T:M =1500
N = 25
OTJTPUT:
The required number = 1699
Total numberof digits=4
Example3
INPU T:M = 99
N = 11
OUTPUT:INVALIDtNpUT
Exampte
6043
SIX
Input z
Output :
Denominations:
ZERO
FOUR
THREE
1000x6=
20x?=
2xl=
lxl=
TOTAL
TOTAL NUMBER OF NOTES
Example3 :
Input z 2)JA0l
Output : INVALID AMOUNT
tt4
FIVE
6000
40
2
I
=
6043
10
IISC 20101
I/
:..
qv . . : l
.t.r
:-,
i e Finding
th"r,.,tu."
dare
n days
i.i:ff S:,':ff'J"",:'rf1;:i.ll5?']"r?Tifffi_r;ction
arter
the
number
of days berweenthe current
date and date
lr'::ilrr"*"
on which a prsjectends.
Date (dd_mm)
01_01
20_07
02_a2
03_03
someof thetunctions/*"th"d:1o;"f*
January (01_01)
Date Number
1
20
33
62
dateare,no#Lro-,
Class name
Data membery'instance variables
:
:
:
:
dd
mm
Member functiony'methods
date (int nd, int nm)
ddte
IqIE
dav
month
intdatetod","""*.?i
, returns
::ffilT::"r::t::^ii:
the date number
obrect.
date datenumbertodate (
int dn )
ld,,* =run
tr*"
retu's
iff:"#.#H:,,13,'*
*n:*]l*;
flJlli**#lh
y.umay
;;;_u,ha,,he
VSC_ 200gi
,/
,.c:-:tstii"f't:z8
" A classNumbers
contains the following
data members and member
(A triangular number it
functions to.checkfor triangular
fot^;J;;
ihe additior,
numbers.
;;*",i""
eg.
,"i;;"'J'r"tegers
"i"
starting from 1.)
7+2-3
1+2+3=6
'1.+2+3+4=19
7+2+3+4+5=15
Therefore g, 6, 10,5 are
triangular numbers.
Class name
Data Members:
Numbers
rnteger to be checked
whether it is triangular
or not.
Member functions:
void gehrum$
int check(int)
-t
to
accepf integer n.
to check if n is triangular.
to. display rnessage ,iheth",
speciry
theclass
n is triangular or not.
Numbers al',TilJ?n"functions
voi
The main functtbn need noib"
d
ge
rn
um
int
fl, "n""t1ir.,ty
i.uJ .l"rl'olr"J""* ff
"#f ;;;;;."
.e-
il
i
/
h cLa-vs ,rtd;[y
C*"Ll-s'
16u'*'ru 1/Wod;$d.
YWrwz '
CLa'\,6
-n
fu&* Yw*b*Ato
2 6h^ua& "tfrT
6
l
o
u
t
w
'
W4
t
t
r
"
o
'A
X"-)
) a-LLTt eL'*z
votd' ruAq
'ff"t"oa'<-
c'l^ol
i
C
e'^
uuod
P "b' ;f:r:ffi" U!*::S
ffird d"/.''o^y{t'sbi7
voLd balr-,od;0A
4'*
dti*q
*,
o
'
o
/U
l
ofd#''L
t
tl
t ) .- oo0,,. ,
-$usi'hiw "qn{ "tuP%
- ,.
veid, &"^4tL)
T"'
ft:
Cht^"+rn ,sbiq"
cJ"**d
'sf"-"''1, "
,
^
-) 1 '""-tlnce t;L
'-l'oro'tz'u
/*, d
o*:g*nJ at^sg*d
"W "-P*'*b!-di*o'n'*-
*l;L b""!
z me*a aLua'i
'
1 -:;: Xn ",o^n{u
Vn*
,r*n1y*o
w'd'bu -fu
'^a-UL
-#^*^'ttt-, "'04n^
'.:,
-ii
ii
'l',
tl
,l^.'
:l,la.-
T*EitLt.
lt*
(-'
{ - '/J -\ c:^:'
$ LtcJk 4 Lk
tu'^
( L({I('ltkntt, tN
i.,v
;:tt;f
AI
.,,/
t,
j J LTIII L nT II . /II t / A v
/
t^A
I /
L l_
aLa
/i,,o!fl,r,,
n,,A
L',,,rLlVar
c!..a.*s
Aol,,t'
/? ^
l_"ya^6
f"
A.[atu""
YWtuLbuq
Wl I YL
il
i /l
I tttCt tYLaK
lVlu*bu.o 'ltrn,twnz
f'*fu\AorO
nuvwbu
'twtnXu'tvoLtoLt"t Lr 'Sb*"
c to Mt (1
o,h*
6rcn
tc,
to
tctD^
: Grtstn"Lo't
O
iruhLf*r'no^.n'Fac'id
?::t"S'o*
A^**r#-{6,*t*r
/' ) n Al
eXP'n /\avw
: T'id"{i4u'oL
--1)
.r'fi?**t'F
nr'
U'Pa
^G
YWefx-c'x
Aouv'\
{rA
uv'O
" f) !, r i j ,_- r .:
/ ju
"
P'a-t-c+,n
e b F "f f i
gP z r c f t cM
,l
.b r'tt *
t\A
Clt'\4
J',-'
+f"
''\-{'2-
"
A^P
J Y La Ax*KvJ
n""n'u
:fffikmr;;::
n t, NL*"no'""
Atrr*]Mt0-r't-a-K't2^9"{L
fi**Ywwbuz'
u
&ouLl'
a^hLJ LJ +
'
:".";
oLKLtl"
u,;t;rt;g-#,-i
A^
,Y{rnolt.lvlu,,,J*;';:;
voA
tr;mi
s'c),n|j;l
w"&af^
'm'dln*''--*
e&
,o T*'^,?^vW
l
*^
^"*h;'
v \dd",# .n w Ci)
ffi#:;:f#r
v oi d
'W'o*r"*u
:*%
"*c1o*^do*-
tf.-
n;,nr'rubW
\.1./t
nkS
Date :
QUESTION
bill
while anotherclass Sales defines the
salesman
a
of
data
perlonal
the
A.class Salesrnandefines
nameof the item' numb e ro f it e ms s o ld a n d p ric e o f t h d it e m. T h e d e t a ils o f c l a s s e s a r e a S :
ruumber,
Salesman
Class name
1
variables
Data members/instance
string variableto storename salesman'
name
string variableto storeaddress'
address
Member functions/methods
Salesman(;
ad)
n,
void readDetails(String String
void Show( )
and address'
constructorto assignblank to name
address'
to assign'n' to name and 'ad' to
using suitableheadings
to prini valuesof name and address
Sales
Class name
Data members/instance variables
billno' qtY
price, Psales
pname
Member functions/methods
p)
void readDetails(intb, int q' double
pr)
void readDetails(doubles, String
calcu
void Show()
price.
to billno, 'q' to qtY and 'p' to
'pr'to pname
to psales (Previoussales)and
furrnula-::
o
x
(qty) l+ previous sales (psales)
t Price (P) quantitf
qty' price' sales an
to disPlaYuulu., of pname, trillno,
total salesmade by invoking suitable function'
to assign
to assign
(a)
(b)
specrrv
inheritance
:::J;'Jtr#or
carcurate
pr),doubre
":^l'l':-::l::lJ.tilii:"TffiiJ'1"":ff
y#b:ffi|il:T,:l ilffiffi;, 5iiareadDetans(doubre',-st'i"g
ffiil;i';.-Y;;
Answer: