0% found this document useful (0 votes)
55 views

C++ Programs List

Cpp practice question

Uploaded by

naresh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

C++ Programs List

Cpp practice question

Uploaded by

naresh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

RahulMaheshwar

i -‘
C++’
Progr
am Li
sti
ng


C++’
Fundament
als

Q1. Wr i
teapr ogram t opr i
nty ourname.
Q2. Wr i
teapr ogram t opr i
ntt hesum oft wonos.
Q3. Wr i
teapr ogram t opr i
ntt hesum andav erageoff i
venos.
Q4. Wr i
teapr ogram t opr i
ntt hesquar eandcubeofano.
Q5. Wr i
teapr ogram t opr i
ntt headdi tion,mul tipli
cat ion, subt ractionanddi v
isionoft wonos.
Q6. Wr i
teaC++pr ogr am thati nit
iatest hreev ariablesnamel yhour sWor ked,pay Rateandt axRate
andt hencal culatesandpr i
ntspay mentamountandTaxpay abl eashour sWor kedxpay Rate
andPay mentamountxt axRat erespect i
vely.
Q7. Wr i
teapr ogram t oinputanumberanddi splayi tont hescr een.
Q8. Wr i
teapr ogram t oinputanumberandpr i
nti tssquar eandcube.
Q9. Wr i
teapr ogram t oinputt wonumber sandpr intt heirsum.
Q10. Wr i
teapr ogram t oinputf ivenumber sandpr i
ntt hei rsum andav erage.
Q11. Wr i
teapr ogram t oinputl engthandbr eadt hofar ect angl eandpr inti tsar eaandper i
met er.
Q12. Wr i
teapr ogram t oinputr adiusofaci rcl
eandpr inti tsar eaandci rcumf erence.
Q13. Wr i
teapr ogram t otemper atureinFahr enhei tandconv er titintoDegr eeCel sius.
Q14. Wr i
teapr ogram t oi nputbasi csal aryofanempl oy eeandcal cul atei tsDA, HRA, PFandGr oss
Sal
ary.
DAi s30%, HRAi s10%, PFi s12%ofBasi cSal ar y.
Gr ossSal ary=Basi cSalar y+DA+HRA–PF
Q14. Wr i
teapr ogram t oinputsal aryofanempl oy eeandcal cul atei t
sI ncomeTax@15%.
Q15. Wr i
teapr ogram t oinputsi desofacubeandpr i
nti tsar eaandv ol ume.
Q16. Wr i
teapr ogram t oinputpr i
ncipleamount , r
at eofi nt erest&t imei ny ear sandcal culateSimple
I
nter
est.
Q17. Wr i
teapr ogram t oi nterchange( swap)t hecont ent soft wov ariabl eswi t
handwi thoutusinga
thir
dv ariable.
Q18. Wr i
teapr ogram t or oundof fani nteger‘ i’tot henextl argestmul ti
pleofanot heri nt
eger‘ j

.For
eg.256whenr oundedof ftot henextl argestmul t i
pledi visibl
eby‘ 7’ resultsi nto‘259’ .
Q19. Thedi stancebet weent woci ties( i
nkm. )isi nputt hr ought hekey boar d.Wr it
eapr ogram to
conv er
tandpr intt hi
sdi stancei nmet ers, f
eet , i
nchesandcent i
met ers.
Q20. Ifafivedi gitnumberi finputt hrought hekey boar d, wr i
teapr ogr am t opr intiti nrev erseorder.
Q21. Ifaf ourdi gitnumberi finputt hrought hekey boar d,wr i
teapr ogr am t oobt aint hesum ofi t
s
fir
standl astdigit.
Q22. Acashi erhascur rencynot esofdenomi nat i
ons10, 50and100.I ft heamountt obewi thdrawn
isinputt hr ought hekey boar di nhundr eds,f indt het otalnumberofcur r
encynot esofeach
denomi nat ionthecashi erwi l
lhav et ogi vet ot hewi thdr awer .
Q23. Ifthet otalsel l
ingpr i
ceof15i temsandt het ot alpr ofitear nedont hem i si nputt hrought he
keyboar d, wri
teapr ogram t of i
ndt hecostpr iceofonei tem.

