Sei sulla pagina 1di 63

KENDRIYA VIDYALAYA SANGATHAN JABALPUR REGION

STUDY MATERIAL COMPUTER SCIENCE XII ( !1! B"a#$ E%a&'


Patron Smt. S. Bisarya Assistant Commissioner KVS RO Jabalpur Region Guided By: R. Radha rishnan PR!"C!PA# K.V. "ARS!"G$P%R Prepared By: &r. Sanatan Ban'i PG( Computer S)ien)e K.V. "ARS!"G$P%R.

Page 1 / 63

H"( )" *+e S)*$, Ma)e#-a./


!t *ill be mu)h bene+i)ial to those students *ho need spe)ial )are and attention. ! am sure, thorough study and pra)ti)ing similar patterns o+ -uestions o+ this material *ill help su)h students se)ure ./0 and abo1e. $o*e1er it is not 2//0 substitute +or (e3tboo . &inimum a set o+ +i1e -uestions *ith ans*ers +rom ea)h -uestions o+ the Board Pattern 4uestion Paper are in)luded, eeping in mind the needs and interest o+ target group. Con)epts in e1ery unit ha1e been e3plained using notes 5 solutions to -uestions 5 guidelines in a simple language. Pra)ti)e and peer group dis)ussion on this study material *ill de+initely impro1e the )on+iden)e le1el o+ the students *hen they sol1e the -uestions. "o* you are *el)ome to the ... )ontent ... Sanatan Ban'i PG( Computer S)ien)e KV "arsinghpur
0e-g1)age )" $-22e#e3) )"4-5+/5"3)e3) *3-)+ S. %"!( "o 2 Re1ie* o+ C99 )o1ered in Class :! 6 Ob'e)t Oriented Programming in C99 a< !ntrodu)tion to OOP using C99 b< Constru)tor > ?estru)tor )< !nheritan)e 7 ?ata Stru)ture > Pointers a< Address Cal)ulation b< Stati) Allo)ation o+ Ob'e)ts )< ?ynami) Allo)ation o+ Ob'e)ts d< !n+i3 > Post+i3 @3pressions 8 ?ata Bile $andling in C99 a< Bundamentals o+ Bile $andling b< (e3t Bile )< Binary Biles A ?atabases and S4# a< ?atabase Con)epts b< Stru)tured 4uery #anguage . Boolean Algebra a< !ntrodu)tion to Boolean Algebra > #a*s b< SOP > POS )< Karnaugh &ap d< Basi) #ogi) Gates C Communi)ation > Open Sour)e Con)epts a< !ntrodu)tion to "et*or ing b< &edia, ?e1i)es, (opologies > Proto)ols )< Se)urity d< Debser1ers e< Open Sour)e (erminologies Page

VSA
2 &ar

SA !
6 &ar s

SA !!
7 &ar s

#A
8 &ar s

(otal 26 ;.<

2 ;2<

= ;8< 6 ;2< 6 ;2<

7 ;2< 8 ;2< 8 ;2<

. ;6< 6 ;2< 8 ;2< 7 ;2< A ;6< 8 ;2< 6 ;2< 2 ;2< 6 ;2< 7 ;2<

6 ;2< 6 ;2< 2 ;2< 6 ;2<

7 ;2< 7 ;2< 8 ;2<

7;2< 6 ;2< 6 ;2< 6 ;2< 2 ;2< 7 ;2< 6 ;2< 6 ;6< 8 ;2< 6 ;6< 2 ;2< 2 ;2< / 63 8 ;2<

6 ;2< . ;6< 6 ;2< 2 ;2< 7 ;2< 6 ;2< 6 ;6< 8 ;2< 6 ;6< 2 ;2< 2 ;2<

(O(A#

E ;E<

6. ;27<

2A ;A<

6/ ;A<

C/ ;76<

Re6-e( "2 C77 5"6e#e$ -3 C.a++ XI


8*e+)-"3+ 9a+e$ "3 Hea$e# :-.e+ Ve#, S1"#) A3+(e# 8*e+)-"3+ ( 1 &a#;'
42. Drite the names o+ the header +iles to *hi)h the +ollo*ing belong: ;i< isdigit;< ;ii< str)mp;< ;iii< +abs;< ;i1< gets;< ;1i< set*;< ;1ii< e3it;< ;1iii< tolo*er;< ;i3< )eil;< ;3i< strupr;< ;3ii< atoi;< ;3iii< setpre)ision;< ;3i1< +loor;< ;31i< strstr;< ;31ii< put;< ;31iii< puts;< ;3i3< e3p;< ;33i< +*rite;< ;33ii< *rite;< ;33iii< setios+lags;< ;33i1< sin;< Ans : ;i< )type.h ;ii< string.h ;1i< iomanip.h ;1ii< pro)ess.h ;3i< string.h ;3ii< stdlib.h ;31i< string.h ;31ii< iostream.h ;33i< stdio.h ;33ii< iostream.h ;iii< math.h ;1iii< )type.h ;3iii< iomanip.h ;31iii< stdio.h ;33iii< iomanip.h ;i1< stdio.h ;i3< math.h ;3i1< math.h ;3i3< math.h ;33i1< math.h ;1< eo+;< ;3< +eo+;< ;31< remo1e;< ;33< +ree;< ;331< abs;<

;1< iostream.h ;3< stdio.h ;31< stdio.h ;33< stdlib.h ;331< stdlib.h 5 math.h 46. "ame the header +ile;s< that shall be needed +or su))ess+ul )ompilation o+ the +ollo*ing C99 )ode: 1oid main; < F )har sub'e)tG7/HI str)py;sub'e)t, JComputer S)ien)eJ<I puts;sub'e)t<I K Ans : string.h "ote: &ar s are not to be dedu)ted i+ any additional header +ile is stdio.h mentioned. But these header +iles must be *ritten. 47. "ame the header +ile;s< that shall be needed +or su))ess+ul )ompilation o+ the +ollo*ing C99 )ode: 1oid main; < F )har nameG6/HI gets;name<I )outLLset*;6/<LLnameI K Ans : iomanip.h stdio.h 48. "ame the header +ile;s< that shall be needed +or su))ess+ul )ompilation o+ the +ollo*ing C99 )ode: 1oid main; < F )har a, bI a M get)har;<I b M toupper;a< )outLLJNn(he upper)ase )hara)ter o+ OLL a LLJ is O LLbI K Ans : )type.h stdio.h Page 3 / 63

4A. "ame the header +ile;s< that shall be needed +or su))ess+ul )ompilation o+ the +ollo*ing C99 )ode: 1oid main; < F )har numGHMP2/68PI )outLLPNn(he ne3t number to PLL num LLP is P LLatoi;num<92I )outLLPNn(he s-uare root o+ PLLnumLLP is P LLs-rt;atoi;num<<I K Ans : stdlib.h math.h

C"35e4) 8*e+)-"3+ 9a+e$ "3 C77 Re6-e( S1"#) A3+(e# 8*e+)-"3+ ( &a#;+'
42. Dhat is the di++eren)e bet*een a ey*ord and an identi+ier in C99Q Gi1e e3amples o+ both. Ans : Key*ord is a spe)ial *ord that has a spe)ial meaning and purpose. Key*ords are reser1ed and are +e*. Bor e3ample: goto, +or, *hile, i+, else et). !denti+iers are the userRde+ined name gi1en to a part o+ a program. !denti+iers are not reser1ed. !t should be the name o+ any ey*ord. Bor e3ample: name, stud, Smy+ile, op et). 46. Dhat is a re+eren)e 1ariableQ Dhat is its usageQ Ans : A re+eren)e 1ariable is an alias name +or a pre1iously de+ined 1ariable. (he usage o+ it is that the same data ob'e)t )an be re+erred to by t*o names and these names )an be used inter)hangeably. 47. Drite t*o ad1antages o+ using in)lude )ompiler dire)ti1es. Ans: ;i< (he Tin)lude )ompiler dire)ti1e lets us in)lude desired header +iles in our program *hi)h enables us *or *ith all de)laration 5 de+initions 5 ma)ros inside the in)luded header +ile;s<. ;ii< !t supports modularity. 48. ?i++erentiate bet*een a #ogi)al @rror and Synta3 @rror. Also gi1e suitable e3amples o+ ea)h in C99. Ans : #ogi)al @rror: @rror o))urred due to in)orre)t logi) applied by the programmer. Synta3 @rror: @rror o))urred due to not +ollo*ing the proper grammar5synta3 o+ the language OR the error o))urred due to 1iolating rules o+ the programming language @3ample: 55Program to +ind area and perimeter o+ re)tangle 1oid main;< F int AM2/, BM6/, AR, PI ARM6U;AUB<I 55#ogi)al @rror V Drong Bormula PM6U;A9B<I )outLLALLP WWendlI 55Synta3 @rror V %se o+ WW *ith )out K 4A. Dhat is the di++eren)e bet*een Global Variable and #o)al VariableQ Ans: Global Variable !t is a 1ariable, *hi)h is de)lared outside all the +un)tions !t is a))essible throughout the program. #o)al Variable !t is a 1ariable, *hi)h is de)lared *ith in a +un)tion or *ith in a )ompound statement !t is a))essible only *ithin a +un)tion5 )ompound statement in *hi)h it is de)lared. Page < / 63

Tin)ludeLiostream.hW +loat "%&ME//I 55"%& is a global 1ariable 1oid #OCA#;int (< F int (otalM/I 55(otal is a lo)al 1ariable +or ;int !M/I!L(I!99< (otal9M!I )outLL"%&9(otalI K 1oid main;< F #OCA#;8A<I K 4.. Dhat is the di++eren)e bet*een Ob'e)t Oriented Programming and Pro)edural ProgrammingQ Ans : Ob'e)t Oriented Programming Pro)edural Programming @mphasis on ?ata @mphasis on doing things ;+un)tions< Bollo*s BottomR%p approa)h in Bollo*s (opRdo*n approa)h in program design program design ?ata hiding +eature pre1ents a))idental Presen)e o+ Global 1ariables in)rease )hange in data )han)es o+ a))idental )hange in data Beatures li e data en)apsulation, Su)h +eatures are not a1ailable polymorphism, inheritan)e are present 4C. ?i++erentiate bet*een a Call by Value and Call by Re+eren)e, gi1ing suitable e3amples o+ ea)hQ Ans: Call by Value Call by Re+eren)e (he )alled +un)tion )reates its o*n (he )alled +un)tion a))esses and *or s *ith )opies o+ the original 1alues sent to it. the original 1alues using their re+eren)es. Any )hanges that are made in the Any )hanges that o))ur in the +un)tion run, +un)tion run, )hanges in the original )hanges in the original 1alues are re+le)ted. 1alues are not re+le)ted. 1oid )hange;int b< 1oid )hange;int >b< F F b M 2/I b M 2/I K K 1oid main;< 1oid main;< F F int a M AI int a M AI )outLLJNn a M OLLaI )outLLJNn a M OLLaI )hange;a<I )hange;a<I )outLLJNn a M OLLaI )outLLJNn a M OLLaI K K Output *ill be: aMA Output *ill be: aMA aMA a M 2/ 4=. Dhat is a parameterQ ?i++erentiate bet*een an a)tual and a +ormal parameter *ith an e3ampleQ Ans : Parameter is the 1ariable 5 1alue passed to a +un)tion or the 1ariable that is used as the in)oming 1alues in a +un)tion. (he 1ariables 5 1alues passed to a +un)tion are )alled a)tual parameters. (he 1ariables that are used as the in)oming 1alues in a +un)tion are )alled +ormal parameters. Bor @3ample: Page = / 63

1oid )hange;int b< 55 b is the +ormal parameter F b M 2/I K 1oid main;< F int a M AI )hange;a<I 55 a is the a)tual parameter )outLLJNn a M OLLaI K 4E. @nlist any +our 'ump statements *ith their uses. Ans : ;i< goto : A goto statement )an trans+er the program )ontrol any*here in the program. ;ii< brea : A brea statement enables a program to terminate o+ the loop5blo) , s ipping any )ode in bet*een. ;iii< )ontinue : A brea statement enables a program to +or)e the ne3t iteration to ta e pla)e, s ipping any )ode in bet*een. ;i1< return : A return statement is used to return +rom a +un)tion. 42/. $o* are the +ollo*ing related to one anotherQ ;i< array and stru)ture ;ii< stru)ture and )lass Ans: ;i< Array is a group o+ items o+ the same data types *hereas stru)ture brings together a group o+ related data items o+ any data types. ;ii< Stru)ture is a)tually a )lass ;in C99< de)lared *ith ey*ord stru)t. By de+ault, all members are publi) in a stru)tureI on the other hand all members are pri1ate by de+ault in a )lass.

8*e+)-"3+ 9a+e$ "3 P#"g#a& E##"#+ S1"#) A3+(e# 8*e+)-"3+ ( &a#;+'


"ote : @rrors are e3plained in the solutions. Dhile sol1ing su)h type o+ -uestion, a student should )are+ully go through )orre)tness o+ ea)h statement and the logi) o+ the *hole program. Students are ad1ised to pra)ti)e 1arious -uestions to de1elop the s ill o+ +inding the errors. 42. Re*rite the +ollo*ing program a+ter remo1ing the synta)ti)al errors ;i+ any<. %nderline ea)h )orre)tion. Tin)ludeLiostream.hW int +un);int y M2/, int >3< F i+;30y M /< return 993 I else return yRR I K 1oid main;< F int p M 6/, - M 67I r M +un);p,-<I )outWWpWW-WWrI K Ans: Tin)ludeLiostream.hW int +un);-3) , , int >3< 55 1iolating the rule o+ ?e+ault argument F i+;30y > > /< return 993 I else return yRR I 55 M M relational operator K 1oid main;< F int p M 6/, - M 67I Page 6 / 63

-3) r M +un);p,-<I 5"*) ?? 4 ?? @ ?? #I

55 r should be de)lared 55 LL operator +or )out

K 46. . Re*rite the +ollo*ing program a+ter remo1ing the synta)ti)al errors ;i+ any<. %nderline ea)h )orre)tion. Tin)ludeLiostream.hW 1oid main;< F int :G HMF./,A/,7/,8/K,XI )ountM8I )inWWXI +or;iM)ountR2IiWM/IiRR< s*it)h;i< F )ase 2I )ase 6: )outLLX U :I brea I )ase 7: )outLLX9 XI K K Ans: Tin)ludeLiostream.hW 1oid main;< F int :G HMF./,A/,7/,8/K,XA 5"*3)><I 55 multiple de)laration separated by )omma )inWWXI +or;-3) -M)ountR2I iWM/I iRR< 55 i should be de)lared s*it)h;i< F 5a+e 1/B 55 )ase should +ollo* by : )ase 6: 5"*)??YCXD-EI brea I 55 #1alue re-uired +or : )ase 7: )outLLX 9 XI K K 47. Re*rite the +ollo*ing program underlining the synta)ti)al errors ;i+ any< and its e3planations. Tin)ludeLiostream.hW 1oid main;< F int n M 88I int Uptr M >nI 99;Uptr<I int U)onst )ptr M >nI 99;U)ptr<I 99)ptrI )onst int nM==I )onst int Uptr) M > nI 99;Uptr)<I 99ptr)I )onst int U)onst )ptr) M> nI 99;U)ptr)<I 99)ptr)I K Ans: Tin)ludeLiostream.hW 1oid main;< F int n M 88I int Uptr M >nI 99;Uptr<I int U)onst )ptr M >nI Page F / 63

77(C54)#'B 55)annot modi+y the )onstant 1alue o+ U)ptr 99)ptrI )onst int nM==I )onst int Uptr) M > nI 77(C4)#5'I 55)annot modi+y the )onstant 1alue o+ Uptr) 99ptr)I )onst int U)onst )ptr) M> nI 77(C54)#5'I 55)annot modi+y the )onstant 1alue o+ U)ptr) 7754)#5I 55)annot )hange the )onstant address o+ )ptr) K 48. Re*rite the +ollo*ing program a+ter remo1ing the synta)ti)al errors ;i+ any<. %nderline ea)h )orre)tion. Tin)lude Liostream.hW stru)t Pi3els F int Color,StyleIK 1oid Sho*Point;Pi3els P< F )outLLP.Color,P.StyleLLendlIK 1oid main;< F Pi3els Point2M;A,7<I Sho*Point;Point2<I Pi3els Point6MPoint2I Color.Point29M6I Sho*Point;Point6<I K Ans: Tin)lude Liostream.hW stru)t Pi3els F int Color,StyleIK B 55 ?e+inition o+ stru)ture Pi3els must be ended *ith I 1oid Sho*Point;Pi3els P< F )outLLP.Color ?? P.StyleLLendlIK 55 !n )as)ading o+ )out, LL to be used 1oid main;< F Pi3els Point2 M G=A3HI 55 F K to be used to initialise o+ members o+ the ob'e)t Sho*Point;Point2<I Pi3els Point6MPoint2I P"-3)1IC"."#7> I 55 member to +ollo*ed by the ob'e)t using . operator Sho*Point;Point6<I K 4A. Re*rite the +ollo*ing program a+ter remo1ing the synta)ti)al errors ;i+ any<. %nderline ea)h )orre)tion. Tin)lude Liostream.hW )lass sum F int 3, y, totalI publi) : sum;int a, b< F 3Ma I y M b U 6 I total M / I K 1oid display;< F )M39yI Page J / 63

total 9M ) I )out LL total I K K 1oid main;< F sum s;6/, 2/<I display;<I K Ans : Tin)lude Liostream.hW )lass sum F int 3, y, totalI publi) : sum;int a, -3) 9< 55 argument b should be de)lared separately F 3Ma I y M b U 6 I total M / I K 1oid display;< F int ) M 3 9 y I 55 lo)al 1ariable ) should be de+ined total 9M ) I )out LL total I K HB 55 )lass de+inition must terminate *ith B 1oid main;< F sum s;6/, 2/<I +I$-+4.a,;<I 55 member +un)tion must be in1o ed using . operator K

