test 2 prog-1

13
TCBZAT3 Structured Programming and Database ': i-! f; li Test 2 L SET B 1. What is the syntax qrror in the following funclion definitiqn? string area (double r) { double a; a = 3.14 * r * r; return r * r; ) ,.d.. The value that is retumed does not match the specified return type. b. The function does not retum the value a. c. The variable a is set but never used. d. The function does not speciff a return type. ", 2. What is incorrect in the following code snippet? void display._box (string str) { cout (( tt-.-------tt << endl; caut << str _(( endl; cout (( 'r--------rr << endl; ] rll! rrain o { cout << display_box ("He11o Worl-d* ) ,. return 0; ) a. The return value from display_box is never used. ;i b. display-box does not return a value; therefore, it cannot be used with cout <<. c.,. display_box is called with incorrect parameters. ,.d. display-box should be cailed in an assignment statement. 3. Which of the following is true about functions? a- Functions can have multiple parameters and can return multiple return values., ,.b;" Functions can have multipie parameters and can retum one return value. c. Funetions can have one parameter and can return multiple return values. d. Functions can have only one parameter and can return only one retum value. Ia7,e 12

description

programming

Transcript of test 2 prog-1

Page 1: test 2 prog-1

TCBZAT3 Structured Programming and Database ': i-! f; liTest 2

L

SET B

1. What is the syntax qrror in the following funclion definitiqn?

string area (double r){

double a;a = 3.14 * r * r;return r * r;

)

,.d.. The value that is retumed does not match the specified return type.b. The function does not retum the value a.

c. The variable a is set but never used.

d. The function does not speciff a return type.

", 2. What is incorrect in the following code snippet?

void display._box (string str){

cout (( tt-.-------tt << endl;caut << str _(( endl;cout (( 'r--------rr << endl;

]rll! rrain o{

cout << display_box ("He11o Worl-d* ) ,.

return 0;)

a. The return value from display_box is never used. ;i

b. display-box does not return a value; therefore, it cannot be used with cout <<.c.,. display_box is called with incorrect parameters.

,.d. display-box should be cailed in an assignment statement.

3. Which of the following is true about functions?a- Functions can have multiple parameters and can return multiple return values.,

,.b;" Functions can have multipie parameters and can retum one return value.c. Funetions can have one parameter and can return multiple return values.d. Functions can have only one parameter and can return only one retum value.

Ia7,e 12

Page 2: test 2 prog-1

6laEe;

9999 'p

0000 '5, 9yz0'q,,i ' ozvg 'e

{! r, n )) Tel\U >> JnOC

t: (Z - Te^u)1err,ztur1sa1

l(0

)

(1erru 1ur) lezrAufso? pTo^

l,leddrus epoc 8uv*olloJ 6qi ur (!)ien{u4so} st IIBo uorlcuru: aq}JI ind}no ogi sl leq1tr "S

'sltrulsuoo lou 6salqerJ€A ss s;lur orll sJulJaO 'p'lSoJS}UI

Jo elBJ B pue lunorue ue tuoiJ peulue lserelur eqi selnduoc lerll uorlouru:u arigeq ';c'peuJee NeJslur eql sunloJ

ueql tsaralur Jo eleJ B prre J.unotuu ue roJ resn eql sldruord luql uorlcunJ u eu$eg'seter trsoJelur dn slool leql uorlcunJ e ougoq

'q,e

j00r / zsr\.d

j00r / TSJVU +

+ ecueTeq + acueTeq - esueTBq

:|ueurlsa^uT = trsajroluT "ro;;ojg'E = zsJ,vu aTqnop lsuocigi = Isrfu eTqnOB i6uoc

6uerBord eqlanordrn ol ouop eq plnoc pq16 'urur6o.rd eqt u1 seculd Jeqlo leronas ur pu? /Koloq urrror{sseceld o^ l oq1 ur 'selqeuu^ lueJeJJrp qtl^{ tnq '$ere}ur JeSe secueleq {wq Eurtnduocro3 urqtrro8lu aues eql sesn loddrus epoc SuvrtolloJ eql tur{l seulou :eurue;8o.rd y 'V I

e strh

Z ]SAIaseqelec pue SurururerSord parnlrnrls t/Ozgll

B I3S

Page 3: test 2 prog-1

.l1,.i

TCB2 073 Structured Programming and DatabaseTest 2

6. Which of the following options,represents the output of the given code snippet?

#include <iostream> ,rr i,vold addsub(j_nt at int& sub, inte add)f

sub=a-1.. +

add=a+I;](.int main ( )

{

inta=5;intb=0;lQlg=Qi , ,

addsub (a, b, cj ; r- \ r

coutreturn 0; ]

a. -_Subtract: 4, Add : J

_,b. Subtract:4, Add:6c. Subtract = 5, Add: Jd. Subtract:6, Add: g

7. Consider the following code snippet:

int ctr: 0;int myanay[3];for (int i :0; i

-< 3; i-rt)

{rmyarray[i] - ctr;ctr: ctr + i;

)cout << myxraypl;

What is the output of the code snippet?

a. Ib.2c.3'd.0

8. Identify the correct statement fcrr defining an integer affay named numcount of fiveelements.

a. int numcount[5];" b. int numcount[]; .j{r ir)i

i:';ri.;e l4

Page 4: test 2 prog-1

gl;i:,:,_;

v'p0'5(, 'q

9'e

{

J0 uf,nJefjurnsf

i (efep^)Ical"{3 - uns.T{

j (f + 1uc)>lceQ qsnd'e1epn]

(++?uc ieju:iS.r 1uT

J (t ) ef ep^ <?ur>.roJco,\l

( ) ureu fur{

iurns uf,nJaf,t

i [r] efPplce^ + uns - uns)

l\

(++1 !Oazrs'pfpplce^ > T j0 = T fuT) roJ,'- lQ - tuns lUT

](ef,pplca^ <fuT>.rof,Je^) {ceqc truT

l,lsddrus epoc 8ur/(olloJ or.llJo tndlno aql sr tpq1[ '0 t!i

E'pT, 'tn'q

: ' 'i j o azrs.unu >> ,".:

'e

! (e ){ceq-qsnd.urnui (e )urnu <1uT>f,of con t_1

1

ileddrus opoo SurmolloJ eWJo 1nd1no eW sr tBqA\ '6

i[fltunocurnu ]urp[unOituhu[g] 1u1 "c

_."."".9l]s.

Z ]SAJaseqele( pue EururuerEord parnlf,n4s t/OzgJl

Page 5: test 2 prog-1

TCBZAT3 Structured Programming and Database | :*il r r,Test

SET B

11. What is the output of the {ollowing code snippet?i ':.

int pow (int base, int power)t

i

int result : 1; ..

for (int i : 0; i < power,. i++){

result:result*base;i!:return result; il i - \

),,int main{

cout << pow(pow(2, 2), 2) (< endl-;return 0;

)

a. 4 jj

b.8,p: i6'd. ?z

12. What is the output of the following code snippet?

vector<int) num(4);num.push_back(4);cout << num. size O ;

/a.4b"sc. 1 lt!.,id.3

13. Considerthe following code snippet:

int mymarks [10] ;int total i .,

f or (int cnt +. I ;l{\

coutcin )> mymarkstotal : total

\'.,i . \.

r',)'t t '; ,-J

cnt (= 10; cnt++)

the marks: " iIcnt];* mymarks Icnt];

r:ga l5

Page 6: test 2 prog-1

4l:;,i:.;

(-r+1 i0I

iiunuuaAai Tunu

iunuueAel lurnu

iT fuT) f,of

lefep f,ur<f uT>.ro1ce/!<lUT>fOJce/\ '3

I ( tTlTunu)>1ceq qsnd'urnuuerra)

(0 -i Z Z Ir]Iurr:u) JTj ( ef,ep ) >1ceq qsnd' lurnu

ielep << uT3i

(++l j0T T fuT) roJsefEp IUT

<luT>JoJcel\<Jur>fof,3aA 'q

{j ( tTllunu)>1ceq qsnd'urnuuana]

(0 :: Z Z [r] Iunu) Jr1 ( Pf ep 1 lceq qsnd' lurnu

t ^4 ': e+ep << uTc

)(++T j0T

ref,ep fuTjunuuola <truT>f,o?cal /Jlunu <fuT>.rofcaL'/U

- - 6tunuueAe petu€u ,{ete raqlouu ut Itunu;o sta8elur uela eql saJo}s pue lurnu-petueu {euu ue ur lndur ieFS6eq} sldecae spddrus opoJ Eur^\olloJ ewJo euo qclqly\'?l

"e1ep luupunper s^ror{s ro roJJo spunoq € sesrer }eddrus opor aql .p :u'lldllq ug tgu'4gue gu11?Wpunr e !q4l31edd1uq epoc aq; ;o''

's1celqns uei lte Jo slretu t?lol eql s,(eldsrp tsCdrus epCIc eqf ' "q

6leddrus epoc ue,u8 aql Eurincexe uo pe,{eldsrp s1 slndlno 8urno11og eqtJo euo qcrry\[

lTelof, >> Jnoct

.l

I' /')

iirytC lsaJ,

i:. i;iti, ! aseqeteq pue SururuerSord parnpnrls t/0Zgf,I

I tls

Page 7: test 2 prog-1

TCB2a73 structured Frogramming and DatabaseTest 2 I--

{SET B

cin >> dqta;nunlIi] : dat.a;if (num1 [i] % 2"':- 0){evennum[i] : numl til ) ;)

1)

d" vector(int> numl;vector(int> evennum;int data;forinti-0;i<10;i++;

{cin >) c_tata;numl . push_back (data) ;if (numltil Z 2 l- 0){

evennum[i] : numl til ) ;]

)

15. Consider the following code snippet:

int ctr : 0;int myarray[3] ;for(inti-0;i<3;i++;{

myarray Ii ] -= ctr,.ctr:ctr+i,.

)

cout (( myarray[2];

What is the output of the code snippet?a.0b. 1

c.2d:3

16. which of the following statements displays 12i.567 w r23.57?

a. coutb " coutc. cout (( setw(5)

l.;1:e l8

Page 8: test 2 prog-1

6l?5c,j

i0 = ssed-lunoo alqnooi0 : TeloJ ?uT

l eureu 6ur:1s]

0u1eu 1ur

l,laddrus epoc EurrrrolloJ eqlJo lndlno eql sl ]BqA(\

0E lsnures

09 uoulls

0t ueqou

gg1 no1,(reyr1

08 ur{of

06 relad

:e1ep EurvrolloJ eql sureluoo ,,lxl'qlnsog,, elg eql leqt atunssv .61 .

III PUB .II .I 'P

ill pu? il 'c

IIIpuel 'q _

II pue I....)E'

aa)ieu ol poeu no,( op so8ueqt lsqi[t- -'

, stcalqo .,,ue4sJlroJ suolte":edo eleudordde aqt qllnr eurlle8 puu << Jo secuirrncco 11e aozldeE 'lil

elg ul r{lt^\ urc Jo secuorrncco 11e eculdag )I-erunl elqeuun ueoJNJr ue aJulce0 "IsaSuuq.

Eu1mo11o3 eqt Supepgsuoc er€ no1 'elg s r.uog slup peeJ uec no.{ }eql os t1 lueueldurero1 partnber A\ou sJ€ no1 'ulc tuo{ elep speeJ 1eql wer8ord e e}oJ1y\

'no,( esbddns .g l

:;.. r! . lL L!-i\11 .1 , :'\i \16 a{ -l rt ' } n.'.1r N.\]*

l{ g't'9'S'V't,2,1,0 }:[],(eueeruos 1u1 .,p'

, l{ g ', og'g'V'E'Z'l '0 } : [g1]fer.rceuros 1ur".c!{ 0l'6'g'L'9'S'V't'e'I'0} : [61].{euuouos }ut .q

l{ 6'g 'L'9'g'V't'Z 'l '0 } - [ ],{errueuos 1ur -E

pe.,€u fu:re ue Jo uor,nzrrenrur pire^ur ue sr slue.,,el€'s t"iil:i,;"t:r11j".fffiilli ,t'1nd1no pa:"rnba: oqf s{eldstp suolldo ai{f, fo auoN -p

i Z ]SAJI ; ill i aseqeleo puE EurururerEor6 paJnpnls t/0zgll

i

gI]s

Page 9: test 2 prog-1

ITCB207 3 structured Programming and Database ! .lri i ,:

Test 2 iTil'd*"*"- .**."-','- I--

double dv€rag€ : 0;int scores;ifstream in file;in_file. op.n ( "Results , txt" ) ;while (in_file >> name{

if (scores )= 50) i, :lrl

'ir'r''{\total:total+score

, co1r,ra-pa9g++, =t' :'il)

ieiverage : total_ / count_pass;cout

average << endl_;return 0;

)

a. The average ofpassed students: 0b, Thc averagc ofpassed studeots: 90e . There is no output due to compilation errors..d" The average ofpassed students: g5

-i 20. Consider the following code snippet:

ofstream out_fil-e;out_f ile. open ( "Scores. txt,, ) iout file <l 'peterout_fi le

Assuming that the file "Scores.txt" does not exist, which of the following statements istrue about the above code snippet?

a" The code snippet causes an error due to the missing file.b' The code snippet causes an error because both striig and integer cannot be writtenin the same line of text.

c. The code snippet creates a new file "Scores.txt" and writes the data to it.d. The code snippet creates a new file "Scores.fxt" with no data in it.

21. Consider the following code snippet:

#include (iostream)#include <fstream)int main ( )

tchar ch;int n;

i:'::ge 110

Page 10: test 2 prog-1

IIlr::!j

j (,,uedo 01 aTrJ,,)uado"eTTJ uT "ql (Uado-oi-aTTJ ) uedo " eTri-uil P

jaTTJ Ur l.uEa.ftrsJTiuedo-of, aTTf ,<< uTcluado-o1 eTTl 6u1.:1s

JTpue >> ,A:Aureu aTTJ Ot{tr laf,uo aseeTd,, )) f,noc

6uado o1 olg elqsue^ eql ul paulsluoc sI slueu

osoqa elg e uado ol leddrus xeluds tcerloc aql slueserder suopdo 3urmo11o3 eqlJo t{c!qA\ 'tZ

"s8uuls u1{}r1\[ peur€]uoc eJE l€q] sJequnu p?eJ u33 StueoJN Euulg"sru5ll pelstl eqlJo llv

'suo4urado ellJ/tt pue peoJ tlrlo3.led ol sroluredo >> puu << esn sulee4s Eu$S'sEuuls ol sJeqwnu ueluoo uB3 slueoJls Eup15

esrueerts Eupr6 lnoqe erut sI sluoruelels Eutm.o11o; eqlJo q3lqA\ 'tZ

IuopuuJ 'pfueugq 'c

s(uall p3lsll oqlJo euoN 'q

lerluenbes 'E

'ssecce polluc sl al$ s ruo{ Joqloue roge un}l auo SutpeeA '97

0u Inod 'pisprlqlselq 0z 'c

0z 'q

isprlq{celq 0z pue rnoc 'e

e,,ispr{q{celq 0Z pue rno5,, lxe} sq} suletuoo txl'sll$JI urerSo.td aqlJo }nd}no aq} sI leqlfi{

j0 ufnlaf{

{:u >> lnoc

jul O labun'eTTJ uT

)

( (i{3) lTbTPsT ) lTi

( (t{c ) 1e6 " e1'r; uT ) aT Iq}lJ (,,Jxl " aTT.{\\ :c,, ) uado' e'ITl ur

JarTf uT ueaflsJrB I]S

T'3

'q.E

I''1 Z }SAJaseqeleo pue EurtutuerEotd parnpnrrs E/SZS3;

Page 11: test 2 prog-1

SET B

d

TCBzaT 3 structured Programming and Database i : rl r .:.

Test 2 i.",._*:*"*.."._"_ I _

a, Priority;2b. There is no output because the program does not compilec. Prioritv: 3

l,:: l:112

:; }"_Iile, open (c_str ( file_to_qpen) ) ;

,d. :-n_f ile . open (f ile to_ open. c_ str O ) ;

25. In the following oode snippet, whicli line can cause a compilation error?

f . ifstream infil_e;2. infilg_. open ( " sample . txt" ) ;:' +lg+J"This is also an i-nserted text! ! !"4. infile. c-l-ose ( ) ;

.r{ Line 3b. Line 4o. Line 1

d. Line2

26. Consider the following code snippet:

vect.or(int) vectdata;

vectdata. push_back ( 90) ;

What is the size of the vector vectdata after the given code snippet is executed?

a)0b).i t

,e) 90

d)2

27. which option represents the output of the following code snippet?

int assign_priority(int priority){

return prrorrty + 2;]int main ot

int priority = assign_priority(3) ;coutreturn 0;

)

Page 12: test 2 prog-1

€Il3H:ii

'doo1 epqm eql oleuruuel ol Jel)erer1c surlJo pue u€ pBeJ lou se('p uorlounJ eql ;/'olg 6q1ur sreperur{c sqlJo 11u feldsrp lou seop uollouru eql tuo+ 1nd1no eqJ '.c'raleuaud tuuersJl or{} o} ocueJeJoJ ? esn }sntu uor}curg oqJ .q

'relarue;ed tuee4sJr eqi ol ralurod e osn Nntu uorlcurg eqJ .e

{

{jqc

l( (qc ) 146'a1-rg.ur ) eTTi{/"

lqc feqci

(aTTf uT uearlsJr) aTTJ /"lor{s pTo^

auorlrugep uollcurg Eurmollog eqt qlr&\ Euolrr sr l€ql[ .62

s#lE#/n 'p.'9/#/##0 'c

, st#/##r 'q'..) 'i s/#E//#l 'e

{

iip >> s >> lnoc

!(Z - p ,s):1sce:' lrr/rt + S - s

i\tesTo

{ip >> 1no3

)(T :> p)JT

l(p luT ,F 6ur.r1s):1sca: pTo^

i,V6taddrus epoc EuvrrolloJ oql ul (g .,,#,,):Ncer sr IIec uoltcuru eqtgl ndtno eql sr teqA\ -gz

ill\ g:K1pop4-,-;p

astsqelec pue Suruurer8ord parnpnrls E/Ozgll

g -cls

Page 13: test 2 prog-1

TCBZAT3 Structured Programming and Database i ,**Test 2 !

I

sET B

fO. WhiEh of the following optiqgs rcprese-nts the qutput ofthe givsn sode snippet?

#include (iostream)void addsub(int ,q, int& sub, int& -add){ ': i -

4 r-.

-L {3

sub:a-1;add:a+Ii

a,

b.c.d.

)int main ( )

iinta:5;intb:O;int c : 0iaddsub (a, b, c) ;couL (( "SubtractreLurn 0;

]

Subtract:4, Add:5Subtract: 5, Add : 5

Subtract:4, Add:6Subtract:6, Add:6

Page 114