I
F..ELSEConst ruct
Q1. Wr it
eapr ogr
am toi
nputandno.andpr intiti
sEv enorOdd.
Q2. Wr it
eapr ogr
am toi
nputandno.andpr intiti
s+i veor–i ve.
Q3. Wr it
eapr ogr
am toi
nputtwonos.andpr i
ntthehighestamongt hem.
Q4. Wr it
eapr ogr
am toi
nputthreenumber sandpr intt hehighestno.(wit
h&wi t
houtusingt er
nary
oper
ator
)
Q5. Wr it
eapr ogr
am toi
nputfi
venumber sandpr i
ntthehi ghestandlowestnumber.
Q6. Any eari
sinput
tedthr
ought hekeyboard,wr i
teapr ogram todeterminewhethertheyearisa
l
eapornot.
Q7. Wr it
eapr ogr
am toi
nputaf ivedi
gitno.andpr intt henumberi nrever
seorder.Alsodetermine
whet hert hei nput t
ednumberi spal indromeornot .
Q8. Wr i
teapr ogr am t oi nputt hr eeangl esofat r
iangleandcheckwhet hert het riangleisv alidor
not.
Not e:At riangl ei sv al i
di fsum ofi t sthr eeangl esi s180.
Q9. Wr i
teapr ogr am t oi nputl engt handbr eadt hofar ect angl et ocheckwhet heritsar eaor
perimet eri sgr eat er.
Q10. Wr i
teapr ogr am t oi nputachar act erandcheckwhet heri tisanupper case,l ower case,di gitor
special sy mbol .
Q11. Wr i
teapr ogr am t oi nputsi desofat r
iangl eandcheckwhet heri ti sar ightangl ed,isoscel es,
scaleneorequi l
at eral triangl e.
Q12. Wr i
teapr ogr am t oinputanal phabetandconv ertitintoi tsequi valentopposi t
ecase.
Q13. Thecur r
enty earandt hey eari nwhi cht heempl oy eej oi nedt heor gani zationar eent ered
through t he key boar d.I ft he numberofy ear sf orwhi ch t he empl oy ee has ser ved t he
organizat ioni sgr eatert han3,t henabonusofRs.2500/ -i sgi vent ot heempl oyee.Ifthey ear
ofser vicear enotgr eat ert han3, thent hepr ogr am shoul ddonot hing.
Q14. Inacompanyanempl oy eei spai dasunder–
Basi cSal ary HRA DA
<1500 10% 90%
<=1500 500 98%
Iftheempl oy ee’ ssal aryi si nput t
edt hr ought hekey boar d,wr i
teapr ogr am t ocalculat ehi s
grosssal
ary.
Q15. Acompanyi nsur eshi sdr iv eri nt hef ollowi ngcases–
* Ifthedr i
v erismar ried.
* Ifthedr i
v erisunmar ried, mal eandabov e30y ear sofage.
* Ifthedr i
v erisunmar ried, femal eandabov e25y ear sofage.
Inallot hercases,t hedr i
v eri snoti nsur ed.I ft hemar italst at us,sexandageoft hedr i
v erar e
inputs,wr iteapr ogr am t odet ermi newhet hert hedr iveri st obei nsur edornot–wi thand
withoutusi ngl ogi cal oper at or s.
Q16. Ifcostpr iceandsel li
ngpr i
ceofani tem i si nputt hrought hekey boar d,wr i
teapr ogram t o
determi newhet hert hesel l
erhasmadepr ofitori ncur redl oss.Al sodet er mi nehowmuchpr ofit
hemadeorl osshei ncur r ed.
Q17. Acer taingr adeofst eel isgr adedaccor di ngt ot hef ollowi ngcondi tions–
(i) Har dnessmustbegr eat ert han50.
(ii
) Car boncont entmustbel esst han0. 7.
(ii
i
) Tensi l
est rengt hmustbegr eatert han5600.
Thegr adesar easf ol lows–
* Gr adei s10i fal lthet hr eecondi tionsar emet .
* Gr adei s9i fcondi tion( i)and( i
i)ar emet .
* Gr adei s8i fcondi tion( i)and( i
ii
)ar emet .
* Gr adei s7i fcondi tion( ii
)and( ii
i)ar emet .
* Gr adei s6i fonl yoneoft hecondi t
ionsi smet .
* Gr adei s5i fnoneoft hecondi t
ioni smet .
Wr i
teapr ogr am whi chwi llr equi ret heusert ogi v
ev aluesofhar dness,car boncont entand
tensil
est rengt hoft hest eel underconsi der ationandout putt hegr adeoft hest eel.
Q18. Al i
brarychar gesaf inef orev er ybookr et urnedl ate.Forf i
rst5day st hef inei s50pai sa,f or6–
10day sf inei sRe.1/ -andabov e10day sf inei sRs.5/ -.I fabooki sr etur nedaf ter30day s, then
member shi piscancel led.Wr iteapr ogr am t oacceptt henumberofday st hememberi sl atet o
returnthebookanddi spl ayt hef ineort heappr opr i
atemessage.
Q19. Thepol i
cyf ollowedbyacompanyt opr ocesscust omeror deri sgi venbyt hef ollowingrules–
(a) I facust omeror derquant ityi slesst hanorequalt ot hati nst ockandhi screditisOK,
suppl yhi sr equi r
ement .
(b) I fhi scr edi tisnotOKt hendonotsuppl y.Sendhi m ani ntimat i
on.
(
c) Ifhiscrediti
sOKbutt heitem i nst ocki sl esst hanhi sor der,supplywhatisinstock.
Int
imat etohimt hedat eonwhi cht hebal ancewi llbeshi pped.
Q20. I
nputa1, 2,3,4or5di gitnumber .Wr iteapr ogram t ofindt heno.ofdi gitsinthenumber.
Q21. Giventhreenumber sA, BandC, writeapr ogr am t owr i
tet heirv aluesindescendingorder.
Q22. Writeapr ogram tofi
ndwhet herthegi venchar act erisadi gitoral et
ter.
LOOPS( do..while, while,
for )
Q1. Wr iteapr ogram topri
ntf i
rsttennat ur alnumber s.
Q2. Wr iteapr ogram tonos.f r
om 57t o30.
Q3. Wr iteapr ogram topri
ntt hesum ofev enandoddnos.f rom 50t o150.
Q4. Wr iteapr ogram topri
ntt hemul ti
plicat i
ont ableofanyi nput tedno.
Q5. Wr iteapr ogram toi
nput10nos.andcounthowmanyar e+i ve, -
ive,evenandoddnos.
Q6. Inputdet ail
sofpassenger sandcounthowmanyar eDai ly,Weekl yandMont hl
ypassenger
s.
Q7. Wr iteapr ogram toi
nputanyno.andchecki tisPal indr
omeornot .
Q8. Wr iteapr ogram toi
nputanyno.andchecki tisPr imeornot .
Q9. Wr iteapr ogram toi
nputanyno.andchecki tisAr mst r
ongno.ornot .
Q10. Writeapr ogram toinputanyno.andchecki tisPr i
meno.ornot .Ifitisapr i
meno.thencheck
i
tisev enoroddno.I fitisev enno.t henpr i
ntt hesquar eoft heno.el seprintit
scube.
Q11. Writeapr ogram toi
nputano.andpr intitsfact orial
.
Q12. Sum thef ol
lowingseries–
(a) 1+2+3+4+5+. ...
..+10( b) 1–2+3–4+5-. ....
.-10 ( c) 1+4+9+16+. ..
.
(d) 1 2 3 4
+ + + + .
...
..
1 2 6 24
(e) 1 2 3 4
- + - + .
...
..
1 4 9 16