8*e+)-"3+ 9a+e$ "3 :-3$-3g O*)4*)+ *+-3g #a3$"&(' S1"#) A3+(e# 8*e+)-"3+ ( &a#;+'
N")e: random;n< generates the numbers randomly +rom / to nV2. Bor e3ample: random;6/< generates randomly +rom / to 2E. @3planations are gi1en at the end o+ ea)h solution. 42. !n the +ollo*ing program, i+ the 1alue o+ " gi1en by the user is A/, *hat ma3imum and minimum 1alues the program )ould possibly displayQ Tin)lude Liostream.hW Tin)lude Lstdlib.hW 1oid main;< F int ",GuessmeI randomiYe;<I )inWW"I GuessmeMrandom;"< 9 AI )outLLGuessmeLLendlI K Ans : &inimum : A &a3imum : A8 @3planation : Sin)e random;A/< gi1es a number randomly +rom / to 8E. !+ it returns / i.e. minimum +or random;A/<, the minimum 1alue +or Guessme *ill be / 9 A M A. !+ it returns 8E i.e. ma3imum +or random;A/<, the ma3imum 1alue +or Guessme *ill be 8E 9 A M A8. Page K / 63

46. !n the +ollo*ing program, *rite the )orre)t possible output;s< +rom the options ;i< to ;i1<. Tin)ludeLstdlib.hW Tin)ludeLiostream.hW 1oid main; < F randomiYe; <I )har CityG HG2/HMFO?@#J,JC$"J,JKO#J,JBO&J,JB"GJKI int BlyI +or;int !M/I !L7I!99< F BlyMrandom;6< 9 2I )outLLCityGBlyHLLJ:JI K K Outputs: ;i< ?@# : C$" : KO#: ;ii< C$": KO# : C$": ;iii< KO# : BO& : B"G: ;i1< KO# : C$" : KO#: Ans : So the possible output *ill be ;ii< C$" : KO# : C$": and ;i1< KO# :C$" : KO#: @3planation : Sin)e random;6< gi1es either / or 2, Bly 1alue *ill be either 2 or 6. CityG2H is OC$"J and CityG6H is OKO#J . Sin)e ! 1alue +rom / to 6 ;L7<, 7 iterations *ill ta es pla)e. So the possible output )onsists 7 strings separated by :, ea)h o+ them may be either OC$"J or OKO#J. 47. Study the +ollo*ing program and sele)t the possible output +rom it: Tin)ludeLiostream.hW Tin)ludeLstdlib.hW )onst int &a3M7I 1oid main; < F randomiYe;<I int "umberI "umberMA/ 9 random;&a3<I +or;int PM"umberI P WMA/I P R R< )outLLPLLJTJI )outLLendlI @3planation : Sin)e random;7< gi1es a number K randomly +rom / to 6. So, the 1alues o+ "umber ;i< A7TA6TA2TA/T ranges +rom A/ ;A/9/< to A6 ;A/96< and the ;ii< A/TA2TA6T "umber should be displayed in des)ending order ;iii< A/TA2T a))ording to the programme. A7 is not possible, so ;i1< A2TA/T the ans*er is ;i1<. Ans: A2TA/T 48. !n the +ollo*ing program, i+ the 1alue o+ Guess entered by the user is .A, *hat *ill be the e3pe)ted output;s< +rom the +ollo*ing options ;i<, ;ii<, ;iii< and ;i1<Q Tin)lude Liostream.hW Tin)lude Lstdlib.hW 1oid main;< F int GuessI randomiYe;<I )inWWGuessI +or ;int !M2I!LM8I!99< F "e*MGuess9random;!<I )outLL;)har<"e*I Page 1! / 63

K K ;i< ABBC ;ii< ACBA ;iii< BC?A ;i1< CAB? Ans: ;i< ABBC

@3planation : !n +irst iteration ! M 2 and random;!< gi1es /. So, "e* M .A 9 /, hen)e output is A. !n +irst iteration ! M 2, So, "e* M .A 9 /, hen)e output is A. !n se)ond iteration ! M 6 and random;!< gi1es / or 2. So, "e* M .A or .., hen)e output is A or B. !n third iteration !M7 and random;!< gi1es / to 6. So, "e* M .A or .. or .C, hen)e output is A or B or C. !n +ourth iteration !M8 and random;!< gi1es / to 7. So, "e* M .A or .. or .C or .=, hen)e output is A or B or C or ?. Option ;i< satis+ies all the abo1e only, so it is the ans*er.

4A. !n the +ollo*ing program, i+ the 1alue o+ " gi1en by the user is 6/, *hat ma3imum and minimum 1alues the program )ould possibly displayQ Tin)lude Liostream.hW Tin)lude Lstdlib.hW 1oid main;< F int ",GuessnumI randomiYe;<I )inWW"I GuessnumM random;" V 2/<92/I )outLLGuessnumLLendlI K Ans : &a3imum Value: 2E &inimum Value: 2/

8*e+)-"3+ 9a+e$ "3 :-3$-3g O*)4*)+ S1"#) A3+(e# 8*e+)-"3+ ( &a#;+'


"ote : Dhile sol1ing su)h type o+ -uestion, a student should )are+ully go through the logi) o+ the *hole program and )on)epts used in it. Various patterns o+ -uestions are gi1en belo*. Students are ad1ised to pra)ti)e 1arious -uestions to de1elop the s ill o+ +inding the output. 42. Bind the output o+ the +ollo*ing program: Tin)lude Liostream.hW stru)t Game F )har &agi)G6/HIint S)oreI KI 1oid main;< F Game &MFO(igerJ,A//KI )har UChoi)eI Choi)eM&.&agi)I Choi)eG8HMZPZI Choi)eG6HMZ#ZI &.S)ore9MA/I )outLL&.&agi)LL&.S)oreLLendlI Game "M&I ".&agi)G/HMZAZI".&agi)G7HMZJZI ".S)oreRM26/I )outLL".&agi)LL".S)oreLLendlI K A3+/ T-LeP==! A-LJP<3! 46. Bind the output o+ the +ollo*ing program: Tin)ludeLiostream.hW 1oid main;< F int "umbersGH M F6,8,=,2/KI int Uptr M "umbersI +or ;int C M /I CL7I C99< F )outLL Uptr LL O[JI ptr99I K )outLLendlI +or;C M /I CL8I C99< F ;Uptr<UM6I RRptrI K +or;C M /I CL8I C99< )outLL "umbers GCHLL OTJI )outLLendlI K A3+ / L<LJL <MJM16M !M

Page 11 / 63

47. Bind the output o+ the +ollo*ing program: Tin)lude Liostream.hW 1oid +un; int p, int U- < F p M U;-< 9M 6I K 1oid main;< F int 3, b M A, aG6H M F 2/, 6/ KI +or; 3 M 2I 3 L 7 I 399< F +un; aG3 V 2H, >b<I )outLL ONnJ LL aG3 R 2H LLJ : O LL bI K K A3+/ 1! / F !/K

48. Bind the output o+ the +ollo*ing program: Tin)lude Liostream.hW 1oid main;< F long "%& M E=A7862/I int +M/,sM/I do F int rem M "%& 0 2/I i+; rem 0 6 MM /< + 9M remI else s 9M remI "%& 5M 2/I K*hile;"%& W /<I )outLLONnJLL+LLJ V OLLsLLO M JLL+ V sI K A3+ / 1< N 1J > N < 4.. Bind the output o+ the +ollo*ing program: Tin)lude Liostream.hW Tin)ludeL)type.hW 1oid main;< F )har UnameM P(h@ b@St me" *!"PI +or ; int i M/I nameGiH\M]N/] I i99< F i+ ; islo*er; nameGiH< < nameGiH M toupper;nameGiH< I else i+; isupper;nameGiH< < i+ ; i06 MM /< nameGiH V V I else nameGiH M tolo*er;nameGiV2H<I K )outLLnameI K A3+ / SHD B9RT MEe 0H1

4A. Bind the output o+ the +ollo*ing program: Tin)ludeLiostream.hW int aM2/I 1oid main;< F 1oid demo;int >, int , int U <I int aM6/,bMAI demo;::a,a,>b<I )outLLJNnJLL::aLLJUJLLaLLJUJLLbI K 1oid demo;int >3, int y, int UY< F a M a 9 3I y M y U aI UY M a9yI )outLLJNnJLL3LLJUJLLyLLJUJLLUY I K A3+/ ! C <!! C < ! !C !C< !

8*e+)-"3+ 9a+e$ "3 :-3$-3g O*)4*)+ S1"#) A3+(e# 8*e+)-"3+ ( 3 &a#;+'


42. Bind the output o+ the +ollo*ing program: Tin)lude Liostream.hW Tin)ludeLstring.hW stru)t K@X F )har *ordG2/HI int )ountI KI 1oid )hange ey*ord;K@X some ey<I Page 1 / 63

1oid main;< F K@X aK@XI str)py;aK@X.*ord, OTde+ineJ<I aK@X.)ountM2/I )outLLaK@X.*ordLL ONtJLLaK@X.)ountLL ONnJI )hange ey*ord;aK@X<I )outLLaK@X.*ordLL ONtJLLaK@X.)ountLL ONnJI K 1oid )hange ey*ord;K@X some ey< F str)py;some ey.*ord, O)onstJ<I some ey.)ount 9M 2I )outLLsome ey.*ordLL ONtJ LLsome ey.)ountLL ONnJI K A3+ / M$e2-3e 1! M5"3+) 11 M$e2-3e 1! 46. Bind the output o+ the +ollo*ing program: Tin)lude Liostream.hW int modi+y;int temp M 6< F i+;temp 0 7 MM /< temp M temp 9 2I else temp M temp 9 7I return tempI K 1oid doupdation;int m, int >n< F stati) int iI i99I m M n 9 iI i+;n W 2/< n M modi+y;<I else n M modi+y;n<I )outLLmLLP I PLLnLLendlI K 1oid main;< F int 3 M =, y M 6/I doupdation;3,y<I )outLL3LLP I PLLyLLendlI doupdation;y,3<I )outLL3LLP I PLLyLLendlI doupdation;y,3<I )outLL3LLP I PLLyLLendlI K

47. Bind the output o+ the +ollo*ing program: Tin)lude Liostream.hW 1oid )hang ; int >3, int y< F int tempI tempM3I 3MyI yMtempI )outLLJNnJLL3LLJ : OLLyI K 1oid main;< F int aM2/, bI bM a99 9 99a 9 99a 9 a99 9 6I )outLLJNnJLL a LLJ : OLLbI )hang; a , b <I )outLLJNnJLL a99 LLJ : JLL 99bI K A3+ / 1< / =! =! / 1< =! / =1

Page 13 / 63

A3+/

1B= JB= 1! B 11 11 B = 1< B = =B= 48. Gi1e the output o+ the +ollo*ing program: Tin)ludeLiostream.hW 1oid main;< F int a, Ub, UU), UUUdI aM26, bM>a, )M>b, dM>)I UUUdUMAI )outLLJNnJLLaLLJ,JLL a 9 UbI ;UU)< 9M 2/I )outLLJNnJLLUU) 9 UUUdI ;UUUd<9M 2/I )outLLJNnJLL a 9 UbI K A3+/ 6! A 1 ! 1<! 16! 4A. Gi1e the output o+ the +ollo*ing program: Tin)lude Liostream.hW Tin)lude Lstring.hW Tin)lude L)type.hW 1oid +unnystr;)har Us, int n M 6< F int i M nI *hile;i L strlen;s<< F sGiH M ]R]I i M i 9 nI K i M /I *hile;sGiH \M ]N/]< F i+;sGiH W ]A] >> sGiH L ]P]< sGiH M tolo*er;sGiH<I else i+;sGiH W ]a] >> sGiH L ]p]< F i+;i 0 7 MM /< sGiH M tolo*er;sGiR2H<I else sGiH M tolo*er;sGiH<I K i99I K K 1oid main;< F )har strGH M P&iCroSoB(PI +unnystr;str,7<I )outLLstrI K A3+ / &-5N"SN2T Page 1< / 63

I3)#"$*5)-"3 )" OOP *+-3g C77


O9Oe5) O#-e3)e$ P#"g#a&&-3g C"35e4)+ S1"#) A3+(e# 8*e+)-"3+
42. ?e+ine ob'e)t. Ans. Ob'e)t is an identi+iable entity *ith some )hara)teristi)s and beha1iour. 46. ?e+ine )lass. Ans. A )lass is group o+ ob'e)ts that share )ommon properties and relationships. 47. ?e+ine data abstra)tion. Ans. Abstra)tion re+ers to the a)t o+ representing essential +eatures *ithout in)luding the ba) ground details or e3planations. 48. Dhat is inheritan)eQ Ans. !nheritan)e is the )apabilities o+ one )lass o+ things to inherit )apabilities or properties +rom another )lass. 4A. ?e+ine modularity. Ans. &odularity is the property o+ a system that has been de)omposed into a set o+ )ohesi1e and loosely )oupled modules. 4.. ?e+ine en)apsulation. Ans. (he *rapping up o+ data and operations 5 +un)tions ; that operate on the data < into a single unit ;)alled )lass < is no*n as en)apsulation . 4C. Dhat is polymorphismQ Ans. Polymorphism is the ability +or a message or data to be pro)essed in more than one +orm. 4=. $o* polymorphism is implemented in C99Q Ans. Polymorphism is implemented in C99 through o1erloaded +un)tions, o1erloaded operators and 1irtual +un)tions. 4E. $o* inheritan)e is implemented in C99Q Ans. !nheritan)e is implemented in C99 by spe)i+ying the base )lass +rom *hi)h the deri1ed )lass o+ the base )lass is de+ined. 42/. Dhat is data hidingQ $o* it is implemented in C99Q Ans. ?ata hiding is a property *hereby the internal data stru)ture o+ an ob'e)t is hidden +rom the rest o+ the program. ?ata hiding is implemented in C99 by pri1ate and prote)ted members o+ )lass. 422. $o* data abstra)tion )an be implemented in C99Q Ans. ?ata abstra)tion )an be implemented in C99 by using publi) members o+ )lass. 426. Dhat is programming paradigmQ Ans. A programming paradigm de+ines the methodology o+ designing and implementing programs using the ey +eatures and building blo) s o+ a programming language. 427. Dhat is pro)edural programming paradigmQ Ans. !n pro)edural programming paradigm, data is shared among all the +un)tions. !ts emphasis is on doing things rather than using the data. Page 1= / 63

428. Dhat are the ad1antages o+ OOPQ Ans : (he ad1antages o+ OOP are Reusability o+ )ode, @ase o+ )omprehension, ease o+ +abri)ation and maintenan)e, ease o+ redesign and e3tension. 42A. Dhat do you understand by +un)tional o1erloadingQ Gi1e an e3ample illustrating its use in a C99 program. Ans: A +un)tion name ha1ing se1eral de+initions that are di++erentiable by the number or types o+ their arguments is no*n as +un)tional o1erloading. Bor e3ample: +loat 1olume;+loat a < F return a U a U aI K +loat 1olume;+loat a, +loat b < F return a U a U bI K +loat 1olume;+loat a, +loat b, +loat )< F return a U b U )I K

CLASSES AND OBJECTS


SOME MPORTANT 8UESTIONS TO RE:RESH THE CONCEPT
81I Drite +our attributes asso)iated *ith de)laration o+ )lasses. A3+. (he attributes asso)iated *ith de)laration o+ )lasses are ?ata &embers, &ember Bun)tions, Program a))ess le1els and Class (agname. 8 I ?e+ine data members and member +un)tions. A3+. ?ata members are e3a)tly li e the 1ariables in a stru)ture. (hey are normally made &ember +un)tion is +un)tion de+ined *ithin a )lass that a)ts on the data members in the )lass. (hey are normally made publi). 83I Drite the s)ope rules o+ members o+ a )lass. A3+I S)ope rules o+ members o+ a )lass are:P Pri1ate (hese members )an be a))essed only by the member +un)tions > +riend +un)tions o+ the )lass. !t )an not be inherited. Prote)ted (hese members )an be a))essed only by the member +un)tions > +riend +un)tions o+ the )lass. !t )an be inherited. Publi) (hese members )an be dire)tly a))essed by any +un)tion. 8<I $o* many types o+ +un)tions are used in a )lassQ A3+I 2. A))essor +un)tion 6. &utator +un)tions 7. &anager +un)tions 4=I Dhen *ill you ma e a +un)tion inlineQ A3+I A +un)tion is made inline *hen it is 1ery small and does not return any 1alue. Also it does not )ontain any loop and stati) 1ariables. 86I Dhat is s)ope resolution operatorQ A3+I (his operator;::< is used in situations *here a global 1ariable e3ists *ith the same name as a lo)al 1ariable. (his is also used *hen the member +un)tions are de)lared outside the )lass de+initionI the +un)tion name is pre)eded by the )lass name and the binary s)ope resolution operator; :: <. 8FI ?e+ine stati) data members. A3+I Stati) data members are initialiYed to Yero *hen the +irst ob'e)t o+ its )lass is )reated. "o other initialiYation is permitted. Only one )opy o+ that member is )reated +or the entire )lass and is shared by all the ob'e)ts +or that )lass. 8JI $o* is memory allo)ated to a )lass and its ob'e)tsQ A3+I Dhen a )lass is de+ined, memory is allo)ated +or its member +un)tions and they are stored in the memory. Dhen ob'e)t is )reated, separate memory spa)e is allo)ated +or its data members. All ob'e)ts *or *ith the same )opy o+ member +un)tion shared by all.

Page 16 / 63