(
f) 1 2 6 24
+ + + + .
..
..
.
1 8 27 64
(
g) 1 x2 x4 x6
- + - + .
..
..
.
1 2! 4! 6!

Q13. Printt
hef ol
lowi
ngpatterns/ser
ies–
(a) 1, 1,2,3,5,
8,.
..
...
(b) * (
c) 1
* * 1 2
* * * 1 2 3
* * * * 1 2 3 4
* * * * * 1 2 3 4 5
(d) 1 (
e) 1
2 3 2 6
4 5 6 3 7 10
7 8 9 10 4 8 11 13
11 12 13 14 15 5 9 12 14 15
(f) *
* * *
* * * * *
* * * * * * *
* * * * *
* * *
*
(
g) * * * * * * * * *
* * * * * * * *
* * * * * *
* * * *
* *
* * * *
* * * * * *
* * * * * * * *
* * * * * * * * *

(
h) A B C D E D C B A
A B C D D C B A
A B C C B A
A B B A
A A
A B B A
A B C D C B A
A B C D E D C B A
A B C D E D C B A

Q14. Wr i
teapr ogr am t oCal culat e simpl eint erestf or10empl oy ees.
Q15. Calculateov er t
imepayf or10empl oy ees.Ov ertimei spai datt her ateofRs.12. 00perhourf or
everyhourwor kedabov e40hour s.Assumet hatempl oy eesdonotwor kforf ractionalpar tof
anhour .
Q16. Wr i
teapr ogr am t oi nputt wonos.andpr intt her esul twhenf irstno.i frai
sedt ot hepowerof
secondno.
Q17. Wr i
teapr ogr am topr intt heASCI Iv al
uesandt heirequi valentASCI Icharact erusi ngawhi l
e

loop”
Q18. Wr i
teapr ogr am t oinputt ennos.andpr intt hef act orial ofal lt hosenos.whi char epr ime.
Q19. Wr i
teapr ogr am t oinputano.andpr intitsequi valentbi nar y,oct al andhexadeci mal no.
Q20. Wr i
teapr ogr am t hat,f oral lposi t
ivei nteger si ,j,kandlf rom 1t hr ough1000,f indsandpr i
nts
allcombi nat ionofi ,
j,kandl sucht hati +j +k=l andi <j <k<l .
Q21. Wr i
teapr ogr am t ocal culat eandpr i
ntr oot sofaquadr aticequat ionax2 +bx+c=0( a≠0) .
Thecoef ficient sofquadr aticequat ionsa, b, car er ecei vedaspar amet er
s.
Q22. Program t ot abul atet hef unct i
on: f(
x)=( x2+1. 5x+5)/(x–3)
forx=-10t o10, ‘x’shoul dt akev alues- 10, -8, -
6, ...,6, 8, 10.
Q23. Wr i
teapr ogr am t odi spl aymenur egardingr ect angl eoper at ionsandper for m accor dingt o
user’schoi ce.
Q24. Wr i
teapr ogr am t ogener atedi visorsofani nteger .
Q25. Wr i
teapr ogr am t opr intev eryi ntegerbet ween1andndi visiblebym.Al sor epor twhet herthe
numbert hati sdi visi
bl ebym i sev enorodd.
Q26. Wr i
teapr ogr am t ofindwhet hert hegi v
enchar act erisadi git,upper casel et
ter , lower casel ett
er
oraspeci al sy mbol .
Q27. Abankaccept sfixeddeposi tsf oroney earormor eandt hepol icyi tadopt soni nterestisas
fol
lows–
(i
) I fadeposi ti sl esst hanRs.2000andf or2ormor ey ear s,thei nt erestr atei s5%
compoundedannual l
y .
(i
i) I fadeposi tisRs.2000ormor ebutl esst hanRs.6000andf or2ormor ey ears,the
inter estr ateis7%compoundedannual l
y .
(i
ii
) I fadeposi ti smor et hanRs.6000andf or1ormor ey ear s,thei nt er estr atei s8%
compoundedannual l
y .
(i
v) Onal ldeposi tsf or5y ear sormor e, interestr atei s10%compoundedannual ly.
(v) On al lot herdeposi ts notcov ered by abov e condi ti
ons,t he i
nt er estr atei s 3%
compoundedannual l
y .
Givent heamountdeposi tedandt henumberofy ears, wr iteapr ogr am tocal cul atet hemoney
i
nthecust
omer
’saccountatt
heendoft
hespeci
fi
edt
ime.

SWI TCHCONTROL
Q1. Wr i
teapr ogr
am toinputano.andpr i
nti t
sindivi
dualdi
git
si nwords.Foreg.if‘
972’i
sentered,
thenitshouldbepr i
ntedas‘ ninesev ent wo’.
Q2. Aposi t
iveintegerisent eredt hr
ought hekey board.Al
ongwi thitthebaseoft henumber i
ng
system inwhi chyouwantt oconv ertthisnumberi sentered.Writ
eapr ogram todispl
aythe
numberent ered,t
hebaseandt heconv ertednumber .
Q3. Wr i
teamenudr i
venpr ogram foraf ourf uncti
onal(addi
ti
on,subtr
action,
multi
pli
cati
on,di
visi
on)
calcul
atorforanytwoi nput t
ednos.