BOARD PATTERN 8UESTIONS/ L"3g A3+(e# 8*e+)-"3+ (< &a#;+' 81I ?e+ine a )lass e&4.",ee *ith the +ollo*ing spe)i+i)ationsI
P#-6a)e members o+ )lass e&4.",ee / e&43" integer e3a&e 6/ )hara)ters 9a+-5A1#aA$a +loat 3e)4a, +loat 5a.5*.a)e( ' A +un)tion to )al)ulate basi) 9 hra 9 da *ith +loat return type P*9.-5 member +un)tions o+ )lass e&4.",ee / 1a6e$a)a( ' +un)tion to a))ept 1alues +or empno, ename, basi) , hra ,da and in1o e 5a.5*.a)e( ' to )al)ulate netpay $-+4$a)a( ' +un)tion to display all the data members on the s)reen . A3+I )lass employee F int empnoI )har enameG6/HI +loat basi),da,hraI +loat netpayI +loat )al)ulate; < F return ;basi) 9 da 9 hra<I K publi) : 1oid ha1edata; < F )out LL J@nter employee noJI )in WW empnoI )out LL JNn @nter name OI )in WW enameI )out LL JNn @nter basi) salaryJI )in WW basi)I )out LL JNn @nter ?A OI )in WW daI )out LL ONn @nter $RA OI )in WW hraI netpay M )al)ulate; <I K 1oid dispdata; < F )out LL ONn @mployee no is OLL empno LL endl I )out LL ONn "ame is O LL ename LL endl I )out LL ONn Basi) Salary isJ LL basi) LL endl I )out LL ONn ?A is O LL endl I )out LL ONn $RA is O LL hra LL endl I )out LL ONn "etpay is O LL netpay LL endl I K KI 8 I ?e+ine a )lass S)*$e3) +or the +ollo*ing spe)i+i)ations : P#-6a)e members o+ the S)*$e3) are : #".. Q 3" integer 3a&e array o+ )hara)ters o+ siYe 6/ Page 1F / 63

5.a++ Q +) array o+ )hara)ters o+ siYe = &a#;+ array o+ integers o+ siYe A 4e#5e3)age +loat 5a.5*.a)e that )al)ulates the per)entage mar s P*9.-5 members o+ the S)*$e3) are : #ea$&a#;+ reads mar and in1o e the )al)ulate +un)tion $-+4.a,&a#;+ prints the data. A3+I )lass Student F int roll S no I )har nameG6/H I )har )lass S stG=H I int mar sGAH I +loat per)entage I 1oid )al)ulate; < I publi) : 1oid readmar s; < I 1oid displaymar s; < I KI 1oid Student : : )al)ulate; < F +loat total M / I +or ; int ! M/ I ! L AI ! 99 < total 9 M mar sG!H I per)entage M total 5 A I K 1oid Student : : readmar s; < F )out LL O Nn @nter A mar s : O I +or ; int ! M/ I ! L A I ! 99 < )in WW mar sG!H I )al)ulate; < I K 1oid Student : : displaymar s; < F )out LL ONn (he A mar s are : O I +or ; int ! M / I ! L A I ! 99 < )out LL mar sG!H LL endl I )out LL O Nn Per)entage M O LL per)entage LL endl I K 83I ?e+ine a )lass DONOR *ith the +ollo*ing spe)i+i)ations : P#-6a)e / D"3"# 3*&9e# integer Na&e 6/ )hara)ters B.""$ g#"*4 6 )hara)ters P*9.-5 / I34*)( ' A +un)tion to a))ept all the in+ormation O*)4*)( ' A +un)tion to display all the in+ormation C1e5;g#"*4( ' A +un)tion *ith )har U return to return Blood Group ?e+ine both the number +un)tions *ith their gi1en des)ription. A3+I )lass ?O"OR F int dSno I )har nameG6/H I )har bSgrpG6H I Page 1J / 63

publi) : 1oid input; < F )out LL ONn @nter the details as donor no, name and blood group : O I )in WW dSno I gets ; name <I gets ; bSgrp < I K 1oid output; < F )out LL ONn (he details are O I )out LL ONn "ame : O LL name LL ONn ?onor "o : LL dSno I )out LL ONn Blood Group : O LL bSgrp I K )har U )he) group ; < F return ; bSgrp < I K KI 48. ?e+ine a )lass (@S( in C99 *ith +ollo*ing des)ription: Pri1ate &embers (estCode o+ type integer ?es)ription o+ type string "oCandidate o+ type integer CenterRe-d ;number o+ )enters re-uired< o+ type integer A member +un)tion CA#C"(R;< to )al)ulate and return the number o+ )enters as ;"oCandidates52//92< Publi) &embers ^ A +un)tion SC$@?%#@;< to allo* user to enter 1alues +or (estCode, ?es)ription, "oCandidate > )all +un)tion CA#C"(R;< to )al)ulate the number o+ Centres ^ A +un)tion ?!SP(@S(;< to allo* user to 1ie* the )ontent o+ all the data members Ans: )lass (@S( F int (estCodeI )har ?es)riptionG6/HI int "oCandidate,CenterRe-dI 1oid CA#C"(R;<I publi): 1oid SC$@?%#@;<I 1oid ?!SP(@S(;<I KI 1oid (@S(::CA#C"(R;< F CenterRe-dM"oCandidate52// 9 2I K 1oid (@S(::SC$@?%#@;< F )outLLJ(est Code :JI)inWW(estCodeI )outLLJ?es)ription :JIgets;?es)ription<I )outLLJ"umber :JI)inWW"oCandidateI CA#C"(R;<I K 1oid (@S(::?!SP(@S(;< F )outLLJ(est Code :JLL(estCodeLLendlI )outLLJ?es)ription :JLL?es)riptionLLendlI )outLLJ"umber :JLL"oCandidateLLendlII )outLLJCentres :JLLCenterRe-dLLendlII K Page 1K / 63

4A.

?e+ine a )lass in C99 *ith +ollo*ing des)ription: Pri1ate &embers ^ A data member Blight number o+ type integer ^ A data member ?estination o+ type string ^ A data member ?istan)e o+ type +loat ^ A data member Buel o+ type +loat ^ A member +un)tion CA#B%@#;< to )al)ulate the 1alue o+ Buel as per the +ollo*ing )riteria ?istan)e Buel LM2/// A// more than 2/// and LM6/// 22// more than 6/// 66// Publi) &embers ^ A +un)tion B@@?!"BO;< to allo* user to enter 1alues +or Blight "umber, ?estination, ?istan)e > )all +un)tion CA#B%@#;< to )al)ulate the -uantity o+ Buel ^ A +un)tion S$OD!"BO;< to allo* user to 1ie* the )ontent o+ all the data members )lass B#!G$( F int BnoI )har ?estinationG6/HI +loat ?istan)e, BuelI 1oid CA#B%@#;<I publi): 1oid B@@?!"BO;<I 1oid S$OD!"BO;<I KI 1oid B#!G$(::CA#B%@#;< F i+ ;?istan)eL2///< BuelMA//I else i+ ;?istan)eL6///< BuelM22//I else BuelM66//I K 1oid B#!G$(::B@@?!"BO;< F )outLLJBlight "o :JI)inWWBnoI )outLLJ?estination :JIgets;?estination<I )outLLJ?istan)e :JI)inWW?istan)eI CA#B%@#;<I K 1oid B#!G$(::S$OD!"BO;< F )outLLJBlight "o :JLLBnoLLendlI )outLLJ?estination :JLL?estinationLLendlI )outLLJ?istan)e :JLL?istan)eLLendlII )outLLJBuel :JLLBuelLLendlII K

Ans:

Page ! / 63

CONSTRUCTOR AND DESTRUCTOR


SOME MPORTANT 8UESTIONS TO RE:RESH THE CONCEPT
42. Dhat is )onstru)torQ Ans. A member +un)tion *ith the same name as its )lass is )alled )onstru)tor and it is used to initialiYe the ob'e)ts o+ that )lass type *ith a legal initial 1alue. 46. Dhat is destru)torQ Ans. A destru)tor is a member +un)tion ha1ing same name as its )lass but pre)eded by _ sign and it deinitialises an ob'e)t be+ore it goes out o+ s)ope. 47. Dhat are di++erent types o+ )onstru)torsQ Ans. (he di++erent types o+ )onstru)tors are ?e+ault )onstru)tor, ParameteriYed )onstru)tor and Copy )onstru)tor. 48. Dhat is de+ault )onstru)torQ Ans. A )onstru)tor that a))epts no parameter is )alled the de+ault )onstru)tor. 4A. Dhat is parameteriYed )onstru)torQ Ans. A )onstru)tor that a))epts parameters +or its in1o)ation is no*n as parameteriYed )onstru)tor. 4.. Dhat is )opy )onstru)torQ Ans. A )opy )onstru)tor is a )onstru)tor that de+ines and initialiYes an ob'e)t *ith another ob'e)t. !t ta es the +orm )lassname;)lassname<. Bor a )opy )onstru)tor there must be a de+ault )onstru)tor or a parameteriYed )onstru)tor.

BOARD PATTERN 8UESTIONS R S1"#) A3+(e# 8*e+)-"3+ ( &a#;+'


"ote : (*o options *ith the +ollo*ing pattern are generally as ed in the Board @3am. Various optional -uestions are gi1en belo*. 4C. Ans*er the +ollo*ing -uestions a+ter going through the +ollo*ing )lass: )lass Seminar F int (imeI publi): Seminar;<I 55Bun)tion 2 1oid #e)ture;< 55Bun)tion 6 F)outLLJ#e)tures in the seminar onJLLend2IK Seminar;int<I 55Bun)tion 7 Seminar;Seminar >ab)<I 55Bun)tion 8 _Seminar;< 55Bun)tion A F )outLLJVote o+ than sJLLend2IK KI ;i< !n Ob'e)t Oriented Programming, *hat is Bun)tion A re+erred as and *hen does it get in1o ed5)alledQ Ans : Bun)tion A is re+erred as destru)tor and it is in1o ed as soon as the s)ope o+ the ob'e)t gets o1er. ;ii< !n Ob'e)t Oriented Programming, *hi)h )on)ept is illustrated by Bun)tion 2, Bun)tion 7 and Bun)tion 8 all togetherQ Ans : Constru)tor O1erloading ;Polymorphism< Page 1 / 63

;iii< Dhi)h )ategory o+ )onstru)tor R Bun)tion 2 belongs toQ Drite an e3ample illustrating the )alls +or Bun)tion 2. Ans : ?e+ault Constru)tor. @3ample to in1o e +un)tion 2 Seminar SI ;i1< Dhi)h )ategory o+ )onstru)tor R Bun)tion 7 belongs toQ Drite an e3ample illustrating the )alls +or Bun)tion 7. Ans : Parameterised Constru)tor. @3ample to in1o e +un)tion 7 Seminar A;=<I ;1< Dhi)h )ategory o+ )onstru)tor R Bun)tion 8 belongs toQ Drite an e3ample illustrating the )alls +or Bun)tion 8. Ans : Copy Constru)tor. @3ample to in1o e +un)tion 8 Seminar S6;S<I Or Seminar S6 M SI ;1i< Drite an e3ample illustrating the )alls +or Bun)tion 7 e3pli)itly. Ans : Seminar A M Seminar;=<I ;1ii< Drite an e3ample illustrating the )alls +or Bun)tion 8 e3pli)itly. Ans : Seminar S6 M Seminar;S<I ;1iii< Drite the )omplete de+inition +or Bun)tion 2 to initialiYe (ime as 7/. Ans : Seminar :: Seminar;< F (ime M 7/I K ;i3< Drite the )omplete de+inition +or Bun)tion 7 to initialiYe (ime *ith &ytime as parameter to the Bun)tion 7. Ans : Seminar :: Seminar;int &ytime< F (ime M &ytimeI K ;3< Drite the )omplete de+inition +or Bun)tion 8. Ans : Seminar :: Seminar;Seminar >ab)< F (ime M ab).(imeI K 4=. Ans*er the +ollo*ing -uestions a+ter going through the +ollo*ing )lass: )lass Comple3 F int 3I int yI publi): Comple3;<I 55Bun)tion 2 1oid disp;< 55Bun)tion 6 F)outLLJ(he Comple3 number is : OLL3LLJ 9 OLLyLLJiJLLend2IK Comple3;int, int<I 55Bun)tion 7 Comple3;Comple3 >ab)<I 55Bun)tion 8 KI ;i< Dhi)h )ategory o+ )onstru)tor R Bun)tion 2 belongs toQ Drite an e3ample illustrating the )alls +or Bun)tion 2. Ans : ?e+ault Constru)tor. @3ample to in1o e +un)tion 2 Comple3 CI ;ii< Dhi)h )ategory o+ )onstru)tor R Bun)tion 7 belongs toQ Drite an e3ample illustrating the )alls +or Bun)tion 7. Ans: Parameterised Constru)tor. @3ample to in1o e +un)tion 7Comple3 C;.,=<I ;iii< Dhi)h )ategory o+ )onstru)tor R Bun)tion 8 belongs toQ Drite an e3ample illustrating the )alls +or Bun)tion 8. Ans : Copy Constru)tor. @3ample to in1o e +un)tion 8 Comple3 C6;C<I Or Comple3 C6 M CI ;i1< Drite an e3ample illustrating the )alls +or Bun)tion 7 e3pli)itly. Ans : Comple3 C M Comple3;.,=<I ;1< Drite an e3ample illustrating the )alls +or Bun)tion 8 e3pli)itly. Ans : Comple3 C6 M Comple3;C<I ;1i< Drite the )omplete de+inition +or Bun)tion 2 to initialiYe 3 as 2/ and y as 6/. Page / 63

Ans : Comple3 :: Comple3 ;< F 3 M 2/ I y M 6/I K ;1ii< Drite the )omplete de+inition +or Bun)tion 7 to initialiYe the data members *ith p and - as parameters to the Bun)tion 7. Ans : Comple3 :: Comple3;int p, int -< F 3 M pI y M -I K ;1iii< Drite the )omplete de+inition +or Bun)tion 8. Ans : Comple3 :: Comple3 ;Comple3 >ab)< F 3 M ab).3I y M ab).yI K

I31e#-)a35e
SOME MPORTANT 8UESTIONS TO RE:RESH THE CONCEPT
81I Drite the reasons behind the introdu)tion o+ inheritan)e in OOP. A3+. (he ma'or reasons behind the introdu)tion o+ inheritan)e in OOP are:;i< !t ensures the )loseness *ith the real *orld models, ;ii< idea o+ reusability, ;iii< transiti1e nature o+ inheritan)e. 8 . Dhat are the di++erent +orms o+ inheritan)eQ A3+. (he di++erent +orms o+ inheritan)e are ;i< Single !nheritan)e, ;ii< &ultiple !nheritan)e, ;iii< $ierar)hi)al !nheritan)e, ;i1< &ultile1el !nheritan)e, ;1< $ybrid !nheritan)e. 83I $o* does the a))ess o+ inherited members depend upon their a))ess spe)i+iers and the 1isibility modes o+ the base )lassQ A3+I A))ess spe)i+ier publi) inheritan)e prote)ted pri1ate inheritan)e Visibility mode inheritan)e 4*9.-5 member in base )lass 4*9.-5 in deri1ed )lass 4#")e5)e$ in 4#-6a)e in deri1ed deri1ed )lass )lass 4#")e5)e$ member in base 4#")e5)e$ in deri1ed 4#")e5)e$ in 4#-6a)e in deri1ed )lass )lass deri1ed )lass )lass 4#-6a)e member in base )lass hidden in deri1ed )lass hidden in deri1ed hidden in deri1ed )lass )lass 8<I Drite the di++erent *ays o+ a))essibility o+ base )lass members. A3+I A))ess Spe)i+ier A))essible +rom A))essible +rom deri1ed A))essible +rom ob'e)ts o*n )lass )lass ;!nheritable< outside )lass publi) Xes Xes Xes prote)ted Xes Xes "o pri1ate Xes "o "o 8=I $o* is the siYe o+ a deri1ed )lass ob'e)t )al)ulatedQ A3+I (he siYe o+ a deri1ed )lass ob'e)t is e-ual to the sum o+ siYes o+ data members in base )lass and the deri1ed )lass. 86I !n *hat order are )lass )onstru)tors and )lass destru)tors )alled *hen a deri1ed )lass ob'e)t is )reated or destroyedQ A3+I Dhen the ob'e)t o+ a deri1ed )lass is )reated, +irstly the )onstru)tor o+ the base )lass is in1o ed and then, the )onstru)tor o+ the deri1ed )lass is in1o ed. On the other hand, *hen the ob'e)t o+ a deri1ed )lass is destroyed, +irstly the destru)tor o+ the deri1ed )lass is in1o ed and then, the destru)tor o+ the base )lass is in1o ed. "ote : Obser1e the +ollo*ing -uestions and their solutions. (he abo1e )on)epts are implemented. Pra)ti)e o+ su)h -uestions *ill de+initely )lear your doubts and impro1e your )on+iden)e le1el. ?is)ussion *ith your +riends and distinguish the 1arieties o+ these -uestions. Page 3 / 63

BOARD PATTERN 8UESTIONS


L"3g A3+(e# 8*e+)-"3+ (< Ma#;+'
42. Ans*er the -uestions ;i< to ;i1< based on the +ollo*ing:
)lass 1ehi)le F int *heelsI prote)ted: int passengerI publi): 1oid inputdata; <I 1oid outputdata; <I KI )lass hea1y1ehi)le : prote)ted 1ehi)le F int dieselSpetrolI prote)ted: int loadI publi): 1oid readdata;int, int<I 1oid *ritedata; <I KI )lass bus : pri1ate hea1y1ehi)le F )har ma eG6/HI publi): 1oid +et)hdata; <I 1oid displaydata; <I KI

i< Drite the member;s< that )an be a))essed +rom the ob'e)t o+ bus. ii< Drite the data member;s< that )an be a))essed +rom the +un)tion displaydata; <. iii< $o* many bytes are re-uired by an ob'e)t o+ bus and hea1y1ehi)le )lasses respe)ti1elyQ i1< !s the member +un)tion outputdata; < a))essible to the ob'e)ts o+ the )lass hea1y1ehi)leQ A3+ / (-' 2e)51$a)a('A $-+4.a,$a)a(' (--' &a;eA ."a$A 4a++a3ge# (---' 2"# )1e "9Oe5) "2 9*+ N J 9,)e+A 2"# )1e "9Oe5) "2 1ea6,6e1-5.e N J 9,)e+ 46. Ans*er the -uestions ;i< to ;i1< based on the +ollo*ing:
)lass li1ingbeing F )har spe)i+i)ationG6/HI int a1erageageI publi): 1oid read;<I 1oid sho*;<I KI )lass ape : pri1ate li1ingbeing F int noSo+SorgansI int noSo+SbonesI prote)ted: int i-Sle1elI publi): 1oid readape;<I 1oid sho*ape;<I KI )lass human : publi) ape F )har ra)eG6/HI )har habitationG7/HI publi): 1oid readhuman;<I 1oid sho*human;<I KI

(-6' N"

;i< ;ii< ;iii< ;i1<

Drite the members *hi)h )an be a))essed +rom the member +un)tions o+ )lass human. Drite the members, *hi)h )an be a))essed by an ob'e)t o+ )lass human. Dhat is the siYe o+ an ob'e)t ;in bytes< o+ )lass humanQ Drite the )lass;es< *hi)h ob'e)ts )an a))ess read;< de)lared in li1ingbeing )lass.