Q4. Wr i
teamenudr ivenpr ogram whi chhasf ollowingopt i
ons–
1. Fact ori
al 2. Pr ime 3. Ev enorOdd
4. Pal indrome 5. Ar mst rong 6. Posi t
ive/Negat iv e
7. Exi t
Onceamenui tem i ssel ect edt heappr opr iateact ionshoul dbet akenandoncet hi sact i
oni s
fini
shed,t hemenushoul dr e-appear .Unl esst heusersel ectt he‘ Exit
’option,t hepr ogram
shouldcont i
nuet owor k.
Q5. Wr i
teapr ogr am t of i
ndt hegr acemar ksf orast udent .Theusershoul dent ert heclass
obtainedbyt hest udentandt heno.ofst udent shehasf ail
edi n.Uset hef ol
lowingl ogi c–
* Ifthest udentget sfirstcl assandt heno.ofsubj ectshef ailedini sgreat ert han3,t han
hedoesnotgetanygr ace.
* Iftheno.ofsubj ectshef ai ledini sl esst hanorequalt o3, thengr aceisof5mar ksper
subj ect.
* Ifthest udentget sSecondcl assandt heno.ofsubj ecthef ail
edi nisgr eat erthan2,
thanhedoesnotgetanygr ace.
* Iftheno.ofsubj ectshef ai ledini sl esst hanorequalt o2, thengr aceisof4mar ksper
subj ect.
* Ifthest udentget sthirdcl assandt heno.ofsubj ectshef ai l
edi nisgreat ert han1, t
han
hedoesnotgetanygr ace.
* Iftheno.ofsubj ectshef ailedi nisequal to1, t
hengr acei sof5mar kspersubj ect.
Q6. Inputt enchar acter sandcounthowmanyar eupper case,lower case, digit
s&speci al sy mbols.
Q7. Wr i
teapr ogr am t oi nputano.andcounthowmanydi gitsint heno.ar eev enandoddandal so
whosesum i sgr eaterandbywhatv alue.
Q8. Wr i
teapr ogram t oi nputdayno.ofaweekandpr i
ntitsequi v alentdayname.Foreg,i fno.
i
nput tedis0, thanout putwi llbe‘ Sunday ’.
Q9. Wr i
teapr ogr am t ocal culatear eaofaci rcle,rectangleorat riangledependi nguponuser ’
s
choicepassedas1,2or3f orar eaofci r
cl e,rectangleandt riangl erespectivelyi namet hod
namel ychoi ce().

FUNCTI ONS
Q1. I
nputt wonos.andpr i
ntt heirsum usingf unction.
Q2. Designamenudr ivenf ourf unctioncalculatorusingfunct i
on.Thepr ogram shoul
dtermi nat
e
onuser ’
schoice.
Q3. Designamenudr i
v enpr ogram hav i
ngopt ionstocal culateareaofr ect
angl
e,peri
met erof
rect
angle,areaofcir
cl eandper i
meterofaci rcle.
Q4. Design a menu dr i
v en pr ogr am hav i
ng opt ions t
o conv er
ttemper aturefrom Cel
sius to
Fahrenheitandvi
ce-v ersa.
Q5. I
nputanumberanddesi gnamenudr ivenpr ogram havi
ngopt i
onst oprint–
(a) Fact ori
al (b) Bi nar yEquivalent
(c) Mul tipl
i
cati
onTabl e (d) Oct alEquivalent
(e) Pr i
meFact ors (f) Hexadeci mal Equi
val
ent
Q6. I
nputanumberanddesi gnamenudr i
venprogram havingoptionstopri
nt–
(a) Sum ofDi git
s (b) Pal i
ndrome
(c) Pr i
meNumber (d) Ar mstrong
Q7. I
nputtwonumber sanddesi gnamenudr i
venpr ogr
am hav i
ngopt i
onstopri
nt–
(a) Fi r
stno.rai
set othepowerofsecondno. (b) Fi r
stno.isdi
visi
blebysecondno.
ornot.
(c) HCFandLCM oft hetwonos. (d) Hi ghestofthetwonos.
(e) Swapt hei
rvalues
Q8. Writ
eapr ogr
am toobt ai
nthesum ofthefi
rsttentermsoft hefoll
owingseri
esusingrecur
sion

x1 x3 x5 x7
- + - + .
..
..
.
1! 3! 5! 7!

Q9. Twodat esar eent ere3dt hroughkey boar di ndd- mm- y yf or mat .Writeapr ogr am t of indoutt he
differencei nt heset wodat esi nt ermsofnumberofday s.
Q10. Consi deracur r
encydenomi nat i
onsi nwhi cht her ear enot esofsev endenomi nat i
ons-1,2,5,
10,20,50&100.I fasum ofRs.N i sent eredt hr ought hekey boar d,wr it
eapr ogr am t o
comput et hesmal lestnumberofnot est hatwi ll
combi net ogi veRs.N.( usepoi nternot ation).
Q11. Wr i
t eapr ogr am t oshowt heuseofr ecur sioni ncal cul ationofpower .e.g.ab.
Q12. Wr i
t ear ecur sivef unct i
onf orpr i
nt i
ngFi bonacci ser iesupt o10t erms.
Q13. Wr i
t eacompl etej av apr ogr am t hati nv okesaf unct ion‘ sat i
s()’t
of indwhet herf ouri nteger sa,
b,c, dsentt osat i
s()sat i
sf yt heequat iona3+b3+c3=d3ornot .Thef unct ionsat i
s( )returns
0ift heabov eequat ioni ssat i
sfiedwi tht hegi venf ournumber sother wi sei tr eturns- 1.
Q14. Wr i
t eapr ogr am t hatusesaf unct i
on‘ power ()’tor ai seanumber‘ m’ topower‘ n’
.Thef unction
takes‘ int’v aluesf or‘m’and‘ n’andr etur nst her esul tcor rectl
y.Useadef aul tv alueof2f or‘n’
tomaket hef unct ioncal cul atesquar ewhent hisar gumenti somi tted.Wr i
teamai n( )togett he
valueof‘ m’ and‘ n’ t
odi spl ayt hecal cul at edr esul t.
ARRAYS
Q1. Wr i
t eapr ogr am t oinput10nos.&pr intt heirsum andav er age.
Q2. Wr i
t eapr ogr am t osear chf orapar ticul arno.i nanar rayof10nos.usi ngLi nearSear ch.
Q3. Wr i
t eapr ogr am t osear chf orapar ticul arno.i nanar rayof10nos.usi ngBi nar ySear ch.
Q4. Pr intt hehi ghestandl owestof10i nput t ednos.
Q5. Wr i
t eapr ogr am t oacceptsal esofeachdayoft hemont handpr i
ntt het otal salesandav erage
salesoft hemont h.
Q6. Wr i
t eapr ogr am t ocountt henumberofempl oyeesear ni ngmor ethanRs.10l akhperannum.
Themont hlysal ariesof100empl oyeesar egi ven.
Q7. I nputmar ksandr ollno.of10st udent sandpr intt her oll no.whosecur edhi ghestmar ks.
Q8. Wr i
t eapr ogr am t or eadsal esof5sal esmeni n12mont hsandt opr intt ot alsal esmadeby
eachsal esman.
Q9. Wr i
t eapr ogr am t ocal cul ategr adesof5st udent sf rom 3t estscores.
Q10. Sor ttheel ement sofanyar rayof10nos.i nascendi ng/ descendi ngor derusi ngSel ect ionSor t
.
Q11. Sor ttheel ement sofanyar rayof10nos.i nascendi ng/ descendi ngor derusi ngBubbl eSor t.
Q12. Wr i
t eapr ogr am t ost oreel ement si na2D ar ray( squar emet rics)anddot hef oll
owi ng
oper ations–
(a) Di spl ayt heel ement si nmet ri
csf or m.
(b) Tr ansposet heel ement sanddi spl ayt hem i nmet ricsf orm.
(c) Sum andAv erageoft heel ement sst or ed.
(d) Sum ofeachr owandeachcol umn.
(e) Sor ttheel ement si nascendi ngor der .
(f) Hi ghestel ementofeachr ow.
(g) Hi ghest&l owestel ementoft hear r
ay .
(h) Sum ofev enandoddnos.
(
i) Conv ertt hemet ri
csi nt oani dent it
ymet rics.
(
j) Sum ofeachdi agonal andcompar ewhi chi sgr eat er.
(
k) Sum ofupperandl owerel ement soft hedi agonal .
(
l) Countt hef requencyofeachel ementandpr intwhi chel ementoccur smaxi mum i nno.
(
m) Checkt heoccur renceofasear chel ementanddi spl ayi tsr owandcol umnno.( i
fexi st s).
(
n) Inputano.andcounthow manyel ement sar egr eat ert han,smal lert hanandequalt o
thati nput t
edno.
(o) Sor ttheel ementofi ndividual row.
Q13. Inputt heel ement soft wo2Dsquar emet ricsanddot hef ollowi ngoper ationandst or et he
resultint het hi rd2Dsquar emet ri
cs.
(a) Addi t
ionoft womet rics (b) Subt ract ionoft womet rics
(c) Mul tiplicat ionoft womet rics
Q14. Insertt heel ement si nasi ngl edi mensi onal arr ayandconv er tthem i ntoequi valent2Dar ray .
Q15. Insertt heel ement si na2Dar rayandconv er tthem i nt oequi v alentonedi mensi onalar r
ay .
Q16. Twoonedi mensi onalar r
ay scompr isesofel ement sst oredi nasor t
edmanner .Youar e
requiredt ost or et heel ement soft heset wo1- Dar ray si nat hird1- Dar raysucht hatt her esul t
i
sagai ninsor t edor der .
fore.g. Ar ray‘ A’ element s-7, 13,26, 37, 42, 58, 65, 72, 77, 83
Ar r
ay‘ B’ element s-3, 7, 18, 37,45, 58, 67, 89, 93, 97
Ar r
ay‘ A’ element s-3, 7, 7, 13, 18, 26, 37, 37, 42, 45, 58, 58,65, 67, 72,77, 83, 89, 93, 97
Q17. Wr i
teapr ogr am t hatcheckwhet herornott woar ray s( ofchar act ers)ar ei dentical,t hati s,
whet hert heyhav esamechar act ersandal l char act ersi ncor respondi ngposi tionar eequal .
Q18. Wr i
teapr ogr am Upper -halfwhi cht akesat wodi mensi onalar ray‘ A’,wi thsize‘ n’rowsand‘ n’
columnsasar gumentandpoi ntt heupperhal foft hear r ay .
23150 23150
71531 1531
eg. I f‘A’ i
s 25781 Theout putwi l
l be 781
01501 01
34915 5
STRI NGHANDLI NG
Q1. I nputast ringanddot hef ollowi ngoper ations–
(a) Lengt hoft hest r
ing (b) No.ofchar act er s,bl anks&wor ds
(c) Countv owel s (d) Countupper case, lower case, di git
s&speci al sy mbol s
(e) Sor tthest r i
ng (f) Fr equencyofi ndividual charact er
(g) Sear chf orasubst ri
ng (h) Conv er tupper caset olower case&v ice-v ersa
(i) Sear chf orachar act er (j) Repl acemor et hanonebl ankspacewi thsi ngl e
space
Q2. I nputast ringandchecki tispal indr omeornot .
Q3. I nputt wost ri
ngandcheckwhet hert het wost ringsar eequal ornot .
Q4. Concat enat et woi nput t
edst rings.
Q5. I nputt henameofacandi dat eanddi splayi tas–
(a)IfInput=‘ MohandaKar am ChandGandhi ’ thenOut put=‘ M. K.C. G.’.
(b)IfInput=‘ MohandaKar am ChandGandhi ’ thenOut put=‘ M. K.C. Gandhi ’
.
Q6. Wr i
teapr ogr am t oext ractapor ti
onofachar act erst r
ingandpr i
ntt heext ractedst ring.
Assumet hat‘ m’ char acter sar eext racted, st ar tingwi tht he‘ nt h’char act er.
CLASSES
Q1. Wr i
teacl ass‘ Conv ert’ wi t
hmet hodsasf ol lows–
(a) ‘ Distance’-t akes4ar gument sr epr esent ingmi l
es,y ar ds,f eetandi nchesandconv er t
s
them i nt oki l
omet ers, met ersandcent i
met ers.
(b) ‘ Temper atur e’ -takesanar gumentr epr esent ingdegr eesFahr enhei tandconv ertsi ti nto
degr eeCent igrade.
(c) ‘ Distance’-aki loby tei si nter pretedi nt woway s:somet i
mesi tis1000by t
es( actual ly
correct),butof ten( andt raditional ly)i tis210 whi chi s1024.Si mi l
ardi screpanci esar i
se
10
formega,gi ga,t eraandpet a( eachi s1000( or2 )t imest hepr ev i
ousone) .The
3 10
functionshoul dt aket he10 ( standar dki lo)andgi vet heequi valentv alueusi ng2 asa
kil
of oral lt
heabov e.
Q2. (a) Def ineacl ass‘ Dat es’.Addr equi redf unct ionseg.Const r
uctor s,printing&v ali
datinga
dateetc.
(b) Uset heabov edef i
nedDat edat aty pei nadi fferentcl assf orcr eatingobj ect ssuchas
bir
thDat e, j
oinDat e,examDat eet c.
Validatet hesedat es.Tr yv eri
fy ingt hem bypassi ngi nv ali
ddat eeg. ,33/ 12/ 03.
Q3. Implementacl asst or epresent2Dpoi nt( x,y ).Youshoul dbeabl etopr i
ntt hecoor di
natesof
thepointandal socompar et het wopoi nt sf orequal ity.
Q4. Wr i
teapr ogr am t oimpl ementa‘ circle’cl ass.Youshoul dbeabl etodi spl ayt her adius,area
andper i
met eroft heci rcle.
Q5. Wr i
teapr ogram t oimpl ementa‘ student ’ class.Hav ea‘ result’met hodasmemberoft hecl ass.
Thismet hodshoul dt akesmar ksi nt hreesubj ect saspar amet ersanddi splayr esultoft he
student.
Q6. Swapv aluesoft woi nteger st hroughbot ht y pesoff unct ioncal li
ngmechani sm.
Q7. Wr i
teapr ogram t oconv ertdistancei nf eetori nchesusi ngacal lbyr eferencemet hod.
Q8. Designacl asst or epresentabankaccount .Includet hef oll
owi ngmember s–
Datamember s- nameoft hedeposi tor ,typeofaccount ,accountnumber ,bal anceamount .
DataMet hods- * toassi gni nitial v alue
* todeposi tt heamount
* towi thdr awanamountaf terchecki ngbal ance
* todi splayt henameandbal ance
* dowr itepr operconst ructorf unctions