A3+ / (-' #a5eA 1a9-)a)-"3A -@Q.e6e.A #ea$1*&a3('A +1"(1*&a3('A #ea$a4e('A +1"(a4e(' (--' #ea$1*&a3('A +1"(1*&a3('A #ea$a4e('A +1"(a4e(' (---' FJ 9,)e+ (-6' .-6-3g9e-3g 47. Ans*er the -uestions ;i< to ;i1< based on the +ollo*ing:
)lass parent F )har nameG6/HI prote)ted: int sonI publi): 1oid inputdata;<I 1oid outputdata;<I KI )lass +ather : prote)ted parent F int daughterI prote)ted: int babyI publi): 1oid readdata;<I 1oid *ritedata;<I KI )lass mother : publi) +ather F int )hildI publi): 1oid +et)hdata;<I 1oid dispdata;<I KI

;i< !n )ase o+ the )lass +ather, *hat is the base )lass o+ +ather and *hat is the deri1ed )lass o+ +atherQ

;ii< Drite the data member;s< that )an be a))essed +rom +un)tion dispdata;<. ;iii< Drite the member +un)tion;s<, *hi)h )an be a))essed by an ob'e)t o+ mother )lass. ;i1< !s the member +un)tion outputdata;< a))essible to the ob'e)ts o+ +ather )lassQ A3+ / (-' 9a+e 5.a++ "2 2a)1e# N 4a#e3)A $e#-6e$ 5.a++ "2 2a)1e# N &")1e# (--' 51-.$A 9a9,A +"3 (---' 2e)51$a)a('A $-+4$a)a('A #ea$$a)a('A (#-)e$a)a(' Page < / 63

(-6' N"

48. Ans*er the -uestions ;i< to ;i1< based on the +ollo*ing:


)lass person F )har nameG6/H, addressG6/HI prote)ted: int 3I publi): 1oid enterSperson;<I 1oid dispSperson;<I KI )lass )lient : pri1ate person F int resour)eI publi): int getSresour)e;<I 1oid +reeSresour)e;<I KI

)lass do)tor : publi) person F )har spe)ialityG6/HI publi): 1oid input;<I 1oid disp;<I KI

;i< Dhat type o+ inheritan)e is depi)ted by the abo1e e3ampleQ ;ii< Drite the member +un)tions, *hi)h )an be )alled by the ob'e)t o+ )lass )lient. ;iii< Dhat is the siYe in bytes o+ the ob'e)t o+ )lass do)tor and )lient respe)ti1elyQ ;i1<Drite the data members, *hi)h )an be used by the member +un)tions o+ the )lass do)tor. A3+ / (-' H-e#a#51-5a. I31e#-)a35e (--' ge)Q#e+"*#5e('A 2#eeQ#e+"*#5e(' (---' +-Re "2 "9Oe5) "2 5.a++ $"5)"# > 6 a3$ 5.-e3) > << (-6' +4e5-a.-),A % 4A. Ans*er the -uestions ;i< to ;i1< based on the +ollo*ing:
)lass author F )har nameG26HI double royaltyI prote)ted: 1oid register;<I publi): author;<FKI 1oid enter;<I 1oid display;<I KI )lass person F )har addressG6/HI prote)ted: +loat salaryI publi): person;<FKI 1oid ha1elt;<I 1oid gi1elt;<I KI )lass employee : pri1ate author, publi) person F int e)odeI )har deptG7/HI publi): employee;<FKI 1oid start;<I 1oid sho*;<I KI

;i< Drite the names o+ data members, *hi)h are a))essible +rom ob'e)t o+ )lass employee.
;ii< Drite the names o+ all the member +un)tions *hi)h are a))essible +rom ob'e)t o+ )lass person. ;iii< Drite the data members *hi)h are a))essible +rom member +un)tions o+ )lass employee.

;i1< $o* many bytes are re-uired by an ob'e)t belonging to )lass employeeQ A3+ / (-' N-. (--' 1a6e-)('A g-6e-)(' (---' e5"$eA $e4)A +a.a#, (-6' F6 9,)e+ 4.. Ans*er the -uestions ;i< to ;i1< based on the +ollo*ing:
)lass P%B#!S$@R F )har PubG26HI double (urno1erI prote)ted: 1oid Register;<I publi): P%B#!S$@R;<I 1oid @nter;<I 1oid ?isplay;<I KI )lass BRA"C$ F )har C!(XG6/HI prote)ted: +loat @mployeesI publi): BRA"C$;<I 1oid $a1eit;<I 1oid Gi1eit;<I KI )lass A%($OR: pri1ate BRA"C$, publi) P%B#!S$@R F int A)odeI )har AnameG6/HI +loat AmountI publi): A%($OR;<I 1oid Start;<I 1oid Sho*;<I KI

;i< Drite the names o+ data members, *hi)h are a))essible +rom ob'e)ts belonging to )lass A%($OR. ;ii< Drite the names o+ all the members *hi)h are a))essible +rom member +un)tions o+ )lass A%($OR. ;iii< $o* many bytes are re-uired by an ob'e)t belonging to )lass A%($ORQ ;i1< Drite the se-uen)e o+ the )onstru)torsZ in1o)ation *hen the ob'e)t o+ author is )reated. A3+/ (-' N-. (--' A5"$eA A3a&eA A&"*3)A E&4.",ee+A S)a#)('A S1"(('A Ha6e-)('A G-6e-)('A Reg-+)e#('A E3)e#('A D-+4.a,(' (---' F! 9,)e+ (-6' BRANCH('A PUBLISHER('A AUTHOR(' 4C. Ans*er the -uestions ;i< to ;i1< based on the +ollo*ing:
)lass C%S(O&@R F int CustSnoI )har CustS"ameG6/HI prote)ted: 1oid Register;<I publi): C%S(O&@R;<I 1oid Status;<I KI )lass SA#@S&A" F int SalesmanSnoI )har SalesmanS"ameG6/HI prote)ted: +loat SalaryI publi): SA#@S&A";<I 1oid @nter;<I 1oid Sho*;<I KI Page = / 63 )lass S$OP : pri1ate C%S(O&@R , publi) SA#@S&A" F )har Vou)herS"oG2/HI )har SalesS?ateG=HI publi): S$OP;<I 1oid SalesS@ntry;<I 1oid SalesS?etail;<I KI

;i< Drite the names o+ data members *hi)h are a))essible +rom ob'e)ts belonging to )lass C%S(O&@R. ;ii< Drite the member +un)tions that are a))essible +rom ob'e)ts belonging to )lass SA#@S&A". ;iii< Drite the names o+ all the members *hi)h are a))essible +rom member +un)tions o+ )lass S$OP.

;i1< $o* many bytes *ill be re-uired by an ob'e)t belonging to )lass S$OPQ A3+ / (-' N"3e "2 $a)a &e&9e#+ a#e a55e++-9.e 2#"& "9Oe5)+ 9e."3g-3g )" 5.a++ CUSTOMERI (--' E3)e#('A S1"((' (---' Da)a &e&9e#+/ V"*51e#QN"A Sa.e+QDa)eA Sa.a#, Me&9e# 2*35)-"3/ Sa.e+QE3)#,('A Sa.e+QDe)a-.+('A E3)e#('A S1"(('A Reg-+)e#('A S)a)*+(' (-6' 66 9,)e+

Da)a S)#*5)*#e S P"-3)e#+


A$$#e++ Ca.5*.a)-"3
S1"#) A3+(e# 8*e+)-"3+ ( 3 &a#;+'
Bormulae o+ Ro* &a'or > Column &a'or are used in the gi1en -uestions. Kindly go through it. 42. An array 3G7/HG2/H is stored in the memory *ith ea)h element re-uiring 8 bytes o+ storage. !+ the base address o+ 3 is 8A//, +ind out memory lo)ations o+ 3G26HG=H and 3G6HG8H, i+ the )ontent is stored along the ro*. Ans : Gi1en, D M 8, " M 7/, & M 2/, Base;3< M 8A// Ro* &a'or Bormula: #o);3G26HG=H< M Base;3<9DU;&U!9J< #o);3G6HG8H< M Base;3<9DU;&U!9J< M 8A// 9 8 U ;2/ U 26 9 =< M 8A//9 8U; 2/U6 9 8< M 8A// 9 8 U 26= M 8A// 9 8 U 68 M 8A// 9 A26 M 8A// 9 E. M A/26 M 8AE. 46. An array PG6/HG7/H is stored in the memory along the )olumn *ith ea)h o+ the element o))upying 8 bytes, +ind out the Base Address o+ the array, i+ an element PG6HG6/H is stored at the memory lo)ation A///. Ans : Gi1en, DM8, "M6/, &M7/, #o);PG6HG6/H<MA/// Column &a'or Bormula: #o);PG!HGJH< MBase;P<9DU;"UJ9!< #o);PG6HG6/H< MBase;P<98U;6/U6/96< Base;P< MA/// V 8U;8//96< MA/// V 2./= M77E6 47. An array ARRGAHG6AH is stored in the memory *ith ea)h element o))upying 8 bytes o+ spa)e. Assuming the base address o+ ARR to be 2///, )ompute the address o+ ARRGAHGCH, *hen the array is stored as : ;i< Ro* *ise ;ii< Column *ise. Ans: ;i< Ro* *ise : ;ii< Column *ise : Gi1en, D M 8, " M A, & M 6A, Gi1en, D M 8, " M A, & M 6A, Base;ARR< M 2/// Base;ARR< M 2/// Ro* &a'or Bormula: Column &a'or Bormula: #o);ARRGAHGCH<M Base;ARR<9DU;&U!9J< #o);ARRGAHGCH<M Base;ARR<9DU;"UJ9!< M 2/// 9 8U; 6AUA 9 C< M 2/// 9 8U; AUC 9 A< M 2/// 9 8 U 276 M 2/// 9 8 U 8/ M 2/// 9 A6= M 2/// 9 2./ M 2A6= M 22./

Page 6 / 63

48. An array SG8/HG7/H is stored in the memory along the ro* *ith ea)h o+ the element o))upying 6 bytes, +ind out the memory lo)ation +or the element SG6/HG2/H, i+ an element SG2AHGAH is stored at the memory lo)ation AA//. Ans. Gi1en, DM6, "M8/, &M7/, #o);SG2AHGAH<MAA// Ro* &a'or Bormula: #o);SG!HGJH< MBase;S<9DU;&U!9J< #o);SG2AHGAH< MBase;S<96U;7/U2A9A< AA// MBase;S< 9 6U;8A/9A< Base;S< MAA// V E2/ M 8AE/ M8AE/96U;7/U6/92/< M8AE/96U;.//92/< M8AE/9266/ M A=2/ 4A. An array PG6/HG7/H is stored in the memory along the )olumn *ith ea)h o+ the element o))upying 8 bytes, +ind out the memory lo)ation +or the element PGAHG2AH, i+ an element PG6H G6/H is stored at the memory lo)ation A///. Ans. Gi1en, DM8, "M6/, &M7/, #o);PG6HG6/H<MA/// Column &a'or Bormula: #o);PG!HGJH< MBase;P<9DU;"UJ9!< #o);PG6HG6/H< MBase;P<98U;6/U6/96< A/// MBase;P<98U;8//96< Base;P< MA/// V 2./= Base;P< M77E6 #o);PGAHG2AH< M77E698U;6/U2A9A< M77E698U;7//9A< M77E69266/ M8.26 #o);SG6/HG2/H<

Page F / 63

S)a)-5 A.."5a)-"3 "2 O9Oe5)+


S1"#) A3+(e# 8*e+)-"3+ ( &a#;+'
"ote : Pra)ti)e the *ay to *rite the +un)tion de+inition *here array and its siYe are passed as arguments. Pra)ti)e *ith the )on)epts o+ a))essing the elements o+ the one 5 t*o dimensional array. Apply the suitable logi) to sol1e the gi1en problem and *rite the )oding o+ it. 42. Drite a +un)tion in C99 to +ind sum o+ ro*s +rom a t*o dimensional array. Ans : 1oid &atAdd;int AG HG H,int ", int &< F +or ;int RM/IRL"IR99< F int SumRM/I +or ;int CM/ICL&IC99< SumR9MAGCHGRHI )outLLSumRLLendlI K K 46. Drite a +un)tion in C99 to +ind the sum o+ both le+t and right diagonal elements +rom a t*o dimensional array ;matri3<. Ans : 1oid ?iagSum;int AG HG H, int "< F int Sum?2M/,Sum?6M/I +or ;int !M/I!L"I!99< F Sum?29MAG!HG!HI Sum?69MAG"R!R2HG!HI K )outLLJSum o+ ?iagonal 2:JLLSum?2LLendlI )outLLJSum o+ ?iagonal 6:JLLSum?6LLendlI K 47. Drite a +un)tion in C99 *hi)h a))epts an integer array and its siYe as arguments and repla)es elements ha1ing e1en 1alues *ith its hal+ and elements ha1ing odd 1alues *ith t*i)e its 1alue. eg: i+ the array )ontains : 7, 8, A, 2., E then the +un)tion should be rearranged as ., 6,2/,=, 2= Ans: 1oid )al);int 3G H, int m< F +or;int iM/I iLmI 99i< F i+;3GiH06MM/< 3GiHM3GiH56I else 3GiHM3GiHU6I K K 48. Drite a user de+ined +un)tion in C99 *hi)h inta es one dimensional array and siYe o+ array as argument and display the elements *hi)h are prime. !+ 2? array is 2/ , 6 , 7 , 8 , A , 2. , 2C , 67 (hen prime numbers in abo1e array are: 6 , 7 , A, 2C, 67 Ans: 1oid primedisp;int 3G H, int m< Page J / 63

F int n+I +or;int iM/I iLmI 99i< F n+M/I +or;int 'M2I 'LM3GiHI '99< i+;3GiH 0 ' MM /< n+99I i+;n+ MM 6< )outLLJNnJLL3GiHI K K 4A. Drite a +un)tion in C99 *hi)h a))epts an integer array and its siYe as arguments5parameters and e3)hanges the 1alues at alternate lo)ations. e3ample : i+ the array is =,2/,2,7,2C,E/,27,./ then rearrange the array as 2/,=,7,2,E/,2C,./,27 Ans : 1oid e3)hange;int 3G H, int m< F int yI +or;int iM/I iLmI iM i96< F i+;mRi MM 2< 55 i+ m ;no. o+ element < is odd last element i M mI 55 should not alter its position. else F yM 3GiHI 3GiH M 3Gi92HI 3Gi92H M yI K K K

S1"#) A3+(e# 8*e+)-"3+ ( 3 &a#;+'


42. Drite a +un)tion in C99 to merge the )ontents o+ t*o sorted arrays A > B into third array C. Assuming array A is sorted in as)ending order, B is sorted in des)ending order, the resultant array is re-uired to be in as)ending order. Ans: 1oid &@RG@;int AG H, int BG H, int CG H, int &, int ", int >K< F int !,J, KI +or;!M/, JM" V 2, KM/I !L& >> JWM/I< F i+ ;AG!HLMBGJH< CGK99HMAG!99HI else CGK99HMBGJRRHI K +or ;int (M!I(L&I(99< CGK99HMAG(HI +or ;(MJI(WM/I(RR< CGK99HMBG(HI K 46. Gi1en t*o arrays o+ integers 3 and y o+ siYes m and n respe)ti1ely. (hird array o+ integers Y has m9n siYe. (hese are passed as the arguments to the +un)tion @:C$A"G@;<. Drite a Page K / 63

+un)tion named @:C$A"G@;< *hi)h *ill produ)e the elements to the third array named Y, su)h that the +ollo*ing se-uen)e is +ollo*ed: ;i< All odds numbers o+ 3 +rom le+t to right are )opied into Y +rom le+t to right. ;ii< All e1en number o+ 3 +rom le+t to right are )opied into Y +rom right to le+t. ;iii< All odd numbers o+ y +rom le+t to right are )opied into Y +rom le+t to right. ;i1< All e1en number o+ y +rom le+t to right are )opied into Y +rom right to le+t. e.g.: 3 is F7,6,2,C,.,7K and y is FE,7,A,.,6,=,2/K then Y M F7,2,C,7,E,7,A,2/,=,6,.,.,6K Ans: 1oid @:C$A"G@;int 3G H, int m, int yG H, int n, int YG H< F int lsM/,rsMm9nR2,iI +or;iM/IiLmI99i< F i+;3GiH06MM/< YGrsRRHM3GiHI else YGls99HM3GiHI K +or;iM/IiLnI99i< F i+;yGiH06MM/< YGrsRRHMyGiHI else YGls99HMyGiHI K )outLLPNn(he Array Y is : PI +or;iM/IiLMm9nR2Ii99< )outLLP PLLYGiHI K 47. Drite +un)tion SOR(PO!"(S;< in )99 to sort an array o+ stru)ture Game in des)ending order o+ points using Bubble Sort "ote: Assume the +ollo*ing de+inition o+ stru)ture Game stru)t Game F long P"oI 55 Player "umber )har P"ameG6/HI long pointsI KI Ans: 1oid SOR(PO!"(S;Game gmG H, int n < F Game tempI 5UPoints to note in bubble sort logi) 2. Compare *ith the ad'a)ent elements ie ' and '92 6. Bigger element goes to the top be)ause the elements in the des)ending order. 7. @a)h iteration the smaller elements )omes in the bottom.U5 +or;iM/I iLnI i99< F +or;'M/I 'L;nR2<RiI '99< F i+;gmG'H.points L gmG'92H.points< Page 3! / 63

55 'L ;nR2<Ri , subtra)ting i to a1oid the last elements 55 *hi)h are in the )orre)t order a+ter ea)h loop e3e)ution.

F tempMgmG'HI gmG'HMgmG'92HI gmG'92HMtempI K K K 48. Drite a +un)tion in C99 *hi)h a))epts an integer array and its siYe as arguments and assign the elements into a t*o dimensional array o+ integers in the +ollo*ing +ormat !+ the array is 2,6,7,8,A,. i+ the array is 2,6,7 (he resultant 6? array is (he resultant 6? array is 2678A. 267 /2678A /26 //2678 //2 ///267 ////26 /////2 Ans: 55#ogi) : Condition +or putting the 1alue is the position ;iLM'< o+ 6? array other*ise put Yero 1oid Change6?array;int 3GH, int siYe< F +or;iM/I iLsiYeI i99< F int M/I +or;int 'M/I 'L siYeI '99< F i+;iLM'< F yGiHG'HM3G HI 99I K else yGiHG'HM/I K K +or;iM/I iL siYeI i99< F )outLLJNnJI +or;int 'M/I 'L siYeI '99< )outLLyGiHG'HLLP PI K K 4A. Drite a +un)tion in C99 *hi)h a))epts an integer array o+ double dimensional *ith its siYe as arguments and displays the total numbers o+ odd, e1en and prime numbers in the array. @3ample : i+ the +ollo*ing integer array *ill be passed to the +un)tion, i.e. . 8 27 2E A C 7 = 22 A2 E 26 67 8 . 62 6E 2= E 2/ 6= A 26 6 . (hen the output should be : (he total odd numbers are : 27 (he total odd numbers are : 26 (he total odd numbers are : 2/ Ans : 1oid num)he) ; int arrG HG H, int m, int n< F Page 31 / 63

int i, ', oddtM/, e1entM/, primetM/, n+, I +or;iM/I iLmI i99< F +or;'M/I 'LnI '99< F i+;arrGiHG'H 0 6 M M /< e1ent99I else oddt99I n+M/I +or; M2I LMarrGiHG'HI 99< F i+;arrGiHG'H 0 M M /< n+99I K i+;n+ M M 6< primet99I K K )outLLJNn (he total odd numbers are : OLLoddtI )outLLJNn (he total e1en numbers are : OLLe1entI )outLLJNn (he total prime numbers are : OLLprimetI K

Page 3 / 63

D,3a&-5 A.."5a)-"3 "2 O9Oe5)+


L"3g A3+(e# 8*e+)-"3+ ( < &a#;+ '
"ote : !nsertion at the beginning o+ #in ed #ist ;Push operation in Sta) <, !nsertion at the end o+ #in ed #ist ;!nsertion in a 4ueue<, ?eletion +rom the beginning o+ #in ed #ist ;Pop operation in Sta) as *ell as ?eletion o+ node in a 4ueue< are in the syllabus. So, only the logi) o+ these three +un)tions should be pra)ti)ed. (he logi) and the *ay to sol1e these +un)tions are gi1en belo*. Pra)ti)e them. 42. Drite a +un)tion in C99 to delete a node )ontaining )ustomerZs in+ormation, +rom a dynami)ally allo)ated 4ueue o+ Customers implemented *ith the help o+ the +ollo*ing stru)ture: stru)t Customer F int C"oI )har C"ameG6/HI Customer U#in I KI Ans: OR stru)t Customer F int C"oI )har C"ameG6/HI Customer U#in I K UBront, URear, UptrI 1oid ?@#@(@;< F i+;Bront M M "%##< )outLLJNn 4ueue %nder+lo*NnJI else F ptr M BrontI Bront M Bront#in I delete ptrI K K 1oid ?@#@(@;Customer U>Bront, Customer U>Rear< F i+;\Bront< )outLLJNn 4ueue %nder+lo*NnJI else F Customer UptrI ptrMBrontI BrontMBront#in I delete ptrI K K "ote: !+ Bront and Rear are de)lared as Global 1ariables then parameters are not needed in the abo1e +un)tion.

46. Drite a +un)tion in C99 to delete a node )ontaining Boo Zs in+ormation, +rom a dynami)ally allo)ated Sta) o+ Boo s implemented *ith the help o+ the +ollo*ing stru)ture. stru)t Boo F Page 33 / 63