FI
LEHANDLI NG
Q1. Readnamesof5st udent sthroughkey boar dandst oret hem i nf i
le‘names. t
xt’.
Q2. Readdat afrom t extf i
le‘names. txt’anddi spl ayi tonmoni tor.
Q3. ReadRol lnoandMar ksof5st udent sf rom af il
e‘ stu1.dat ’andst oret hem onaf i
lenamel y

stu2. dat’
.
Q4. Rol lnoandmar ksofsomest udent sarest or edi nf i
le‘ stu.dat’.Creat ea‘ topper .
dat’fi
lethat
cont ainsdataofonl yt hosest udent swhohav escor edmor et han75%mar ks.
Q5. Wr i
teapr ogram t hatr eadsat extf il
eandcr eat esanot herf i
l
et hatisi dent i
calexceptt hatevery
sequenceofconsecut i
vebl ankspacesi sr epl acedbyasi nglespace.
Q6. Wr i
teapr ogram t hatcopi esonef il
et oanot her .Hast hepr ogr am t otaket hef i
lenamesf rom
theuser ?Hast hepr ogram t oref usecopyi fther ealreadyi saf i
lehav i
ngt het argetname?
Q7. Wr i
teapr ogram t hatappendst hecont ent sofonef i
let oanot her.Hav et hepr ogr am t
aket he
fi
lenamef rom theuser .
Q8. Wr i
teapr ogram t hatr eadschar act ersfrom t hekey boar donebyone.Al llower casecharacters
getst oredinsidet hefileLOWER, allupper casechar act ersgetst oredi nsidet hef i
leUPPERand
allotherchar acter sgetst oredi nsi dethef ileOTHER.
Q9. Wr i
teapr ogram t osear cht henameandaddr essofper sonhav i
ngagemor et hat30y ear
si n
thef il
e‘persons. dat’.
Q10. Wr i
teapr ogr am t hatcount sthenumberofchar act
er s,wor dsandl inesi nthef i
le.

You might also like