int B"oI )har B"ameG6/HI Boo U"e3tI KI

Ans: stru)t Boo F int B"oI )har B"ameG6/HI Boo U"e3tI KUBront, URear, UptrI 1oid POP;< F i+;Bront M M "%##< )outLLJNn Sta) %nder+lo*NnJI else F ptr M BrontI Bront M Bront#in I delete ptrI K K

OR
1oid POP;Boo U>Bront, Boo U>Rear< F i+;\Bront< )outLLJNn Sta) %nder+lo*NnJI else F Boo UptrI ptrMBrontI BrontMBront#in I delete ptrI K K "ote: !+ Bront and Rear are de)lared as Global 1ariables then parameters are not needed in the abo1e +un)tion.

47. Drite a +un)tion in C99 to per+orm a P%S$ operation in a dynami)ally allo)ated sta) )onsidering the +ollo*ing: stru)t node F int 3,yI node U#in I KI Ans : stru)t node F int 3,yI node U#in I KUtop, UtempI 1oid P%S$;node Unp< F i+;top M M "%##< top M npI else F temp M topI top M npI 55 "e* node be)omes to the +irst node np#in M tempI K K 48. Drite a +un)tion in C99 to per+orm !nsert operation in a dynami)ally allo)ated 4ueue )ontaining names o+ students. stru)t stud Page 3< / 63

F )har "ameG6/HI stud U#in I KI Ans : stru)t stud F )har "ameG6/HI stud U#in I K U+ront, UrearI 1oid !nsert;stud Unp< F i+ ;+ront M M "%##< +ront M rear M npI else F rear#in M npI rear M npI K K 4A. Drite a +un)tion in C99 to per+orm Push operation on a dynami)ally allo)ated Sta) )ontaining real numbers. stru)t "O?@ F +loat ?ataI "O?@ U#in I KI Ans: )lass S(ACK F "O?@ U(opI publi): S(ACK;<I 1oid Push;<I 1oid Pop;<I KI 1oid S(ACK::Push;< F "O?@ U(empI (empMne* "O?@I )inWW(emp?ataI (emp#in M(opI (opM(empI K

Page 3= / 63

I32-% S P"+)2-% E%4#e++-"3+


S1"#) A3+(e# 8*e+)-"3+ ( &a#;+' (P"+)2-% )" I32-%'
42. @1aluate the +ollo*ing post+i3 notation o+ e3pression: 2A 7 6 9 5 C 9 6 U Ans: Step 2: Push

2A Step 6: Push 7 2A Step 8: 9 7 2A Step A: 5 Push Pop Op6MA 2A Step .: Push C 7 Step C: 9 C 7 Step =: Push 6 2/ Step C: U Push Pop Op6M6 2/ Page 36 / 63 Pop Op2M6 Op6M2/ 6/ Push Pop Op6MC 7 Pop Op2M7 Op6MC 2/ Push Pop Op6M6 Pop Op2M7 Op6M6 Step 7: Push 3 1=

A 2A

Pop Op2M2A Op6MA 7

Step =: Pop Result 6/ 46. ;e< @1aluate the +ollo*ing post+i3 notation o+ e3pression: (rue, Balse, A"?, (rue, (rue, "O(, OR, A"? Ans : Step 2: Push

(rue Step 6: Push Balse (rue Step 7: A"?

Push Pop Op6M(rue (rue Pop Op2MBalse Op6M(rue Balse

Step 8: Push (rue Balse Step A: Push (rue (rue Balse Step .: "O(

Push Pop Op6M(rue (rue Balse Push Pop Op6MBalse (rue Balse Push Pop Op6M(rue Balse Balse (rue Balse Pop Op2M(rue Op6MBalse Balse Pop Op2MBalse Op6M(rue Balse

Step C: OR

(rue Balse

Step =: A"?

Step E: Pop Result Balse Page 3F / 63

47. Ans:

@1aluate the +ollo*ing post+i3 notation o+ e3pression: 6A = 7 V 5 . U 2/ 9 Operator S)anned 6A = 7 R 5 . U 2/ 9 So, the ans*er is 8/. Sta) Content 6A 6A, = 6A, =, 7 6A, A A A, . 7/ 7/, 2/ 8/

(I32-% )" P"+)2-%'


48. Con1ert A 9 ; B U C V ; ? 5 @ << U B into post+i3 +orm sho*ing sta) status a+ter e1ery step. Ans : Step Symbol S)anned Sta) @3pression "o. 2 A ; A 6 9 ;9 A 7 ; ;9; A 8 B ;9; AB A U ;9;U AB . C ;9;U ABC C V ;9;R ABCU = ; ;9;R; ABCU E ? ;9;R; ABCU? 2/ 5 ;9;R ABCU? ;5 22 @ ;9;R; ABCU?@ 26 < ;9; ABCU?@5V 27 < ; ABCU?@5V 9 28 U ;U ABCU?@5V 9 2A B ;U ABCU?@5V 9B 2. < ABCU?@5V 9BU So, the post+i3 +orm is: A B C U ? @ 5 V 9 B U 4A. Con1ert "O( A OR "O( B A"? "O( C into post+i3 +orm. Ans : Step Symbol S)anned Sta) @3pression "o. 2 ; 6 "O( ; "O( 7 A ; "O( A 8 OR ; OR A "O( A "O( ; OR "O( A "O( . B ; OR "O( A "O( B C A"? ; OR A"? A "O( B "O( = "O( ; OR A"? "O( A "O( B "O( E C ; OR A"? A "O( B "O( C "O( Page 3J / 63

2/

< A "O( B "O( C "O( A"? OR So, the post+i3 +orm is: A "O( B "O( C "O( A"? OR

DATA :ILE HANDLING


SOME MPORTANT POINTS TO RE:RESH THE CONCEPT
2. (ype o+ #in Stream Class @3ample ?e)laration BileRtoR&emory i+stream i+stream +inI &emoryRtoRBile o+stream o+stream +outI BileRtoR&emory 5 &emoryRtoRBile +stream +stream +inoutI 6. Synta3 o+ open ;< R Lstream typeW.open;Ldata +ileW, L+ile modesW<I @3ample:R +in.open;O&ARK.?A(J, ios::in ` ios::binary<I +out.open;O&ARK.?A(J, ios::out ` ios::app ` ios::binary<I 7. ?i++erent +ile modes are : ios::in, ios::out, ios::ate, ios::app, ios::trun), ios::binary, ios::no)reate, ios::norepla)e. 8. Synta3 o+ read;< R Lstream typeW.read;;)har U< > bu++er, siYeo+;bu++er<<I @3ample : +in.read;;)har U< > stud, siYeo+;stud<<I 55 stud is an ob'e)t5)lass A. Synta3 o+ *rite;< R Lstream typeW.*rite;;)har U< > bu++er, siYeo+;bu++er<<I @3ample : +out.*rite;;)har U< > stud, siYeo+;stud<<I 55 stud is an ob'e)t5)lass .. ?ete)ting @OB : @3ample :R +in.eo+;< C. Common +orms o+ +ile pointer +un)tions: ;a< see g;< V Listream ob'e)tW.see g;long, see Sdir<I @3ample : R +in.see g;7/ , ios::beg<I ;b< see p;< V Lostream ob'e)tW.see p;long, see Sdir<I @3ample : R +out.see p; V2 U siYeo+;stud<, ios::)ur<I ;)< tellg;< 5 tellp;< returns the position in bytes o+ getSpointer5putSpointer. ;d< ?i++erent de+initions o+ see Sdir are ios::beg ;re+ers to beginning o+ the +ile<, ios::)ur;re+ers to )urrent position in the +ile<, ios::end ;re+ers to end o+ the +ile<. =. Closing a +ile : streamSob'e)t.)lose;<I @3ample : +in.)lose;<I

Ve#, S1"#) A3+(e# 8*e+)-"3+ ( 1 &a#;'


42. Obser1e the program segment gi1en belo* )are+ully and +ill the blan s mar ed as Statement 2 and Statement 6 using see g;<5see p;< +un)tions +or per+orming the re-uired tas . Tin)lude L+stream.hW )lass !tem F int !noI)har !temG6/HI publi): 55Bun)tion to sear)h and display the )ontent o+ a parti)ular re)ord 1oid Sear)h;int <I 55Bun)tion to modi+y the )ontent o+ a parti)ular re)ord number 1oid &odi+y;int<I KI 1oid !tem::Sear)h;int Re)"o< F +stream BileI Bile.open;OS(OCK.?A(J,ios::binary`ios::in<I Page 3K / 63

SSSSSSSSSSSSSSSSSSSSSS 55Statement 2 Bile.read;;)harU<this,siYeo+;!tem<<I )outLL!noLLJMMWJLL!temLLendlI Bile.)lose;<I K 1oid !tem::&odi+y;int Re)"o< F +stream BileI Bile.open;OS(OCK.?A(J,ios::binary`ios::in`ios::out<I )outWW!noI)in.getline;!tem,6/<I SSSSSSSSSSSSSSSSSSSSSS 55Statement 6 Bile.*rite;;)harU<this,siYeo+;!tem<<I Bile.)lose;<I K A3+ / S)a)e&e3) 1 N :-.eI+ee;g( (Re5N" N 1' C +-Re"2(I)e&'A -"+//9eg'B S)a)e&e3) N :-.eI+ee;4((Re5N" N 1' C +-Re"2(I)e&'A -"+//9eg'B 46. Obser1e the program segment gi1en belo* )are+ully and +ill the blan s mar ed as Statement 2 and Statement 6 using see g;< and tellg;< +un)tions +or per+orming the re-uired tas . Tin)lude L+stream.hW )lass @mployee F int @noI)har @nameG6/HI publi): 55Bun)tion to )ount the total number o+ re)ords int Countre);<I KI int !tem::Countre);< F +stream BileI Bile.open;O@&P.?A(J,ios::binary`ios::in<I SSSSSSSSSSSSSSSSSSSSSS 55Statement 2 int Bytes M SSSSSSSSSSSSSSSSSSSSSS int Count M Bytes 5 siYeo+;!tem<I Bile.)lose;<I return CountI K S)a)e&e3) 1 N :-.eI+ee;g(!A-"+//e3$'B S)a)e&e3) N :-.eI)e..g('B 47. Obser1e the program segment gi1en belo* )are+ully and ans*er the +ollo*ing:R Tin)lude L+stream.hW )lass stud F int rnoI )har nameG6/HI publi): 1oid enroll;<I 1oid disp;<I Page <! / 63 A3+/ 55Statement 6

long rrno;< Freturn rnoIK KI 1oid update;long i< F +stream BileI Bile.open;OS(OCK.?A(J,ios::binary`ios::in<I Stud s2I int re)ordM/,+oundM/I *hile;Bile.read;;)harU<>s2,siYeo+;stud<<< F i+;i MM s2.rrno;<< F )outLLJenter ne* s)oreJI S2.enroll;<I SSSSSSSSSSSSSSSSSSSSSS SSSSSSSSSSSSSSSSSSSSSS BoundM2I K Re)ord99I K !+;+oundMM2< CoutLLJre)ord updateJI Bile.)lose;<I K Drite the statement 2 to position the +ile pointer at the beginning o+ the re)ord > statement 6 to *rite the re)ord. S)a)e&e3) 1 N :-.eI+ee;4(N1 C +-Re"2( +1 'A -"+ // 5*#'B S)a)e&e3) N :-.eI(#-)e( ( 51a# C' S+1A +-Re"2(+1''B

55Statement 2 55Statement 6

A3+/

48. A +ile named as OS(%?@"(.?A(J )ontains the student re)ords, i.e. ob'e)ts o+ )lass student. Assuming that the +ile is 'ust opened through the ob'e)t B!#@ o+ +stream )lass, in the re-uired +ile mode, *rite the )ommand to position the put pointer to point to the beginning o+ the se)ond re)ord +rom the last re)ord. A3+ / :ILEI+ee;4( N C +-Re"2(+)*$e3)'A -"+//e3$'B 4A. A +ile named as O@&P#OX@@.?A(J )ontains the student re)ords, i.e. ob'e)ts o+ )lass employee. Assuming that the +ile is 'ust opened through the ob'e)t B!#@ o+ +stream )lass, in the re-uired Bile mode, *rite the )ommand to position the get pointer to point to eighth re)ord +rom the beginning. A3+ / :-.eI+ee;g(JA-"+//9eg'B

S1"#) A3+(e# 8*e+)-"3+ ( &a#;+'


42. Drite a +un)tion in C99 to )ount the number o+ lo*er)ase alphabets present in a te3t +ile OBOOK.(:(JI Ans: int )ountlo*er; < 55 all re-uired header +iles are in)luded F i+stream +in;OBOOK.(:(J<I )har )hI int )ountM/I *hile;+in.get;)h<< F i+;islo*er;)h<< )ount99I K Page <1 / 63

+in.)lose; <I return )ountI K 46. Drite a +un)tion in C99 to )ount the number o+ alphabets present in a te3t +ile O?A(A.(:(J. Ans: 1oid )ount; < F i+stream +ile;O?A(A.(:(J<I )har )hI int totalM/I *hile;+ile.get;)h<< F i+;isalpha;)h<< total99I K )outLLJNn (he (otal no o+ alphabets areJLLtotalI +ile.)lose; <I K 47. Ans: Drite a +un)tion in C99 to )ount the number o+ 1o*els present in a te3t +ile OS(ORX.(:(J. 1oid 1o*el)ount; < F Char )hI i+stream +ile;OS(ORX.(:(J<I int nM/I *hile;+ile.get;)h<< F i+;)hMMZaZ`` )hMMZAZ`` )hMMZeZ`` )hMMZ@Z`` )hMMZiZ`` )hMMZ!Z`` )hMMZoZ`` )hMMZOZ`` )hMMZuZ``)hMMZ%Z< n99I K )outLLJNn (otal no. o+ 1o*els areJLLnI +ile.)lose;<I K

48. Ans:

Drite a +un)tion in C99 to )ount the number o+ *ords in a te3t +ile "O(@S.(:(. 1oid *ord)ount; < F i+stream +2;O"O(@S.(:(J<I )har )hI int totM/I +2.see g;/<I *hile;+2.get;)h<< F i+; )hMMZ a`` )hMMZ.Z`` )hMMZQZ< tot99I K )outLLJNn total no. o+ *ords are OLLtotI +2.)lose;<I K 4A. Drite a +un)tion in C99 to )ount the number o+ lines present in a te3t +ile OS(ORX.(:(J. Ans : 1oid Count#ine;< F i+stream B!#;OS(ORX.(:(J<I Page < / 63

int #!"@SM/I )har S(RG=/HI *hile ;B!#.getline;S(R,=/<< #!"@S99I )outLLJ"o. o+ #ines:JLL#!"@SLLendlI B!#.)lose;<I K

S1"#) A3+(e# 8*e+)-"3+ ( 3 &a#;+'


42. Drite a +un)tion in C99 to add more ne* ob'e)ts at the bottom o+ a binary +ile S(%?@"(.?A(J, assuming the binary +ile is )ontaining the ob'e)ts o+ the +ollo*ing )lass. )lass S(%? F int RnoI )har "ameG6/HI publi): 1oid @nter;<F)inWWRnoIgets;"ame<IK 1oid ?isplay;<F)outLLRnoLL"ameLLendlIK KI 1oid Addne*;< F o+stream B!#I B!#.open;OS(%?@"(.?A(J, ios::out ` ios::binary ` ios::app<I S(%? SI )har C$ M ayZI *hile;C$ MMZXZ `` C$ MMZyZ< F S.@nter;<I B!#.*rite;;)harU<>S,siYeo+;S<<I )outLLJ&ore;X5"<QJI)inWWC$I K B!#.)lose;<I K

Ans:

46. Drite a +un)tion in C99 to read > display the details o+ all the members *hose membership type is a#Z or a&Z +rom a binary +ile OC#%B.?A(J. Assume the binary +ile )ontains ob'e)t o+ )lass C#%B. )lass C#%B F int mnoI )har mnameG6/HI )har typeI publi): 1oid register ; <I 1oid dis;<I )har *hattype; < F return typeIK KI Ans : 1oid sho*; < F i+stream +ileI Page <3 / 63

C#%B )2I )har sI +ile.open;OC#%B.?A(J, ios::in ` ios::binary<I *hile; +ile.read;;)harU<>)2, siYeo+ ;)2<<< F s M )2.*hattype; <I i+;;sMMZ#Z< `` ;sMMZ&Z<< )2.dis; <I K Bile.)lose;<I K 47. Gi1en a binary +ile P$O"@.?A( )ontaining re)ords o+ the +ollo*ing stru)ture type. )lass Phonlist F )har addI )har "ameG6/HI )har areaGAHI publi): 1oid register;<I 1oid sho*;<I int )he) ;)har a)G H< F return str)mp;area,a)< K KI Drite a +un)tion (RA"SB@R; < in C99, that *ould )opy all re)ords *hi)h are ha1ing area as J?@#J +rom P$O"@.?A( to P$O"BACK.?A(. Ans: 1oid trans+er; < F i+stream BinI O+stream BoutI Phonlist phI Bin.open;OP$O"@.?A(J, ios::in ` ios::binary<I Bout.open;OP$O"BACK.?A(J, ios::out ` ios:: binary<I *hile;Bin.read;;)harU<>ph, siYeo+;ph<<< F i+;ph.)he) ;O?@#J< MM /< Bout.*rite;;)harU<>ph, siYeo+;ph<<I K Bin.)lose;<I Bout.)lose;<I K Drite a +un)tion in C99 to modi+y the name o+ a student *hose roll number is entered during the e3e)ution o+ the program. Sear)h the a))epted roll number +rom a binary +ile OS(%?@"(.?A(J and modi+y the name, assuming the binary +ile is )ontaining the ob'e)ts o+ the +ollo*ing )lass. )lass S(%? F int RnoI )har "ameG6/HI publi): int srno;<F return RnoIK 1oid @nter;<Fgets;"ame<IK Page << / 63

48.

1oid ?isplay;<F)outLLRnoLL"ameLLendlIK KI Ans : 1oid &odi+yname;< F +stream BileI Bile.open;OS(%?@"(.?A(J, ios::binary ` ios::in ` ios::out<I S(%? sI int mrnoI )outLLJNn@nter the roll number to modi+y : OI )inWWmrnoI *hile ;Bile.read;;)harU<>s, siYeo+;s<<< F i+;s.srno;< M M mrno< F )outLLJNn &odi+y the name OI s.@nter;<I Bile.see p; V2 U siYeo+;s<, ios::)ur<I Bile.*rite;;)har U<>s, siYeo+;s<<I K K Bile.)lose ;<I K 4A. Gi1en a binary +ile P$O"@.?A(, )ontaining re)ords o+ the +ollo*ing stru)ture type )lass Phonlist F )har "ameG6/HI )har AddressG7/HI )har AreaCodeGAHI )har Phone"oG2AHI publi): 1oid Register;<I 1oid Sho*;<I int Che) Code;)har ACGH< F return str)mp;AreaCode,AC<I K KI Drite a +un)tion (RA"SB@R ; < in C99, that *ould )opy all those re)ords *hi)h are ha1ing AreaCode as O?@#J +rom P$O"@.?A( to P$O"BACK.?A(. Ans : 1oid (RA"SB@R;< F Phonlist PI +stream +in, +outI +in.open;OP$O"@.?A(J,ios::binary`ios::in<I +out.open;OP$O"BACK.?A(J,ios::binary`ios::out<I +in.see g;/<I *hile;+in.read;;)harU<>P, siYeo+;P<<< F i+;P.Che) Code;O?@#J< M M /< +out.*rite;;)harU<>P, siYeo+;P<<I K +in.)lose;<I +out.)lose;<I K Page <= / 63

Da)a9a+e+ a3$ S8L


S1"#) A3+(e# 8*e+)-"3+
42. Dhat is a database systemQ Dhat are the ad1antages pro1ided by a database systemQ Ans : A database is a )olle)tion o+ interrelated data and a database system is basi)ally a )omputer based re)ord eeping system. (he ad1antages pro1ided by a database system are ;i< redu)ed data redundan)y ;ii< Controlled data in)onsisten)y ;iii< Shared data ;i1< StandardiYed data ;1< Se)ured data ;1i< !ntegrated data. 46. Dhat are the 1arious le1els o+ database abstra)tion in a database systemQ Ans : (he 1arious le1els o+ database abstra)tion in a database system are ;i< !nternal ;Physi)al< #e1el ;ii< Con)eptual #e1el ;iii< @3ternal ;Vie*< #e1el. 47. Dhat is ?ata !ndependen)eQ Dhat are the le1els o+ ?ata !ndependen)eQ Ans: ?ata !ndependen)e is the ability to modi+y a s)heme de+inition in one le1el *ithout a++e)ting a s)heme de+inition in the ne3t higher le1el. (he t*o le1els o+ ?ata !ndependen)e are ;i< Physi)al ?ata !ndependen)e ;ii< #ogi)al ?ata !ndependen)e. 48. Dhat is a 1ie*Q $o* is it use+ulQ Ans : A 1ie* is a 1irtual table that does not really e3ist in its o*n right but is instead deri1ed +rom one or more underlying base table;s<. !t pro1ides an e3)ellent *ay to gi1e people a))ess to some but not all o+ the in+ormation in a table. 4A. Dhat is relationQ ?e+ine the relational data modelQ Ans : A relation is a table ha1ing atomi) 1alues, uni-ue ro*s and unordered ro*s and )olumns. (he relational data model represents data and relationships among data by a )olle)tion o+ tables no*n as relation, ea)h o+ *hi)h has a number o+ )olumns *ith uni-ue names. 4.. ?e+ine : ;i< (uple ;ii< Attribute ;iii< ?egree ;i1< Cardinality. Ans : ;i< (uple V (he ro*s o+ tables ;relations< are re+erred as tuples. ;ii< Attribute V (he )olumns o+ tables ;relations< are re+erred as attributes. ;iii< ?egree V (he number o+ attributes in a relation;table< is )alled degree o+ a relation. ;i1< Cardinality V (he number o+ tuples in a relation;table< is )alled )ardinality o+ a relation. 4C. Dhat do you understand by Primary Key > Candidate KeysQ Ans : An attribute or set attributes *hi)h are used to identi+y a tuple uni-uely is no*n as Primary Key. !+ a table has more than one su)h attributes *hi)h identi+y a tuple uni-uely than all su)h attributes are no*n as Candidate Keys. 4=. ?e+ine alternate ey. Dhat do you understand by +oreign eyQ Ans : A )andidate ey that is not the primary ey is )alled an alternate ey. A nonR ey attribute, *hose 1alues are deri1ed +rom the primary ey o+ some other table, is no*n as +oreign ey in its )urrent table. 4E. Dhat is ?ata ?e+inition #anguageQ Gi1e e3amples o+ some ??# )ommands. Ans : (he S4# ?ata ?e+inition #anguage pro1ides )ommands +or de+ining relation s)hemas, deleting relations, )reating inde3es and modi+ying relation s)hemas. (he e3amples o+ some ??# )ommands are CR@A(@ (AB#@, A#(@R (AB#@, ?ROP (AB#@, ?ROP V!@D )ommands et). 42/. Dhat is ?ata &anipulation #anguageQ Gi1e e3amples o+ some ?&# )ommands. Ans : (he S4# ?ata &anipulation #anguage in)ludes a -uery language to insert, delete and modi+y tuples in the database. (he e3amples o+ some ?&# )ommands are S@#@C(, !"S@R(, ?@#@(@, %P?A(@ )ommands et). 422. Dhat is S4#Q Drite the 1arious pro)essing )apabilities o+ S4#. Ans : S4# is a language that enables you to )reate and operate on relational databases. (he 1arious pro)essing )apabilities o+ S4# are data de+inition language, data manipulation language, 1ie* de+inition, authoriYation, integrity and transa)tion )ontrol.

SYNTAX "2 +"&e S8L COMMANDS /


Page <6 / 63

2. S@#@C( )olumn list BRO& Ltable nameW D$@R@ L)onditionW GRO%P BX L)olumn name;s<W $AV!"G Lsear)h )onditionW OR?@R BX )olumn nameI 6. !"S@R( !"(O Ltable nameW GL)olumn listWH VA#%@S ; L1alueW, L1alueW, ...<I 7. ?@#@(@ BRO& Ltable nameW GD$@R@ Lpredi)ateWHI 8. %P?A(@ Ltable nameW S@( L)olumn nameW M Lne* 1alueW GD$@R@ Lpredi)ateWHI A. CR@A(@ (AB#@ Ltable nameW ;L)olumn nameW Ldata typeW G;siYe<H L)olumn )onstraintW, L)olumn nameW Ldata typeW G;siYe<H L)olumn )onstraintW, ... Ltable )onstraintW ;L)olumn nameW GL)olumn nameW ...H< ...<I .. CR@A(@ V!@D L1ie* nameW G;L)olumn nameW, L)olumn nameW,...<H AS LS@#@C( )ommandWI C. A#(@R (AB#@ Ltable nameW A?? 5 &O?!BX L)olumn nameW Ldata typeW LsiYeWI =. ?ROP (AB#@ Ltable nameWI E. ?ROP V!@D L1ie* nameWI

L"3g A3+(e# 8*e+)-"3+


42. Consider the +ollo*ing tables AC(!V!(X and COAC$. Drite S4# )ommands +or the statements ;i< to ;i1< and gi1e outputs +or S4# -ueries ;1< to ;1iii<. (able: AC(!V!(X ACode A)ti1ity"ame Parti)ipants"u PriYe&oney S)hedule?ate m 2//2 Relay 2//38 2. 2//// 67RJanR6//8 2//6 $igh 'ump 2/ 26/// 26R?e)R6//7 2//7 Shot Put 26 =/// 28RBebR6//8 2//A #ong Jump 26 E/// /2RJanR6//8 2//= ?is)uss (hro* 2/ 2A/// 2ER&arR6//8 PCode 2 6 7 8 (able: COAC$ "ame ACode Ahmad $ussain 2//2 Ra1inder 2//= Janila 2//2 "aaY 2//7

;i< (o display the name o+ all a)ti1ities *ith their A)odes in des)ending order. ;ii< (o display sum o+ PriYe&oney +or ea)h o+ the "umber o+ parti)ipants groupings ;as sho*n in )olumn Parti)ipants"um 2/,26,2.<. ;iii< (o display the )oa)hZs name and ACodes in as)ending order o+ ACode +rom the table COAC$. ;i1< (o display the )ontent o+ the GA&@S table *hose S)hedule?ate earlier than /25/256//8 in as)ending order o+ Parti)ipant"um. ;1< S@#@C( CO%"(;?!S(!"C( Parti)ipants"um< BRO& AC(!V!(XI ;1i< S@#@C( &A:;S)hedule?ate<,&!";S)hedule?ate< BRO& AC(!V!(XI ;1ii< S@#@C( S%&;PriYe&oney< BRO& AC(!V!(XI ;1iii< S@#@C( ?!S(!"C( Parti)ipant"um BRO& COAC$I Ans : ;i< S@#@C( A)ti1ity"ame, ACode BRO& AC(!V!(X OR?@R BX A)ode ?@SCI ;ii< S@#@C( S%&;PriYe&oney<,Parti)ipants"um BRO& AC(!V!(X GRO%P BX Parti)ipants"umI ;iii< S@#@C( "ame, ACode BRO& COAC$ OR?@R BX ACodeI ;i1< S@#@C( U BRO& AC(!V!(X D$@R@ S)hedule?ateLZ/2RJanR6//8Z OR?@R BX Parti)ipants"umI ;1< 7 Page <F / 63

;1i< 2ER&arR6//8 26R?e)R6//7 ;1ii< A8/// ;1iii< 2. 2/ 26 46. Consider the +ollo*ing tables GA&@S and P#AX@R. Drite S4# )ommands +or the statements ;i< to ;i1< and gi1e outputs +or S4# -ueries ;1< to ;1iii<. (able: GA&@S GCode Game"ame "umber PriYe&oney S)hedule?ate 2/2 Carom Board 6 A/// 67RJanR6//8 2/6 Badminton 6 26/// 26R?e)R6//7 2/7 (able (ennis 8 =/// 28RBebR6//8 2/A Chess 6 E/// /2RJanR6//8 2/= #a*n (ennis 8 6A/// 2ER&arR6//8 (able: P#AX@R PCode "ame G)ode 2 "abi Ahmad 2/2 6 Ra1i Sahai 2/= 7 Jatin 2/2 8 "aYneen 2/7 ;i< (o display the name o+ all Games *ith their G)odes. ;ii< (o display details o+ those games *hi)h are ha1ing PriYe&oney more than C///. ;iii< (o display the )ontent o+ the GA&@S table in as)ending order o+ S)hedule?ate. ;i1< (o display sum o+ PriYe&oney +or ea)h o+ the "umber o+ parti)ipation groupings ;as sho*n in )olumn "umber 6 or 8<. ;1< S@#@C( CO%"(;?!S(!"C( "umber< BRO& GA&@SI ;1i< S@#@C( &A:;S)hedule?ate<,&!";S)hedule?ate< BRO& GA&@SI ;1ii< S@#@C( S%&;PriYe&oney< BRO& GA&@SI ;1iii< S@#@C( ?!S(!"C( G)ode BRO& P#AX@RI Ans : ;i< S@#@C( Game"ame,G)ode BRO& GA&@SI ;ii< S@#@C( U BRO& GA&@S D$@R@ PriYe&oneyWC///I ;iii< S@#@C( U BRO& GA&@S OR?@R BX S)hedule?ateI ;i1< S@#@C( S%&;PriYe&oney<,"umber BRO& GA&@S GRO%P BX "umberI ;1< 6 ;1i< 2ER&arR6//8 26R?e)R6//7 ;1ii< AE/// ;1iii< 2/2 2/7 2/= 47. Consider the +ollo*ing tables $OSP!(A#. Gi1e outputs +or S4# -ueries ;i< to ;i1< and *rite S4# )ommands +or the statements ;1< to ;1iii<. "o "ame Age ?epartment ?ateo+admin Charge Se3 2 Arpit .6 Surgery 625/25/. 7// & 6 bayana 2= @"( 265265/A 6A/ B 7 Kareem .= Orthopedi) 2E5/65/. 8A/ & 8 Abhilash 6. Surgery 685225/. 7// & A ?hanya 68 @"( 6/52/5/. 7A/ B . Si'u 67 Cardiology 2/52/5/. =// & C An ita 2. @"( 275/85/. 2// B = ?i1ya 6/ Cardiology 2/5225/. A// B Page <J / 63

E 2/

"idhin $ari

6A 6=

Orthopedi) Surgery

265/A5/. 2E5/75/.

C// 8A/

& &

;i< Sele)t S%&;Charge< +rom $OSP!(A# *here Se3MZBZI ;ii< Sele)t CO%"(;?!S(!"C( ?epartment < +rom $OSP!(A#I ;iii< Sele)t S%&;Charge< +rom $OSP!(A# group by ?epartmentI ;i1< Sele)t "ame +rom $OSP!(A# *here Se3MZBZ A"? Age W 6/I ;1< (o sho* all in+ormation about the patients *hose names are ha1ing +our )hara)ters only. ;1i< (o redu)e Rs 6// +rom the )harge o+ +emale patients *ho are in Cardiology department. ;1ii< (o insert a ne* ro* in the abo1e table *ith the +ollo*ing data : 22, aRa eshZ, 8A, a@"(Z, F/=5/=5/=K, 26//, a&Z ;1iii< (o remo1e the ro*s +rom the abo1e table *here age o+ the patient W ./. Ans : ;i< ;ii< ;iii< 26// 8 2/A/ C// 22A/ 27// ;i1< ?hanya ;1< S@#@C( U BRO& $OSP!(A# D$@R@ "A&@ #!K@ OS S S SJI ;1i< %P?A(@ $OSP!(A# S@( C$ARG@ M C$ARG@ V 6// D$@R@ ;?@PAR(&@"( M aCAR?!O#OGXZ A"? S@: M aBZ<I ;1ii< !"S@R( !"(O $OSP!(A# VA#%@S;22,aRa eshZ,8A,a@"(Z,F/=5/=5/=K, 26//, a&Z<I ;1iii< ?@#@(@ BRO& $OSP!(A# D$@R@ AG@ W ./I

48. Consider the +ollo*ing tables BOOKS. Drite S4# )ommands +or the statements ;i< to ;i1< and gi1e outputs +or S4# -ueries ;1< to ;1iii<. (able : BOOKS BS!d Boo S"ame AuthorS"ame Publisher Pri)e (ype 4uantity C/2 Bast Coo #ata Kapoor @PB 7AA Coo ery A B/2 (he (ears Dilliam $op ins Birst .A/ Bi)tion 6/ (/2 &y C99 Brain > Broo e BPB 7A/ (e3t 2/ (/6 C99 Brain A.D.Rossaine (?$ 7A/ (e3t 2A B/6 (huderbolts Anna Roberts Birst CA/ Bi)tion A/ i<. (o list the names +rom boo s o+ (e3t type. ii<. (o display the names and pri)e +rom boo s in as)ending order o+ their pri)e. iii<. (o in)rease the pri)e o+ all boo s o+ @PB publishers by A/. i1<. (o display the Boo S"ame, 4uantity and Pri)e +or all C99 boo s. 1<. Sele)t ma3;pri)e< +rom boo sI 1i<. Sele)t )ount;?!S(!"C( Publishers< +rom boo s *here Pri)e WM8//I 1ii<. Sele)t Boo S"ame, AuthorS"ame +rom boo s *here Publishers M aBirstZI 1iii<. Sele)t min;Pri)e< +rom boo s *here type M a(e3tZI Ans : ;i< S@#@C( Boo S"ame BRO& BOOKS D$@R@ (ype M a(e3tZI ;ii< S@#@C( Boo S"ame, Pri)e BRO& BOOKS OR?@R BX Pri)eI ;iii< %P?A(@ BOOKS S@( Pri)e M Pri)e 9 A/ D$@R@ Publisher M a@PBZI ;i1< S@#@C( Boo S"ame, 4uantity, Pri)e BRO& BOOKS D$@R@ Boo S"ame #!K@ a0C990ZI ;1< CA/ ;1i< 6 ;1ii< (he (ears Dilliam $op ins (huderbolts Anna Roberts ;1iii< 7A/ Page <K / 63

8=I Consider the tables !(@&S > CO&PA"X. Drite S4# )ommands +or the statements ;i< to ;i1< and gi1e the outputs +or S4# -ueries ;1< to ;1iii<. Ta9.e / ITEMS ID PNAME PRICE MDATE 8TY (//2 Soap 26.// 225/756//C 6// (//6 Paste 7E.A/ 6752656//. AA (//7 ?eodorant 26A.// 265/.56//C 8. (//8 $air Oil 6=.CA 6A5/E56//C 76A (//A Cold Cream ...// /E52/56//C 288 (//. (ooth Brush 6A.// 2C5/656//. 8AA ID (//2 (//= (//7 (//8 (//E (//. -'I --'I ---'I -6'I 6'I 6-'I 6--'I 6---'I Table : COMPANY COMP C-), $## &umbai Colgate ?elhi $## &umbai Paras $aryana Ponds "oida Dipro Ahmedabad

(o display P"A&@, PR!C@ U 4(X only +or the )ity &umbai. (o display produ)t name, )ompany name > pri)e +or those items *hi)h !?s are e-ual to the !?s o+ )ompany. (o delete the items produ)ed be+ore 6//C. (o in)rease the -uantity by 6/ +or soap and paste. S@#@C( CO%"(;U< BRO& !(@&S D$@R@ !(@&S.!?MCO&PA"X.!?I S@#@C( P"A&@ BRO& !(@&S D$@R@ PR!C@MS@#@C( &!";PR!C@< BRO& !(@&SI S@#@C( CO%"(;U< BRO& CO&PA"X D$@R@ CO&P #!K@ OPS S S SJI S@#@C( P"A&@ BRO& !(@&S D$@R@ 4(XL2//I

Ans : ;i< S@#@C( P"A&@, 4(XUPR!C@ BRO& !(@&S D$@R@ !(@&S.!? M CO&PA"X.!? A"? CO&PA"X.CityMZ&umbaiZI ;ii< S@#@C( P"A&@, CO&P, PR!C@ BRO& !(@&S, CO&PA"X D$@R@ !(@&S.!? M CO&PA"X.!? ;iii< ?@#@(@ BRO& !(@&S D$@R@ &?A(@ L F/25/256//CKI ;i1< %P?A(@ !(@&S S@( 4(X M 4(X 9 6/ D$@R@ P"A&@ M aSoapZ OR P"A&@ M aPasteZI ;1< 8 ;1i< Soap ;1ii< 6 ;1iii< Paste ?eodorant

B"".ea3 A.ge9#a
I3)#"$*5)-"3 )" B"".ea3 A.ge9#a S La(+ B"".ea3 A.ge9#a R*.e+
2 6 7 /9:M: /.:M/ 29:M2 Properties o+ / Properties o+ 2 Page =! / 63

8 A . C = E 2/ 22 26 27 28 2A 2. 2C 2= 2E 6/

2.:M: :9:M: :.:M: ;:< M : : 9 : M 2 : . : M / :9XMX9: : .X M X. : :9;X9b<M;:9X<9b : ;Xb< M ;:X< b : ;X 9 b< M :X 9 :b : 9 Xb M ;: 9 X< ;: 9 b< : 9 :X M : : . ;: 9 X< M : : 9 : X M : 9X ;: 9 X< M : . X ;:.X< M : 9 X

!dempoten)e #a* !n1olution #a* Complementarity #a* Commutati1e #a* Asso)iati1e #a* ?istributi1e #a* Absorption #a* (hird ?istributi1e #a* ?e&organZs (heorem

S1"#) A3+(e# 8*e+)-"3+ ( &a#;+'


42. State and 1eri+y ?emorgan]s #a*s algebrai)ally. Ans : ?emorgan]s #a*s are : ;i< ;:9X<] M :].X] ;i< ;:.X<] M :] 9 X] Veri+i)ation ;:9X<].;:9X< M :].X].;:9X< ;:.X<] 9 ;:.X< M ;:] 9 X]< 9 ;:.X< / M :].X].: 9 :].X].X 2 M ;:] 9 X] 9 :<. ;:] 9 X] 9 X< / M :].: .X]9 :]./ 2 M ;:] 9 : 9 X]< . ;:] 9 2< / M / .X]9 / 2 M ;2 9 X]< . 2 /M/9/ 2M2.2 /M/ 2M2 #.$.S M R.$.S #.$.S M R.$.S

46. State and algebrai)ally 1eri+y Absorption #a*s. Ans : Absorption #a*s are : ;i< :9:.X M : Veri+i)ation: #.$.S M : 9 : . X #.$.S M :.2 9 :.X M :.;2 9 X< M :.2 M: M R.$.S

;ii< : . ;: 9 X< M : M:.;:9X< M :.: 9 :.X M : 9 :.X M :.;2 9 X< M :.2 M: M R.$.S

47. State ?istributi1e #a*s. Drite the dual o+ : : 9 : X M : 9 X Ans : ?istributi1e la*s are : ;i< : . ; X 9 b < M :.X 9 :.b ;ii< : 9 X.b M ;: 9 X<.;: 9 b< (he dual +orm o+ : 9 : X M : 9 X is : . ; : 9 X < M : . X 48. State any one +orm o+ Asso)iati1e la* and 1eri+y it using truth table. Ans : Asso)iati1e la* states that : ;i< : 9 ;X 9 b< M ;: 9 X< 9 b ;ii< :.;X.b< M ;:.X<.b Veri+i)ation o+ : 9 ;X 9 b< M ;: 9 X< 9 b using truth table : X b X9b :9 : 9 ;X 9 ;: 9 X< 9 b X b< Page =1 / 63

/ / / / / / / / / 2 2 / 2 2 / 2 / 2 2 2 2 / 2 2 2 2 2 2 2 / / / 2 2 2 2 / 2 2 2 2 2 2 2 / 2 2 2 2 2 2 2 2 2 2 2 4A. State the prin)iple o+ duality in boolean algebra and gi1e the dual o+ the +ollo*ing:

:.X.b 9 :.X.b 9 :.X.b Ans : Prin)iple o+ duality states that +rom e1ery boolean relation, another boolean relation )an be deri1ed by : ;i< )hanging ea)h OR ;9< sign to an A"? ;.< sign ;ii< )hanging ea)h A"? ;.< sign to an OR ;9< sign ;iii< repla)ing ea)h 2 by / and ea)h / by 2. (he dual +orm o+ :.X.b 9 :.X.b 9 :.X.b is ;:9X9b< . ;:9X9b< . ;:9X9b< 4.. @3plain about tautology and +alla)y. Ans : !+ result o+ any logi)al statement or e3pression is al*ays (R%@ or 2, it is )alled tautology. !+ result o+ any logi)al statement or e3pression is al*ays BA#S@ or /, it is )alled +alla)y. Bor e3ample, 2 9 : M 2 is a tautology and / . : M / is a +alla)y.

SOP S POS Ve#, S1"#) A3+(e# 8*e+)-"3+ ( 1 Ma#;'


42. Drite the POS +orm o+ a Boolean +un)tion B, *hi)h is represented in a truth table as +ollo*s: % V D B "ote: !n POS, )onsider only the )ases / / / 2 those )ontaining / in B )olumn. Bor / / 2 / the same ro*s, *rite sum o+ the / 2 / 2 logi)al 1ariables ;@3. % i.e. / in % / 2 2 / )olumn, %] i.e. 2 +or % )olumn<. (hen 2 / the produ)t / *rite +orm2 o+ all su)h 2 / o+ logi)al 2 terms. / sum 2 2 / 2 2 2 2 2 Ans : B;%,V,D< M ; % 9 V 9 D] <.; % 9 V] 9D] <.; %] 9 V 9 D] < 46. Drite the SOP +orm o+ a Boolean +un)tion G, *hi)h is represented in a truth table as +ollo*s: : X b G )onsider / / "ote: !n SOP, / / only the )ases those )ontaining 2 in G )olumn. Bor / / 2 2 the same ro*s, *rite produ)t o+ the / 2 / 2 logi)al 1ariables ;@3. :] i.e. / in : / 2 2 / )olumn, : i.e. 2 +or : )olumn<. (hen 2 / *rite the/ sum +orm / o+ all su)h 2 / produ)t o+ 2 logi)al terms. 2 2 2 / 2 2 2 2 / Ans : G;:,X,b< M ; :] . X] . b < 9 ; :] . X .b] < 9 ; : . X] . b < 9 ; : . X . b] < 47. Con1ert the +ollo*ing +un)tion into )anoni)al SOP +orm. B; A , B, C, ? < M ; 2, 8, ., =, 22, 27< Ans : B; A , B, C, ? < M A] B] C] ? 9 A] B C] ?] 9 A] B C ?] 9 A B] C] ?] 9 A B] C ? 9 A B C] ? ;"ote : $ere 2 M ///2 A] B] C] ? , 8 M /2// A] B C] ?] , 27 M 22/2 A B C] ? ...< Page = / 63

48. Con1ert the +ollo*ing +un)tion into )anoni)al SOP +orm. B; A , B, C, ? < M ; /, 7, C, E, 2/, 28< Ans : B; A , B, C, ? < M ;A9 B9C9?< . ;A9B9C]9?]< . ;A9B]9C]9?]< . ;A]9B9C9?]< . ;A]9B9C]9?< . ;A]9B]9C]9?< ;"ote : $ere / M //// A9 B9C9? , 7 M //22 A9B9C]9?], 2/ M 2/2/ A]9B9C]9?...< 4A. Con1ert the +ollo*ing +un)tion to its e-ui1alent SOP shorthand notation. B; A , B, C, ? < M ; /, 7, C, E, 2/, 28< Ans : (he e-ui1alent SOP shorthand notation o+ B; A , B, C, ? < M ; /, 7, C, E, 2/, 28< is B; A , B, C, ? < M ; 2, 6, 8, A, ., =, 22, 26, 27, 2A< 4.. Con1ert the +ollo*ing +un)tion to its e-ui1alent POS shorthand notation. B; A , B, C, ? < M ; 2, 8, ., =, 22, 27< Ans : (he e-ui1alent POS shorthand notation o+ B; A , B, C, ? < M ; 2, 8, ., =, 22, 27< is B; A , B, C, ? < M ; /, 6, 7, A, C, E, 2/, 26, 28, 2A<

Ka#3a*g1 Ma4 S1"#) A3+(e# 8*e+)-"3+ ( 3 &a#;+'


42. Redu)e the +ollo*ing Boolean @3pression using KR&ap: B; A, B, C, ? < M ; /, 6, 7, 8, ., C, =, E, 2/, 26, 27, 28 < Ans : C? AB C]?] C]? C? C?] A]B] A]B AB AB]

2
/ 2

2
7

2
6

2
8 A

2
C

2
.

2
26

2
27 2A

2
28

2
=

2
E 22

2
2/

(here are 2 o)tet, 6 -uads a+ter eliminating the redundant groups. O)tet ;m/, m6, m8, m., m=, m2/, m26, m28< redu)es to ?] 4uad ;m6, m7, m., mC< redu)es to A]C 4uad ; m=, mE, m26, m27< redu)es to AC ] $en)e, B; A, B, C, ? < M ?] 9 A]C 9 AC ] 46. Redu)e the +ollo*ing Boolean @3pression using KR&ap: C9? B; A, B, C,C9? ? < M ; /, 7, A, ., C, C]9?] =, 22, 2A < C]9? A9B C9?] Ans :

/
/ 2

/
7 6

A9B A9B]

/
8 A

/
C

/
.

/
26 27 2A 28

/
= E

Page =3 / 63
22 2/

A]9B] A]9B

(here are 2 -uad and 7 pairs a+ter eliminating the redundant groups. 4uad ;&7, &C, &22, &2A< redu)es to C] 9 ?] Pair ; &A, &C< redu)es to A 9 B ] 9 ?] Pair ; &., &C< redu)es to A 9 B ] 9 C] Pair ; &/, &=< redu)es to B 9 C 9 ? $en)e, B; A, B, C, ? < M ;C] 9 ?]< . ;A 9 B ] 9 ?]< . ;A 9 B ] 9 C]< . ;B 9 C 9 ?< 47. Redu)e the +ollo*ing Boolean @3pression using KR&ap: B; A, B, C, ? < M ; 6, 7, 8, A, 2/, 22, 27, 28, 2A < Ans : C? AB C]?] C]? C? C?] A]B] A]B AB AB]

2
/ 2 7

2
6

2
8

2
A C .

2
26 27

2
2A

2
28

2
= E 22

2
2/

(here are 6 -uads and 6 pairs a+ter eliminating the redundant groups. 4uad 2 ;m6, m7, m2/, m22< redu)es to B]C 4uad 6 ; m2/, m22, m28, m2A< redu)es to AC Pair 2 ;m8, mA< redu)es to A] BC ] Pair 2 ;m27, m2A< redu)es to AB? $en)e, B; A, B, C, ? < M B]C 9 AC 9 A]BC ] 9 AB? 48. Redu)e the +ollo*ing Boolean @3pression using KR&ap: B;A,B,C,?<M;/,2,6,8,A,.,=,2/< Ans: ATBT ATB AB
1 13 J K 1= 1<

CTDT 1
!

CTD 1
1

CD
3

CDT 1 1
F 6

1
<

1
=

ABT

1
11

1
1!

(here are 7 -uads a+ter eliminating the redundant groups. 4uad 2 ;m/, m2, m8, mA< redu)es to A] C ] 4uad 6 ; m/, m6, m8, m.< redu)es to A] ?] 4uad 7 ; m/, m6, m=, m2/< redu)es to B] ?] Page =< / 63

$en)e, B; A, B, C, ? < M A] C ] 9 A] ? ] 9 B ] ? ] 48. Redu)e the +ollo*ing Boolean @3pression using KR&ap: B;A,B,C,?<M;/,2,8,A,C,2/,27,2A< Ans: CTDT CTD CD CDT ATBT 1 1
! 1 3

ATB AB

1
< 1

1
=

1
F 6 1<

1
13 J K

1
1=

ABT
11

1
1!

(here are 6 -uads and one blo) a+ter eliminating the redundant groups. 4uad 2 ;m/, m2, m8, mA< redu)es to A] C ] 4uad 6 ; m/, m6, m8, m.< redu)es to B ? m2/ M A B ] C ? ] $en)e, B; A, B, C, ? < M A] C ] 9 B ? 9 A B ] C ? ]

Ba+-5 L"g-5 Ga)e+


"ote : A gate is simply an ele)troni) )ir)uit *hi)h operates on one or more signals to produ)e an output signal. (he three basi) logi) gates are "O( gate, OR gate, A"? gate. "OR gate, "A"? gate, :OR gate, :"OR gate )an be deri1ed +rom these three basi) gates. "OR and "A"? gates are )alled uni1ersal gates be)ause any )ombinational )ir)uit is possible using "OR or "A"? gates. Pra)ti)e di++erent -uestions based on logi) gates.

S1"#) A3+(e# 8*e+)-"3+ ( &a#;+'


42. Drite the e-ui1alent Boolean @3pression +or the +ollo*ing #ogi) Cir)uit. P 4

Ans : B ; P, 4 < M ; PZ 9 4 < . ; P 9 4Z < 46. Drite the e-ui1alent Boolean @3pression +or the +ollo*ing #ogi) Cir)uit. % V

Ans:

B ; % , V < M %Z . V 9 % . VZ : > ( A I C ' 7 ( A I B ' 7 ( B I C '

47. ?ra* the #ogi) Cir)uit ?iagram +or the +ollo*ing Boolean @3pression : Ans : A B Page == / 63

48. ?ra* the diagram o+ digital )ir)uit +or B;A, B, C< M AB 9 BC 9 AC using "A"?RtoR"A"? logi). Ans: B;A, B, C< M AB 9 BC 9 AC M ;AB 9 BC 9 AC< M ; ;AB< . ;BC< . ;AC< < A B B C A C B

4A. ?ra* the diagram o+ digital )ir)uit +or B;:, X, b< M ;: 9 X< ;X 9 b< ;: 9 b< using "ORRtoR"OR logi). Ans: B;:, X, b< M ;: 9 X< ;X 9 b< ;: 9 b< M ;: 9 X< ;X 9 b< ;: 9 b< M ;;: 9 X< ;X 9 b< ;: 9 b< < : X X b : b B

C"&&*3-5a)-"3 S O4e3 S"*#5e C"35e4)+


Ve#, S1"#) A3+(e# 8*e+)-"3+
42. Dhat is a net*or Q Ans : A net*or is inter)onne)ted )olle)tion o+ autonomous )omputers that )an share and e3)hange in+ormation. 46. &ention the ad1antages o+ net*or ing. Ans : (he ad1antages o+ net*or ing are Resour)e sharing, Reliability, Redu)ed )ost, Bast )ommuni)ation. 47. ?e+ine ser1er. &ention the types o+ ser1ers. Ans : A )omputer that +a)ilitates the sharing o+ data, so+t*are, and hard*are resour)es on the net*or is termed as ser1er. (he t*o types o+ ser1ers are nonRdedi)ated > dedi)ated ser1ers. 48. Dhat is "!%Q Dhat does the &AC address re+er toQ

Page =6 / 63

Ans : A "et*or !nter+a)e %nit is an interpreter that helps establish )ommuni)ation bet*een the ser1er and *or stations. (he &AC address re+ers to the physi)al address assigned by "!C manu+a)turer. 4A. Dhat are the di++erent types o+ s*it)hing te)hni-uesQ Ans : (he di++erent types o+ s*it)hing te)hni-ues are )ir)uit s*it)hing, &essage s*it)hing and pa) et s*it)hing. 4.. Dhat is a )ommuni)ation )hannelQ Gi1e e3amples o+ guided media > unguided media. Ans : Communi)ation )hannel means the )onne)ting )ables that lin 1arious *or stations. (he e3amples o+ guided media are (*istedRpair )ables, Coa3ial )ables, BibreRopti)s )ables. (he e3amples o+ unguided media are mi)ro *a1e, radio *a1e, satellite, in+rared *a1e et). 4C. ?e+ine the term Band*idth. Gi1e any one unit o+ Band*idth. Ans : Band*idth is re+erred to the 1olume o+ in+ormation per unit o+ time that a transmission medium ;li e an !nternet )onne)tion< )an handle. OR (he amount o+ data that )an be transmitted in a +i3ed amount o+ time is no*n as band*idth. Bor digital de1i)es, the band*idth is usually e3pressed in bits per se)ond;bps< or bytes per se)ond. Bor analog de1i)es, the band*idth is e3pressed in )y)les per se)ond, or $ertY ;$Y<. 4=. @3pand : $((P, B(P, (CP5!P, S#!P, PPP, "CP, GS&, (?&A, C?&A, D##, PS(". Ans : $((P : $yperte3t (rans+er Proto)ol, B(P : Bile (rans+er Proto)ol (CP5!P : (ransmission Control Proto)ol 5 !nternet Proto)ol S#!P : Serial #ine !nternet Proto)ol, PPP : Point to Point Proto)ol "CP : "et*or Control Proto)ol, GS& : Global System +or &obile (?&A : (ime ?i1ision &ultiple A))ess, C?&A : Code ?i1ision &ultiple A))ess D## : Direless #o)al #oop PS(" : Publi) S*it)hed (elephone "et*or 4E. Dhat are the di++erent types o+ net*or sQ Ans : (he di++erent types o+ net*or s are : ;a< #o)al Area "et*or ;#A"<: (his )omputer net*or is )on+ined to a lo)alised area su)h as an o++i)e or a )ampus. ;b< &etropolitan Area "et*or ;&A"<: (his is the net*or that lin s )omputer +a)ilities *ithin a )ity. ;)< Dide Area "et*or ;DA"<: (his net*or spreads o1er large distan)es li e a)ross )ountries or e1en )ontinents. 42/. Dhat do you mean by net*or topologyQ Dhat are the most popular topologiesQ Ans : (opology re+ers to the *ay in *hi)h the *or stations atta)hed to the net*or are inter)onne)ted. (he most popular topologies are Bus (opology, Ring (opology, Star (opology, (ree (opology. 422. Dhat are the ad1antages o+ @RmailQ Ans : (he ad1antages o+ @Rmail are #o* )ost, Speed, Daste redu)tion, @ase o+ use, Re)ord maintenan)e, Patien)e. 426. Dhat is DDDQ Dhat are the DDD attributesQ Ans : (he Dorld Dide Deb ;DDD< is a set o+ proto)ols that allo* you to a))ess any do)ument on the "@( through a naming system based on %R#s. (he 1arious DDD attributes are : %serR+riendly, &ultimedia do)uments, $yperte3t and $yperlin s, !ntera)ti1e, Brames. 427. Dhat is *eb bro*serQ Gi1e any t*o e3amples o+ *eb bro*sers. Ans : A *eb bro*ser is a DDD )lient that na1igates through the DDD and displays *eb pages. @3amples o+ *eb bro*sers are !nternet @3plorer, "ets)ape "a1igator and &osai). 428. ?e+ine the terms: Deb site, Deb page, $ome page, Deb portal. Ans : Deb site : A lo)ation on a net ser1er is )alled a *eb site. Deb page: A do)ument that uses $yperte3t (rans+er Proto)ol is )alled a Deb page. $ome page : (he topRle1el *eb page o+ a *ebsite is )alled $ome page. Deb portal : (he *ebsite *hi)h hosts other *ebsites is )alled Deb portal. 42A. Dhen do you pre+er :&# o1er $(&# and *hyQ Page =F / 63

Ans : (he +irst bene+it o+ :&# is that be)ause you are *riting your o*n mar up language, you are not restri)ted to a limited set o+ tags de+ined by proprietary 1endors. Rather than *aiting +or standards bodies to adopt tag set enhan)ements ;a pro)ess *hi)h )an ta e -uite some time<, or +or bro*ser )ompanies to adopt ea)h other]s standards, *ith :&#, you )an )reate your o*n set o+ tags at your o*n pa)e. 42.. Compare authorisation *ith authenti)ation. Ans : Authorisation determines *hether the ser1i)e pro1ider has granted a))ess to the *eb ser1i)e to the re-uestor. Authorisation is per+ormed by as ing the user a legal login id. Authenti)ation ensures that ea)h entity in1ol1ed in using a *eb ser1i)e is *hat a)tually )laims to be. !t is termed as pass*ord prote)tion as the authorised user is as ed to pro1ide a 1alid pass*ord. 42C. Dhat is Bire*allQ $o* +ire*all prote)ts our net*or Q Ans : (he system designed to pre1ent unauthorised a))ess to or +rom a pri1ate net*or is )alled +ire*all. !t is a de1i)e or set o+ de1i)es )on+igured to permit, deny, en)rypt, de)rypt, or pro3y all ;in and out< )omputer tra++i) bet*een di++erent se)urity domains based upon a set o+ rules and other )riteria. 42=. Dhat are )oo iesQ Ans : Coo ies are messages that a Deb ser1er transmits to a Deb bro*ser so that the Deb ser1er )an eep tra) o+ the userZs a)ti1ity on a spe)i+i) Debsite. 42E. $o* is a )ra) er di++erent +rom a ha) erQ !+ someone has ha) ed your Debsite, to *hom you lodge the ComplainQ Ans : A )ra) er is a mali)ious programmer *ho brea s into se)ure system *hereas a ha) er is more interested in gaining no*ledge about )omputer systems. !+ someone has ha) ed our Debsite the )omplaint has to be lodged *ith the Poli)e under !( A)t. 46/. Dhat is Cyberla*Q Ans : Cyberla* is a generi) term, *hi)h re+ers to all the legal and regulatory aspe)ts o+ !nternet and the Dorld Dide Deb. 462. @3pand : ;i< B#OSS ;ii< BSB ;iii< OS! ;i1< D7C Ans : ;i< B#OSS M Bree #ibre and Open Sour)e So+t*are ;ii< BSB M Bree So+t*are Boundation ;iii< OS! M Open Sour)e !nitiati1e ;i1< D7C M Dorld Dide Deb Consortium 466. Dhat is a )omputer 1irusQ Drite the basi) types o+ 1iruses. Ans : Computer 1irus is a mali)ious program that re-uires a host and is designed to ma e a system si) . Broadly three types o+ 1iruses are Bile in+e)tors, Boot Se)tor Viruses and &a)ro 1iruses. 467. ?e+ine the terms : (ro'an $orses, Dorm, Spam. Ans : (ro'an $orses : !t is )ode hidden in a program su)h as a game or spreadsheet that loo s sa+e to run but has hidden side e++e)ts. Dorm : A *orm is a program designed to repli)ate. Spam : !t re+ers to ele)troni) 'un mail or 'un ne*sgroup posting.

L"3g A3+(e# 8*e+)-"3+


42. Kno*ledge Supplement Organisation has set up its ne* )entre at &angalore +or its o++i)e and *eb based a)ti1ities. !t has 8 blo) s o+ buildings as sho*n in the diagram belo*: Block A B."5; C

B."5; D N*&9e# "2 C"&4*)e#+ Bla) A 6A Blo) B A/ Blo) C 26A Blo) ? 2/

B."5; Ce3)#e )" 5e3)#e $-+)a35e+ 9e)(ee3 6a#-"*+ 9."5;+ B Bla) A to Blo) B A/ m Blo) B to Blo) C 2A/ m Blo) C to Blo) ? 6A m Page Blo) A to Blo) ? 2C/ m =J / 63 Blo) B to Blo) ? 26A m Blo) A to Blo) C E/ m

;a< Suggest a )able layout o+ )onne)tions bet*een the blo) s. ;b< Suggest the most suitable pla)e ;i.e. blo) < to house the ser1er o+ this organisation *ith a suitable reason. ;)< Suggest the pla)ement o+ the +ollo*ing de1i)es *ith 'usti+i)ation ;i< Repeater ;ii< $ub5S*it)h ;d< (he organiYation is planning to lin its +ront o++i)e situated in the )ity in a hilly region *here )able )onne)tion is not +easible, suggest an e)onomi) *ay to )onne)t it *ith reasonably high speedQ A3+ / ;a< B."5; #ayout 2 Bloc C
k A B."5; B B."5; C B."5; D

OR
Bloc k A B."5; B B."5; D

#ayout 6
Sin)e the distan)e bet*een Blo) A and Blo) B is -uite short

;b< (he most suitable pla)e 5 blo) to house the ser1er o+ this organisation *ould be Blo) C, as this blo) )ontains the ma3imum number o+ )omputers, thus de)reasing the )abling )ost +or most o+ the )omputers as *ell as in)reasing the e++i)ien)y o+ the ma3imum )omputers in the net*or . ;)< ;i< Bor #ayout 2, sin)e the )abling distan)e bet*een Blo) s A and C, and that bet*een B and C are -uite large, so a repeater ea)h, *ould ideally be needed along their path to a1oid loss o+ signals during the )ourse o+ data +lo* in these routes. Bor layout 6, sin)e the distan)e bet*een Blo) s A and C is large so a repeater *ould ideally be pla)ed in bet*een this path ;ii< A hub5s*it)h ea)h *ould be needed in all the blo) s, to inter)onne)t the group o+ )ables +rom the di++erent )omputers in ea)h blo) . ;d< (he most e)onomi) *ay to )onne)t it *ith a reasonable high speed *ould be to use radio *a1e transmission, as they are easy to install, )an tra1el long distan)es, and penetrate buildings easily, so they are *idely used +or )ommuni)ation, both indoors and outdoors. Radio *a1es also ha1e the ad1antage o+ being omni dire)tional, *hi)h is they )an tra1el in all the dire)tions +rom the sour)e, so that the transmitter and re)ei1er do not ha1e to be )are+ully aligned physi)ally. 46. Ra1ya !ndustries has set up its ne* )enter at Ka a "agar +or its o++i)e and *eb based a)ti1ities. (he )ompany )ompound has 8 buildings as sho*n in the diagram belo*: BaYY Ra' Building Building
Harsh Building

JaYY Building Page =K / 63

Ce3)#e )" 5e3)#e $-+)a35e+ 9e)(ee3 6a#-"*+ 9*-.$-3g+ $arsh Building to Ra' Building A/ m RaY Building to BaYY Building ./ m BaYY Building to JaYY Building 6A m JaYY Building to $arsh Building 2C/ m $arsh Building to BaYY Building 26A m Ra' Building to JaYY Building E/ m

N*&9e# "2 C"&4*)e#+ $arsh Building Ra' Building BaYY Building JaYY Bulding

2A 2A/ 2A 6A

;a< Suggest a )able layout o+ )onne)tions bet*een the buildings. ;b< Suggest the most suitable pla)e ;i.e. building< to house the ser1er o+ this organisation *ith a suitable reason. ;)< Suggest the pla)ement o+ the +ollo*ing de1i)es *ith 'usti+i)ation: ;i< !nternet Conne)ting ?e1i)e5&odem ;ii< S*it)h ;e< (he organisation is planning to lin its sale )ounter situated in 1arious parts o+ the same )ity, *hi)h type o+ net*or out o+ #A", &A" or DA" *ill be +ormedQ Justi+y your ans*er. Ans : ;a< #ayout 2: BaYY Ra' Buildin Buildin g g
Harsh Buildi ng

JaYY Buildin g

#ayout 6: Sin)e the distan)e bet*een BaYY Building and JaYY Building is -uite short Ra' Buildi ng
Harsh Buildi ng

BaYY Buildi ng JaYY Buildi ng

;b< (he most suitable pla)e 5 blo) to house the ser1er o+ this organisation *ould be Ra' Building, as this blo) )ontains the ma3imum number o+ )omputers, thus de)reasing the )abling )ost +or most o+ the )omputers as *ell as in)reasing the e++i)ien)y o+ the ma3imum )omputers in the net*or . ;)< ;i< Ra' Building ;ii< !n both the layouts, a hub5s*it)h ea)h *ould be needed in all the buildings, to inter)onne)t the group o+ )ables +rom the di++erent )omputers in ea)h blo) ;d< (he type o+ net*or that shall be +ormed to lin the sale )ounters situated in 1arious parts o+ the same )ity *ould be a &A", be)ause &A" ;&etropolitan Area "et*or s< are the net*or s that lin )omputer +a)ilities *ithin a )ity. 47. "ootan Vidya &andir in OO(X is setting the net*or bet*een its di++erent *ings. (here D-+)a35e 9e)(ee3 )1e 6a#-"*+ (-3g+ a#e g-6e3 up 9e."(/ N*&9e# "2OBB!C@;O<. C"&4*)e#+ are 8 *ings named as S@"!OR;S<, &!??#@;&<, J%"!OR;J< and Ding O to Ding S 2//m Ding O 2/ Ding O to Ding & 6//m Ding S 6// Ding O to Ding J 8//m Ding & 2// Ding S to Ding & 7//m Page 6! / 63 Ding J A/ Ding S to Ding J 2//m Ding J to Ding & 8A/m

;i< Suggest a suitable (opology +or net*or ing the )omputer o+ all *ings. ;ii< "ame the *ing *here the ser1er to be installed. Justi+y your ans*er. ;iii< Suggest the pla)ement o+ $ub5S*it)h in the net*or . ;i1< &ention an e)onomi) te)hnology to pro1ide internet a))essibility to all *ings. Ans: ;i< Star or Bus or any other 1alid topology. ;ii< Ding S, be)ause ma3imum number o+ )omputers are lo)ated at Ding S. ;iii< $ub5 S*it)h in all the *ings. ;i1< Coa3ial )able5&odem5#A"5(CPR!P5?ialup5?S#5#eased #ines or any other 1alid te)hnology.

48. @ast and Dest Publi) #td. has de)ided to net*or all its o++i)es spread in +i1e buildings. G H indi)ates the total no. o+ )omputers.

Building 6 G8AH Building 2 G8/H Building A GC/H

Building 7 G22/H

Building 8 G./H

(he distan)es bet*een buildings are gi1en belo*: Bet*een 2 > 6 6/ &ts Bet*een 7 > A C/ &ts Bet*een 6 > 7 A/ &ts Bet*een 2 > A .A &ts Bet*een 7 > 8 26/ &ts Bet*een 6 > A A/ &ts Bet*een 8 > A 7/ &ts Bet*een 2 > 7 ./ &ts ;i< Suggest )able layout;s< +or )onne)ting the buildings. ;ii< Suggest the most suitable building to install the ser1er o+ this organiYation *ith a suitable reason, *ith 'usti+i)ation. ;iii< Suggest the pla)ement o+ the +ollo*ing de1i)es *ith 'usti+i)ationQ ;a< $ub5S*it)h ;b< Repeater ;i1< (he )ompany also has another o++i)e in the same )ity but at a distant lo)ation about 6AR 7/ ms a*ay. $o* )an lin be established *ith this buildingQ ;i.e. suggest the transmission medium<. Ans : ;i< Buil Buil Buil Buil Buil ding ding ding ding ding 2 8 A 6 7 ;ii< (he ser1er should be installed in building 7 as it )ontains the ma3imum number o+ )omputers, thus de)reasing the )abling )ost +or most o+ the )omputers as *ell as in)reasing the e++i)ien)y o+ the ma3imum )omputers in the net*or . ;iii< ;a< $ub5s*it)h ea)h *ould be needed in all the buildings, to inter)onne)t the group o+ )ables +rom the di++erent )omputers in ea)h building. Page 61 / 63

;b< Sin)e the )abling distan)e bet*een Building 7 and Building 8 is -uite large, so a repeater *ould ideally be needed along their path to a1oid loss o+ signals during the )ourse o+ data +lo* in these routes. ;i1< &i)ro*a1e 5 Radio*a1e 5 Satellite 4A. Standard Ban has set up its ne* )enter in !ndia +or its o++i)e and *eb based a)ti1ities. !t has +i1e buildings as sho*n in the diagram belo*:

?istan)e bet*een 1arious buildings A to B A/ &ts B to C 7/ &ts C to ? 7/ &ts ? to @ 7A &ts @ to C 8/ &ts ? to A 26/ &ts ? to B 8A &ts @ to B .A &ts

;a< Suggest a possible )able layout +or )onne)ting the buildings. ;b< Suggest the most suitable pla)e to install the ser1er o+ this organiYation. ;)< Suggest the pla)ement o+ the +ollo*ing de1i)es *ith 'usti+i)ation. ;i.< $ub5S*it)h ;ii.< Repeater ;d< (he )ompany *ants to lin its head o++i)e in aAZ building to its O++i)e in Sydney (-' Dhi)h type o+ transmission medium is appropriate +or su)h a lin Q (--' Dhat type o+ net*or this )onne)tion result intoQ

Ans: ;a< A B C ? @

OR A ? B Page 6 / 63 @ C

;b< (he ser1er should be installed in building B as it )ontains the ma3imum number o+ )omputers, thus de)reasing the )abling )ost +or most o+ the )omputers as *ell as in)reasing the e++i)ien)y o+ the ma3imum )omputers in the net*or . ;)< ;i< A hub5s*it)h ea)h *ould be needed in all the buildings, to inter)onne)t the group o+ )ables +rom the di++erent )omputers in ea)h blo) . ;ii< Sin)e the )abling distan)es bet*een buildings are not -uite large, so no repeater is re-uired. ;d< ;i< !nternet ;ii< DA"

ALL THE BEST

Prepared By: &r. Sanatan Ban'i PG( Computer S)ien)e K@"?R!XA V!?XA#AXA "ARS!"G$P%R. Guided By: R. Radha rishnan PR!"C!PA# K@"?R!XA V!?XA#AXA "ARS!"G$P%R.

Page 63 / 63

Potrebbero piacerti anche