102
What is K-map ? (1 Mark) (Ans) A Karnaugh Map is a graphical way of minimizing a boolean expression(Maxterms orMinterms). What is a Truth Table ?  (1 Mark) (Ans) A Truth Table is a table that gives all possible values of logical variables in all possible combinations, an their corresponing results. Who was George Boole ? (1 Mark) (Ans) !eorge "oole, was an #nglishman who invente "oolean algebra. $is concepts are well %nown toay in the fiel of mathematical logic. $e gave the operators &An, 'r, an ot& use to connect conitions. $is maor boo% on symbolic logic ientifie the concept of &"oolean *ogic& in &The Mathematical Analysis of *ogic& in +-. $e authore &An /nvestigation of the *aws of Thought& in +0-. $ere he escribe what the computer inustry now calls cybernetics. Use NOR gates to repr esent the boolean express ion - (X+Y)(Y+Z)(X+Z) ? ( Marks) (Ans) 1teps are23 a) 4erive the simplifie 5'1 expression b) 4raw the circuit iagram using 'T, A4 an '6 gates. c) 6eplace 'T, A4 an '6 gates with '6 gates. '6 gates are suitable for expressions in 5'1 form. Give the complement of the following Boolean expressions – a) X! " X! " X! b) #B"$)#%"&) ( Marks) (Ans) a)7omplement of 89: ; 8:9 ; 89:9 < (89: ; 8:9 ; 89:9)9  < (89:)9 . (8:9)9 . (89:9)9 as (8;:;=)9 < 89.:9.=9 < (899 ; :9) . (89; :99) . (899 ; :99) as (8.:)9 < 89;:9 < (8;:9).(89;:).(8;:) b) 7omplement of (";49)(A;79) < ((";49)(A;79) )9 < (";49)9 ; (A;79)9 < "9499 ; A9799 

Boolean Algebra Qand Answer

  • Upload
    vikas2

  • View
    230

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 1/102

What is K-map ? (1 Mark)

(Ans)A Karnaugh Map is a graphical way of minimizing a boolean expression(MaxtermsorMinterms).What is a Truth Table ?

  (1 Mark)

(Ans)A Truth Table is a table that gives all possible values of logical variables in all possiblecombinations, an their corresponing results.Who was George Boole ?

(1 Mark)

(Ans)!eorge "oole, was an #nglishman who invente "oolean algebra. $is concepts are well%nown toay in the fiel of mathematical logic. $e gave the operators &An, 'r, an ot&use to connect conitions. $is maor boo% on symbolic logic ientifie the concept of&"oolean *ogic& in &The Mathematical Analysis of *ogic& in +-. $e authore &An

/nvestigation of the *aws of Thought& in +0-. $ere he escribe what the computerinustry now calls cybernetics.Use NOR gates to represent the boolean expression - (X+Y)(Y+Z)(X+Z) ? 

( Marks)

(Ans)1teps are23a) 4erive the simplifie 5'1 expressionb) 4raw the circuit iagram using 'T, A4 an '6 gates.c) 6eplace 'T, A4 an '6 gates with '6 gates.'6 gates are suitable for expressions in 5'1 form.

Give the complement of the following Boolean expressions –

a) X! " X! " X!b) #B"$)#%"&) 

( Marks)

(Ans)a)7omplement of 89: ; 8:9 ; 89:9 < (89: ; 8:9 ; 89:9)9  < (89:)9 . (8:9)9 . (89:9)9 as (8;:;=)9 < 89.:9.=9 < (899 ; :9) . (89; :99) . (899 ; :99) as (8.:)9 < 89;:9 < (8;:9).(89;:).(8;:)

b) 7omplement of (";49)(A;79)< ((";49)(A;79) )9 

< (";49)9 ; (A;79)9 < "9499 ; A9799 

Page 2: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 2/102

< "94 ; A97'rom the following truth table( give the &anonical um*of*+ro,uctsexpression?

8 : = >? ? ? ?? ? + ?? + ? +? + + ?+ ? ? ++ ? + ?+ + ? ?+ + + + 

( Marks)

(Ans)89:=9 ; 8:9=9 ; 8:= < >

What is a Binar ,ecision ?  ( Marks)

(Ans)A binary decision is one that results in either a Yes or a No.Consider the statements below –

a) Is Mumbai an important city of India?

 b) Is the train on time?

c) Is the library open?

hese can be answered with a yes or no! and are called lo"ical statements. he result! rue or #alse is called truth $alue.

&onvert the given into &anonical .+ form -#% " &)/#& " $) 

( Marks)(Ans)@herever a literal is missing in a term, a (missing literal . negate missing literal)(A ; 7).(7 ; 4) < (A ; 7 ; 449).(AA9 ; 7 ; 4) < (A;7;4)(A;7;49)(A;7;4)(A9;7;4) as (8;:=)<(8;:)(8;=)< (A;7;4)(A;7;49)(A9;7;4)&onvert the given expression into &anonical .+ form -!/0 " X ! 

( Marks)

(Ans)@herever a literal is missing in a term, multiply it withthe (missing literal; its negatemissing literal)

:= ; 89 :< (8 ; 89):= ; 89:(= ; =9)< 8:= ; 89:= ; 89:= ; 89:=9 < 8:= ; 89:= ; 89:=9 What is a canonical expression ? 

( Marks)

(Ans)A "oolean expression that is compose of only Minterms or Maxterms is sai to be in7anonical form.Thus we can have expressions in 7anonical 1umof 5roucts form or7anonical 5rouctof1ums form.+rove using the truth table( that( X/#X"!) 1 X 

( Marks)

(Ans)ruth table is of the %!y!%.(%&y) is "i$en below ' 8 : 8;: 8.(8;:)

Page 3: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 3/102

? ? ? ?? + + ?+ ? + ++ + + +The truth table shows the two columns 8 an 8.(8;:) to be ientical.$ence, 8 < 8.(8;:) 

'rom the following truth table( give the &anonical +ro,uct*of*ums an,&anonical um*of*+ro,ucts expression?

A " 7 4 >? ? ? ? +? ? ? + ?? ? + ? +? ? + + ?? + ? ? ?? + ? + +? + + ? ?? + + + ++ ? ? ? +

+ ? ? + ?+ ? + ? ++ ? + + ?+ + ? ? ?+ + ? + ++ + + ? ?+ + + + +

( Marks)

(Ans)

utput is "i$en below 'A " 7 4 > Minterms Maxterms

? ? ? ? + A9"97949  ? ? ? + ? A;";7;49  ? ? + ? + A9"9749  ? ? + + ? A;";79;49  ? + ? ? ? A;"9;7;4? + ? + + A9"794? + + ? ? A;"9;79;4? + + + + A9"74+ ? ? ? + A"97949  + ? ? + ? A9;";7;49  + ? + ? + A"9749  

+ ? + + ? A9;";79;49  + + ? ? ? A9;"9;7;4+ + ? + + A"794+ + + ? ? A9;"9;79;4+ + + + + A"747anonical 1umof5roucts expression as sum of minterms< A9"97949 ; A9"9749 ; A9"794 ; A9"74 ; A"97949 ; A"9749 ; A"794 ; A"747anonical 5rouctof1ums expression as sum of maxterms<(A;";7;49).( A;";79;49).( A;"9;7;4).( A;"9;79;4).( A9;";7;49).( A9;";79;49).( A9;"9;7;4).( A9;"9;79;4).$efine 2interms an, 2axterms ?

( Marks)

Page 4: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 4/102

(Ans)A 2interm is a prouct of all the literals (inputs) into the system.#ach literal may bewith or without the bar (i.e. complemente).A 2axterm is a sum of all the literals (inputs) into the system.The literals may be withor without the bar (i.e. complemente).3ow is Boolean %lgebra ,ifferent from the regular %lgebra that ou stu, in2athematics ?

( Marks)

(Ans)/n "oolean algebra, ? an + (>alse an True) are the only values allowe.The meaningan application of logical aition (;), logical multiplication (.), is very ifferent fromaition an multiplication in orinary algebra. 'ther operators li%e B, C are not use.The basic postulates on which boolean expressions are base are not applicable inorinary algebra.There are certain laws (li%e /nempotence law an Absorption law) antheorems that li%e, 4e Morgan9s theorems that apply to boolean algebra.$efine X4.5 Gate ?

( Marks)

(Ans)he *N+ ,ate is an lo"ically e-ui$alent to an in$ertor *+ ,ate i.e. *+ a"te followed up by

a N ,ate(in$entor). he *N+ ,ate roduces / (hi"h) utput when the input combination

has e$en number of one /0s.What Boolean %lgebra ? 

( Marks)

(Ans)"oolean Algebra is a branch of mathematics, somewhat similar to, but ifferent fromorinary algebra. /t is a system of symbols an operators that apply to logical problems./t is an algebra in which elements can ta%e only one of two values ? or + that representfalse or true, an are subect to operations base on A4, '6 an 'T.What are logical operations ? 

( Marks)(Ans)*ogical operations involve the use of three operators 3 'T, A4 an '6. 'T simplenegates a value. /t uses one operan. #xampleD a) ot True (which means, >alse as Truean >alse are the only possible values) b) Knowing #nglish A4 >rench (means someonewho %nows both #nglish A4 >rench) c) Knowing #nglish '6 >rench (means someonewho %nows either #nglish or >rench).$efine Tautolog an, 'allac ? 

( Marks)

(Ans)A Tautolog is any logical statement that always results in True. #xample, thestatement 3 EMalaria is angerousF is always true.A 'allac is a statement that always results in >alse. #xample 3 EToxic waste is easy tostoreF D is always false.What is the +rinciple of $ualit ? 

( Marks)

(Ans)Accoring to the 5rinciple of 4uality, the ual of any statement in "oolean algebra isobtaine by interchanging ; an . an simultaneously interDchanging ? an + in thestatement. /n this way, starting with a boolean expression, we get another booleanexpression.'or example2(i) The ual of the statement (x . + )(? ; xG) < ? is (x ; ?)(+ . xG) < +(ii) The ual of the statement(x ; y)(y ; z) < x.z ; y is x.y ; y.z < (x ; z).y

Page 5: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 5/102

Wh are 4%4$ an, 4.5 calle, universal gates ? ( Marks)

(Ans)7ircuits using A4 an '6 are popular as they are easier to esign an thereforecheaper.>unctions of other gates can easily be implemente using A4 an '6gates.>or this reason they are calle universal gates.$esign a circuit with 6 inputs that gives a high output onl when the number ofhigh inputs is even ? 

(! Marks)

(Ans)

Truth Table for H inputs, 8, : an = is D  8 : = >? ? ? ?? ? + ?? + ? ?? + + +

+ ? ? ?+ ? + ++ + ? ++ + + ?

> < mH ; m0 ; mI

Mar%ing the minterms in the Karnaugh map, we get the simplifie 1'5 expression D> < 89:= ; 8:9= ; 8:=9 

tate $e 2organs Theorems/ +rove the first theorem? (" Marks)

(Ans)4e Morgan9s two theorems are2

/ 1 an

The first theorem says that when the sum('6) of two variables is inverte, this is thesame as inverting each variable iniviually an then A4ing these inverte variables.

1

Page 6: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 6/102

Accoring to 7omplementarity *aw

(+) an

(J)

The first of these laws states that when a logical variable (or expression) is ae to itscomplement, the output is +.The secon law states that when a logical variable (or expression) is multiplie with itscomplement, the output is ?.*et us assume A < 8 ; : where A, 8 an : are logical variables.

Accoring to the 7omplimentarity *aw, an

/f A < 8 ; :, then, A< 8 ; : ,

; which accoring to 4e Morgan9s first theorem is eual to 8.: 1o, we will try to prove

that

(8 ; :) ; 8 . : < +an (8 ; :) . 8 : < ?

5roving (8 ; :) ; 8 . : < +

5roving (8 ; :).8 : < ?

Thus 4e Morgan9s first theorem is prove.

Thus 4e Morgan9s first theorem is prove.

$escribe the 7ogical .perators in Boolean %lgebra? (" Marks)

(Ans)Mathematical operators li%e ;, D, B, C are use with variables to form algebraicexpressions, li%e, a ; b 3 cC.

Page 7: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 7/102

'T, A4 an '6 are logical operators use to form logical expressions, li%e, 'T>rench, #nglish A4 !erman, #nglish '6 !erman.4.T operatorot >rench D the only specification is that the person shoul not be >rench.

The Lenn iagram below shows 8 as the set of >rench persons, the rest of the area,leaving 8, represents those other than >rench, i.e. 8. Thus, the bar negates 8, or stansfor the complement of 8.

Truth Table for 4.T operator'T operates on a single variable hence is a unary operator.

The %4$ operator

#nglish A4 !erman D our search is narrowe, as we can consier only those who %now#nglish as well as !erman. The logical A4 operator is represente by . an is callelogical multiplication. The Lenn iagram shows the rectangle as all the available people,> is #nglish spea%ers, $ is !erman spea%ers an the overlapping part is people who%now both. A4 allows us to pic% up only from the overlappe part.

Truth Table for %4$ operatorThe truth table shows that if 8 an : both, are +, the result of 8.: is +.

The .5 operator

#nglish '6 !erman D our search is broaene, as we can consier people who %now#nglish, those who %now !erman, or both. The logical '6 operator is represente by ;an is calle logical aition. The Lenn iagram shows the rectangle as all the availablepeople, > is #nglish spea%ers, $ is !erman spea%ers an the overlapping part is peoplewho %now both. '6 allows us to pic% up from any of the areas covere by > an $.

Truth Table for .5 operator

8

8? ++ ?

8 : 8 . :? ? ?? + ?+ ? ?+ + +

Page 8: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 8/102

The truth table shows that if 8 or : is +, the result of 8 ; : is +.

What is a logic gate? $escribe the 6 basic logic gates use, in ,igital circuits ?  (" Marks)

(Ans)*ogic gates are igital circuits constructe from ioes, transistors, an resistors that

prouce an output, from some given inputs.4.T gatesD/t is also calle /nverter.The 'T operation can be performe on a singleinput. >or example, if the variable A is subecte to the 'T operation, the result x canbe expresse as8 < where represents the 'Toperation.

The truth table of the 4.T operation is as follows2

%4$ gatesDThe A4 gate uses J or more inputs to prouce asingle output.Theresultantoutput + occurs only then all of the inputs are +.

Truth Table for 8 input %4$ Gate

8 : 8 ; :? ? ?? + ++ ? ++ + +

A 8 <

? +

+ ?

A " 8 < A . "

? ? ?

? + ?

+ ? ?

+ + +

Page 9: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 9/102

The output A." can be written as A", without the N.9 symbol.

.5 gatesDThe '6 gate uses J or more inputs to prouce a single output. The resultprouce is + when any of the inputs is +.The result ? is prouce only when all theinput variables are ?.

Truth Table for .5 Gate 

Computer Science[C++] For Class 12

Classes And Objects

What are static ,ata members? (1 Mark)

(Ans)1tatic ata members are class variables. 'nly one copy of the static ata member ismaintaine an this is share by all the obects. They are visible only within the class buttheir lifetime is the entire program. They can be use in all member functions.What are static member functions? 

(1 Mark)

(Ans)A static member function is a member function that can access only static atamembers. /t is calle using the class name an not with the obect as is the case withother member functions.3ow is struct ,ifferent from class in &""? 

(1 Mark)

A " 8 < A ; "? ? ?

? + +

+ ? +

+ + +

Page 10: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 10/102

(Ans)Members of a class are private by efault while members of a structure are public byefault.What is a frien, function? 

(1 Mark)

(Ans)/t is a non member function that can access private ata members. $owever, this goesagainst one of the basic principles of the class, that only public member functions canaccess private members. $ence frien functions shoul be sparingly use.What are ob9ects? 

(1 Mark)

(Ans)An obect is an instance of a class. >or a class that has been efine, obects can becreate as variables of that class. #ach obect will have a set of ata members efine inthe class.What is the ,ifference between private an, protecte, members of a class?

(1 Mark)

(Ans)The only ifference is that private members cannot be inherite while protectemembers can be.What is nesting of member functions?

(1 Mark)

(Ans)@hen a member function of a class calls another member function, it is %nown asnesting of member functions.3ow are public members ,ifferent from private members of a class?

(1 Mark)

(Ans)5ublic members can be calle in outsie functions, using the obect. 5rivate members

can be calle or use only by other members of the class. Also, public members can beinherite while private members cannot be.What is a neste, class? 

(1 Mark)

(Ans)A class eclare insie another class is a neste class.What ,o ou un,erstan, b the term containership? 

(1 Mark)

(Ans)7ontainership refers to an obect of a class being a member of another class.When shoul, we ma:e a function inline? 

(1 Mark)(Ans)Ma%e only small functions inline. /t must fulfill certain other conitions D it must not havea loop, switch or goto if it returns a value, it must not have static variables an must notbe recursive.What constitutes the public interface of the class? 

(1 Mark)

(Ans)5ublic members, that can be calle in any function (using the obect) constitute thepublic interface of the class.Write a statement ,eclaring an arra name, B: of ;< ob9ects of class Boo:/ 

(1 Mark)

(Ans)"oo% "%O+0PQ

Page 11: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 11/102

tate the a,vantages an, ,isa,vantages of inline functions/ ( Marks)

(Ans)/n case of inline functions, the function call is replace by the function coe. Thus theoverheas involve in calling the function are avoie an the inline function runs a littlefaster. The isavantage is that if the function is calle +? times, its coe will be insertein +? places, ma%ing the program longer.3ow are member functions ,ifferent from non member functions? 

( Marks)

(Ans)+. Member functions can access private an protecte members of the class while nonmember functions have access to only public members an that too, through theobects. J. Member functions have no scope outsie the class while non member functions havescope outsie the class. 3ow is memor allocate, for a class an, its ob9ects? 

( Marks)

(Ans)The class efinition gives the ata members an member functions. "ase on the classefinition, obects are eclare. #ach obect will have its own set of ata members butthere will be one set of functions accesse by all the obects. 1o, when the class isefine, memory is allocate for member functions an they are store there. @henobects are eclare, separate memory space is allocate for each obect, sufficient toaccommoate all its ata members.&an a member function an, a non member function be given the same name?upport our answer with an explanation/ 

( Marks)

(Ans):es they can.

The scope of a member function is restricte to the class. /t may be calle by othermembers of the class or if calle in a non member function, it is lin%e with an obect ofthe class.on member functions have no such restrictions. /f efine globally, they have programscope an can be calle from any function. /f efine insie a function, they have scopelocal to that function.

$efine a class Boo: with the following specifications =+rivate members –

boo:*co,e integer

  title 8> characters

  author 8> characters+rice integer

+ublic members –getboo:#) – function that accepts boo: ,etails

  buboo:#) – function that accepts no/ of copies to bu an, ,isplastotal amount to be pai,/

'unction ,efinitions must be given/ 

( Marks)

(Ans)

class "oo%R

Page 12: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 12/102

int boo%coeQchar titleOJ?PQchar authorOJ?PQint 5riceQpublic2voi getboo%()R

cout SS &n#nter "oo% 7oe 2 &Qcin boo%coeQcout SS &n"oo% Title 2 &Qcin.getline(title,J?)Qcout SS &n"oo% Author 2 &Qcin.getline(author,J?)Qcout SS &n5rice 2 &Qcin 5riceQUvoi buyboo%()Rint cQcout SS &n$ow many copies to buyV &Q

cin cQcout SS &n5ay 6s.&SS priceCcQU

UQ

7oo: at the following co,e fragment –int a(b

  class %@int x  float

  char A  voi, initval#voi,)@  x1>  1>/>  A1>  C

public=  int a

  int b  voi, sums#int n)@  coutDDEum;1EDD #x " )Fn  coutDDEum81EDD #a"b)Fn

Cvoi, fn#int i( float 9( char :)

  C  voi, %==fn#int i(float 9(char :)@

  x1i19A1:  C

% ob  voi, ,isp#voi,)@  int a18;>  coutDD a  C 

Which variables can be accesse, b the following functions?  sums#)( fn#)( ,isp#)

Page 13: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 13/102

( Marks)

(Ans)

sums() can access A22x, A22y, A22z, A22a, A22b, 22a, 22b  and passed $ariable nfn() can access A22x, A22y, A22z, A22a, A22b, 22a, 22bisp() can access 22a, 22b, local variable a, A22a an A22b through ob.

$efine a class to store ban: account ,etails of customers base, on thespecifications given =

$ata members= %ccount 4umber integer

  4ame of %ccount 3ol,er 8> characters  Tpe of %ccount ; character # - avings & - &urrent)

  Balance float 

2ember 'unctions =  init#) - to give ,ata members initial values  ,isp#) - to ,ispla account ,etails  ,eposit#) - to ,eposit mone

  ,raw#) - to with,raw mone( leaving at least 5s/;>>> as balance  %ll functions must be ,efine,/

 

( Marks)

(Ans)class A7R int accnoQchar nameOJ?PQchar typeQfloat balanceQpublic2

voi init()RcoutSS&n#nter Account o.&QcinaccnoQcoutSS&name of Account $oler 2 &Qcin.getline(name,J?)QcoutSS&nType < 1 or 7 &QcintypeQtype<toupper(type)QcoutSS&n"alance 2 &QcinbalanceQUvoi isp()RcoutSS&nAccount o.&SS accnoQcoutSS&name of Account $oler 2 &SS nameQcoutSS&nType < &SS typeQcoutSS&n"alance 2 &SS balanceQUvoi eposit(float )Rbalance < balance ; QcoutSS&n"alance Wpate&QUvoi raw(float )Rif(balance D <+???)R balance<balanceDQcoutSS&n"alance Wpate&Q

Uelse

Page 14: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 14/102

coutSS&*eaves insufficient balance&QUUQ

,entif errors in the following co,e =

class X@int a  static int b  public=  voi, f;#voi,)@  a1;>  b18>  C  static voi, f8#voi,)@

  coutDD aDD bC

  C  X ob

  voi, main#)@  ob/f;#)  ob/f8#)  C

( Marks)

(Ans)>unction fJ() is a static member function. /t is accessing a, which is a non static atamember. 1econly, static ata member b is not efine outsie the class.3ow ,oes a class implement $ata 3i,ing( $ata %bstraction an, Hncapsulation? 

(! Marks)

(Ans)A class bins together ata an functions that access it thus enforcing encapsulation.The class represents essential features of the obect, thus implementing ataabstraction./n the class, members are classifie as private, protecte an public. Accessibility of themembers epens on which category they are uner. 5rivate an protecte memberscan only be accesse by public members of the class, thus enforcing ata hiing.$escribe the access specifiers of a class in brief/ 

(! Marks)

(Ans)There are three access specifiers D private, protecte an public. Members eclare as private or protecte can only be accesse by other members of theclass. They are thus hien from the outsie worl.Members eclare as public can be accesse even outsie the class, in nonDmemberfunctions, but only by using an obect of the class.% ,ining hall can accommo,ate onl <> guests/ $efine a class to store seatnumber an, name of the guests who are seate, on first come first seate, basis/$efine functions to ,ispla ,etails of an seat number an, to ,ispla the

current seating situation/ Write a program to show the wor:ing of this class/ (! Marks)

(Ans)Xinclue S iostream.h Xinclue S ctype.h class 4$Rint seatQchar nameOJ?PQstatic int ta%enQpublic2voi getata()R

Page 15: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 15/102

ta%en;;QcoutSS&n1eat umber < &SS ta%enQcoutSS&name < &Qcin.getline(name,J?)Qseat<ta%enQU

static voi status()RcoutSS&nTotal 1eats < 0?&QcoutSS&n1eats Ta%en < &SS ta%enQcoutSS&n Available < &SS 0?Dta%enQUvoi isp( )RcoutSS&n1eat o. < &SS seatQcoutSS&name < &SS nameQUUQ4$ obO0?PQint 4$22ta%enQ

voi main()Rint i,sQchar mo<G:G,cQWhen can a function not be inline? 

(# Marks)

(Ans)1ome situations where efining a function as inline will not wor% 3+. /f the function returns a value an contains a loop, switch or goto statement.J. /f the function oes not return a value an contains a return statement.H. /f the function contains static variables.-. /f the function is recursive.Constructors And Destructors

What is a constructor ?

(1 Mark)

(Ans)A constructor is a member function of a class that is invo%e automatically when anobect of that class is create. /t has the same name as the class an initializes theobect with legal initial values.What purpose ,oes a constructor serve? 

(1 Mark)

(Ans)The constructor provies some vali initial values to the obect create.What is a ,efault constructor? 

(1 Mark)

(Ans)A constructor that oes not accept any argument is a efault constructor.#xample2 for a class calle 1TW4#T, the following is the efault constructorD1TW4#T( ) Rrno<?QUWhat are parameteriAe, constructors? 

(1 Mark)

(Ans)A constructor that ta%es arguments is a parameterize constructor.#xample 2class A"7R

int aQint bQpublic2

Page 16: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 16/102

A"7( int x, int y)Ra<xQ b<yQU BB parameterizes constructorYY..UQvoi main()RA"7 obJ(J,H)Q BB parameterize constructor invo%eYY..

UWhat is a temporar instance? 

(1 Mark)

(Ans)A temporary instance of a class is an unname obect which is short live. /t remains inmemory as long as the statement efining it is execute an then is automaticallyestroye.

What is meant b the term cop initialiAation? (1 Mark)

(Ans)/nitializing obects through the copy constructor is calle copy initialization. /n the example, for a class A"7, the statement below creates obect obJ initialize withthe obect ob.A"7 obJ(ob)Q BB copy constructor calleWhat are ,estructors? 

(1 Mark)

(Ans)4estructors are special member functions that are invo%e automatically when an obectis to be estroye. The name of the estructor is the same as the class, precee by a Zcharacter.3ow is the constructor ,ifferent from other member functions?

(1 Mark)(Ans)The constructor is a special function of the class. /t stans out in many ways. >irstly, it isthe one invo%e automatically when the obect is create./t has the same name as theclass. /t cannot return a value. /t cannot be inherite. /t cannot be static. /f noconstructor has been efine for a class, the compiler creates one. 'ther memberfunctions o not have these features.Hxplain constructor overloa,ing with the help of examples/ 

( Marks)

(Ans)$erloaded function refer to the same function performin" different acti$ities dependin" on the $alues passed toit. Constructor too is a function! and it can be o$erloaded. Multiple constructors can be defined and different

number and types of $alues can be sent for initiali2ation. 3%ample 'class A4int a5int b5

 public'A ( ) 4a675 b6758 99default constructor A( int %! int y)4a6%5b6y5899constructor with 1 ar"umentsA(int %)4a6%5 b61:%58 99constructor with / ar"uments85$oid main()4

A ob5 99 will in$o;e the default constructor A ob1(1!<)5 99 constructor with two ar"uments in$o;edA ob<(=)5 99 constructor with one ar"uments in$o;ed

U What are cop constructors? 

Page 17: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 17/102

( Marks)

(Ans)The 7opy 7onstructor is use to initialize an obect using another obect. /t has the formclassname (classname [ ).Wh is the ob9ect passe, b reference to a cop constructor? 

( Marks)(Ans)This is because, when an argument is passe by value, its copy is mae. To ma%e a copyof an obect, the copy constructor is calle. Thus, it calls itself again. /n fact, it calls itself over an over again until the compiler is out of memory. 1o, the obect is passe byreference which creates no copies.What will be the or,er of invocation of constructors for the following co,e?class X@IIICclass ! @ I// Cclass 0 @ I//  public=  0 # )

  X ox  ! oC

voi, main#) @  X x;

  ! ;  0 A;C

( Marks)

(Ans)The orer of invocation will be 3 +. 8 22 8( ) for x+

J. : 22 :( ) for y+H. 8 22 8( ) for ox in z+-. : 22 :( ) for oy in z+0. = 22 =( ) for z+

What is meant b ,namic initialiAation of ob9ects?

( Marks)

(Ans)4ynamic initialization means that initial values for the obect may be provie atruntime. /n the example, values to be passe as arguments are receive at run time. class A"7 R int aQ

int bQpublic2A"7( int x, int y) R a<xQ b<yQ U..UQvoi main( )Rint x, yQcoutSSF#nter integer values for x an y EQcinxyQA"7 ob ( x, y)QYUWh are ,estructors nee,e,?

  ( Marks)

Page 18: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 18/102

(Ans)An obect create in a program must be estroye when it is no more neee. This tas%is carrie out by the estructor. /t einitializes the obect an eallocates all allocateresources.

3ow are the two statements given below ,ifferent?hape s;#;>(<) JJstatement ;

  hape s; 1 hape#;>(<) JJ statement 8

( Marks)

(Ans)/n both the statements, an obect, s+ is create. /n statement +, the constructor is calleimplicitly. /n statement J, the constructor is calle explicitly, by name.

3ow man times is the cop constructor calle, in the following co,e( usingclass % =

% func#% x)@

  % #x)  % A 1   return AC voi, main# ) @  % a  % b 1 func#a)

  % c 1 func#b)C

( Marks)(Ans)The copy constructor is calle times.+. obect a passe by value to func( )J. obect y initialize in func ( ) with xH. obect z initialize in func ( ) with y-. obect z returne0. obect b passe by value to func( )I. obect y initialize in func ( ) with x. obect z initialize in func ( ) with y. obect z returne

&lass +ro, has been ,efine,/ The statement below gives an error( what coul,

be the reason?+ro, ob JJerror generate,

( Marks)

(Ans)Assuming this statement is in an outsie function, if the constructor is efine unerprivate or protecte , the statement will generate an error. Another reason coul be, ifthe constructor is uner public but the estructor has been efine uner private orprotecte.What con,itions must a function satisf in or,er to create ob9ects of a class? 

( Marks)

(Ans)A function can create obects of a class if it can access the constructor an estructor.

Page 19: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 19/102

When the compiler can provi,e a constructor( wh shoul, we ,efine it? ( Marks)

(Ans)The compiler provies its own values, which are legal. @hen we efine the constructor,we can provie values accoring to our reuirement.Lse an example an, show how a constructor with ,efault values wor:s li:e the,efault constructor/ 

(! Marks)

(Ans)The efault constructor ta%es no arguments. $owever, the class can ha$e a constructor withdefault ar"uments too. In case $alues are not pro$ided while creatin" the ob>ect! the constructor with default$alues can pro$ide $alues.In the e%ample below! we see how the constructor with default ar"uments can wor; >ust li;e the defaultconstructorclass AC4

int a5int b5 public'

$oid show()4cout@@A 6 @@ a@@ 6 @@ b58

AC( )4a6/1<5b6<B5 8 99default constructor AC(int %6! int y6DD)4a6%5 b6y58 99 constructor with default ar"uments.85$oid main()4AC ob5 99default constructor called ? or one with default ar"uments?ob.show()5

8

$ere, the obect ob is being create an no arguments are passe, so the efaultconstructor shoul be invo%e. $owever, the constructor with efault values can also becalle as it provies values for missing arguments. /n this example, to create obect ob,both efault an the constructor with efault values can be calle. This is actually anambiguous situation an shoul be avoie.

$escribe the two was the constructor can be calle,/ (! Marks)

(Ans)The constructor may be calle implicitly or explicitly. mplicit &all to the &onstructor 3 here, the constructor is not calle by name but isinvo%e automatically. /t initializes the obect with the passe values.#xample 2 for a class name />', the statement below will implicitly call theconstructor./>' 8(+J,9A9)QHxplicit &all to the &onstructor 3 here, the constructor is calle by name to initializethe obect with the passe values.#xample 2 for a class name />', the statement below will explicitly call theconstructor./>' :</>'(+J,9A9)Q$ere, the obect create is : an the constructor is explicitly calle to initialize it with thevalues +J an NA9.3ow will it affect the ob9ects when the constructor is ,eclare, un,er private?un,er public? 

(! Marks)

(Ans)The constructor obeys all access rules. @hen eclare uner private, it will be available

Page 20: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 20/102

to other members of the class only. Thus, member functions can eclare obects. Thesame also applies to frien functions as they can also access private members of a class.@hen they are eclare uner public, they can be accesse in outsie functions too.$ence, obects can be eclare in outsie functions when the constructor can beaccesse.

What are the situations when a cop constructor is calle,?

(! Marks)

(Ans)+. @hen an obect is create an initialize with another obect, as shown in theexample below, />' :(8)Q$ere, class is />', : is the obect being create an 8 is the obect being use toinitialize it.J. @hen an obect is passe by value to a function.

func(ob)Q D function call, an obect being passeH. @hen a function returns an obect.A"7 funcJ( )Q D prototype of a function that returns an obect of class A"7ob < funcJ( )QD function callWhat are the main characteristics of ,estructors? 

(! Marks)

(Ans)4estructors too are special member functions. Their characteristics are 3+. They have the same name as the class, precee by the NZ9 character (tile).J. They are invo%e automatically when obects are estroye.H. o return type is specifie for estructors-. 4estructors obey the access rules.0. They cannot be static.I. They cannot be inherite.. Arguments cannot be passe to a estructor.. /t is not possible to ta%e the aress of a estructor.\. An obect cannot be member of a union if the class has a estructor.+?. Member functions can be calle from insie the estructor.++. The compiler creates efault estructors wherever neee.+J. /f the class has a estructor, the obects are eDinitialize before they go out ofscope.tate the important characteristics of constructors? 

(# Marks)

(Ans)Constructors are special member functions. heir characteristics are –/. hey ha$e the same name as the class.

1. hey are in$o;ed automatically when ob>ects are created.<. No return type is specified for constructorsB. Constructors obey the access rules. nly functions that ha$e access to the constructor can create ob>ects of

that class. Eo! if the constructor is pri$ate or protected! it is a$ailable only to members or friends. If it is public! it can be used in outside functions.

. hey cannot be static.

=. hey cannot be inherited but the deri$ed class can call the base class constructor.F. hey can ha$e default ar"uments.D. It is not possible to ta;e the address of a constructor.G. An ob>ect cannot be member of a union if the class has a constructor./7. Member functions can be called from inside the constructor.//. he compiler creates default constructor and copy constructor where$er needed.

/1. If the class has a constructor! the ob>ects are initiali2ed before use./<.. Normally the constructor is called implicitly but it can be called e%plicitly too.

Page 21: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 21/102

Inheritance: !tendin" Classes

What is inheritance ? (1 Mark)

(Ans)/nheritance is an important concept of 'bect 'riente 5rogramming. /t is the capabilityof one class to inherit properties from another class.What is the a,vantage of inheritance? 

(1 Mark)

(Ans)'ne of the main avantages is coe reusability. 'nce a class has been satisfactorilyefine, it can be use in other classes without ma%ing changes. /t represents real worlentities very effectively 3 class 5ersoncan have features that can be inherite by#mployee as well as 1tuent.What ,o ou un,erstan, b base class an, ,erive, class #or sub class) ? 

(1 Mark)

(Ans)

An existing class can be use to erive a new class. The existing class, whose propertiesare inherite is the base class an the class that inherits features is the erive class.% class inherits a function that has the same name an, arguments as one of its

own member functions/ The ob9ect calls the function an, there is no scoperesolution operator given/ Which of these two functions will be calle,? 

(1 Mark)

(Ans)The member function of its own class will be calle.Which members are not inherite, even if the are public members of a class? 

(1 Mark)

(Ans)he Constructor and Hestructor are not inherited.

What is %bstract &lass? (1 Mark)

(Ans)@hen a class is use only to erive other classes it is an abstract class. o obects arecreate for this class. /n the example below, A is an abstract class.class A 

R Y.

public 2

int aQUQ

class " 2 public A BB inherit public member a from A

R Y.

public 2

int bQ

UQ

Page 22: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 22/102

voi main( )R

" ob+Q

YYY

U

What is the ,ifference between private an, protecte, members? (1 Mark)

(Ans)5rivate members are not inherite but can be inirectly accesse in the erive class byinherite members of the same class. 5rotecte members can be inherite an accesse

 ust li%e other protecte members of the erive class.4ame the ,ifferent forms of nheritance/ 

( Marks)

(Ans)

The ifferent forms of inheritance are 1ingle, Multiple, $ierarchical, Multilevel an$ybri.

($%) What ,o ou un,erstan, b visibilit mo,es?

( Marks)

(Ans)Lisibility moes are use to specify how the features of the base class are inherite intothe erive class. The three visibility moes are public private an protecte. Theinheritable base class members are place uner the access specifiers in the eriveclass epening on the visibility moe an its own access specifier.

&an private members be inherite,? f es( how/ f no( how can the be

accesse, in the ,erive, class? ( Marks)

(Ans)5rivate members cannot be inherite. $owever, other member functions that access theprivate members can be inherite. Thus, private members can be inirectly accessethrough inherite functions.

($%) What is &ontainership? 3ow is it ,ifferent from nheritance? ( Marks)

(Ans)@hen a class contains an obect of another class as a member, it is a case ofcontainership. 7ontainership is very ifferent from /nheritance. /n /nheritance, we have aclass that has its own features in aition to some features of another class. Through7ontainership we can create an obect that contains an obect within it.

($%) +rivate members cannot be inherite,/ What can be ,one to ma:e these

members inheritable? ( Marks)

(Ans)To inherit private members we have to change their accessibility i.e. either ma%e thempublic members or ma%e them protecte members.

Page 23: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 23/102

5ublic members are reaily inherite an can be accesse by all 3 outsie functions too.This may eliminate the avantages of ata hiing.Ma%ing them into protecte members will allow them to be inherite while retaining thefeature of security.The visibility moe uner which they are erive ecies whether they can be inheritefurther. 1o, uner public or protecte visibility moe they can be inherite further but

uner private visibility moe, they will again become private members.

($%) What is a 4este, &lass? 3ow is it ,ifferent from nheritance? 

( Marks)

(Ans)@hen a class is efine insie another class, it is a neste class. This is ifferent from/nheritance. Members of the neste class can access its other members an obect of theneste class can access its public members. 1imilarly, members of the outsie class canaccess other members an the obect can access public members. @e cannot say thatmembers of one class become members of another class. 5ublic members of the neste

class can still only be calle by its obects. /f they were inherite, obects of the eriveclass woul be able to call them too.What is meant b virtual base class? 

( Marks)

(Ans)

hen a class inherits from multiple base classes! it can lead to an ambi"uous situation. his

is specially when the base classes themsel$es are deri$ed from a common base class

As shown in the figure, A is a base class from which two classes are erive, " an 7.These further act as base classes for 4.

*et us now try to visualize the problem that can arise. 4 wants to access a functionwhich is inherite from base class A, into " an 7. 'bviously, since 4 is inheriting fromboth " an 7, it receives two copies of the members they inherite from their base classA.

Page 24: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 24/102

@hen this member is accesse, the compiler faces an ambiguous situation, which can beresolve in two ways.

'ne way out is to call the member with the class name i.e. " 22 member or 7 22 memberso that it is clear which member is being accesse.

The other way is to ma%e the common base class (here, A) virtual, as shown in theexample below.

class A

R Y.

public 2

int aQ

UQ

class " 2 public virtual A

R Y.

public 2

int bQ

UQclass 7 2 public virtual A

R Y.

public 2

int cQ

UQ

class 4 2 public ", public 7

R Y.

public 2

int cQ

UQ

ow, because of the %eywor virtual, classes " an 7 will share a single common base

class member a. Thus there will be no ambiguity when accessing it.

Page 25: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 25/102

&lass % inherits from &lass B/ $efine a constructor for class % that ta:es 6integer arguments( passes on two of these to the base class constructor an,

initialiAes its own member x with the thir, one/ ( Marks)

(Ans)class A 2 public "R int xQ 

Y..

public2

A( int a, int b, int c) 2 "(a, b)

R x < cQ U

YY..

UQ

What is the ,ifference between the two ,erive, classes below ?a) class ; = private +

b) class 8 = public + ( Marks)

(Ans)/n the first statement, class 5 is inherite in private moe. Thus inheritable public anprotecte members of 5 become private members of 1+. 5rivate members can beaccesse only by other members or friens of the class, not by the obects./n the secon statement, class 5 is inherite in public moe. Thus inheritable public anprotecte members of 5 become members of 1J, with the same accessibility. 5rotectemembers can be accesse only by other members but the public members will beaccessible by the obects.3ow ,o visibilit mo,e an, access specifier ,etermine the access of inherite,members?

(! Marks)

(Ans)

he $isibility mode specifies whether features of the base class are deri$ed publicly! pri$ately

or in protected mode. his controls the access specifiers of the inherited members in the

deri$ed class.

5ublic visibility moe 3 /nheritable public members of base class become public membersof the erive class an protecte members of base class become protecte members ofthe erive class. 5rivate members are not inherite.

Page 26: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 26/102

5rotecte visibility moe D /nheritable public members an protecte members of baseclass become protecte members of the erive class. 5rivate members are notinherite.

Page 27: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 27/102

5rivate visibility moe D /nheritable public members an protecte members of base

Page 28: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 28/102

class become private members of the erive class. 5rivate members are not inherite.

$escribe the ,ifferent forms of nheritance in brief/ (! Marks)

(Ans)

he different forms of inheritance are

1ingle 3 @hen a subclass inherits from only one base class.

Page 29: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 29/102

The syntax in single inheritance is 3

class eriveclassname 2 visibilitymoe baseclassname

R

YYYYY. BB members of the erive classU

Multiple D @hen a subclass inherits from multiple base classes.

Page 30: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 30/102

The syntax in multiple inheritance is 3

class eriveclassname 2 visibilitymoe baseclassname+, visibilitymoebaseclassnameJ O,visibilitymoe baseclassname+, Y P

R

YYYYY. BB members of the erive class

U

Multilevel D @hen a subclass inherits from a class which inherits from another class.

Page 31: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 31/102

The general form of multilevel inheritance is 3

class eriveclassname+ 2 visibilitymoe baseclassname

R

YYYYY. BB members of the erive classU

class eriveclassnameJ 2 visibilitymoe eriveclassname+

R

YYYYY. BB members of the erive class

U

$ierarchical D @hen many subclasses inherit from one base class.

Page 32: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 32/102

The general form of inheritance is 3

class eriveclassname 2 visibilitymoe baseclassname

R

YYYYY. BB members of the erive classU

$ybri 3 A combination of J or more forms, li%e when a subclass inherits from multiplebase classes an the base classes inherit from a single base class.

O# KBDP

Page 33: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 33/102

3ow are constructors an, ,estructors han,le, in ,erive, classes?

(! Marks)

(Ans)As you %now, constructors an estructors are not inherite. A erive class has its ownmembers along with inherite members. An obect of the erive class will have its ownata members an it will be built upon the ata members inherite from the base class.To create an obect, the constructor must be calle./f the base class has a constructor that accepts arguments (i.e. parameterizeconstructor) then the erive class shoul have a constructor that passes the argumentsto the base class constructor. /f the base class has only efault constructors, then theerive class nee not have a constructor.

The example below shows single inheritance in private visibility moe, where the baseclass constructor ta%es an argument. The erive class has a constructor that invo%esthe base class constructor an passes on the value to it.

Xinclue S iostream.h

class 5R BBbase class 5int aQpublic25(int x)R a<xQ BB constructor ta%es + argumentcoutSS&a < &SS aQUvoi getat()RcoutSS&a < &QcinaQUvoi ispat()RcoutSS aQUUQclass # 2 private 5R BBerive class #

Page 34: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 34/102

int cQpublic2#(int x, int y) 2 5(x) BBconstructor invo%es base class constructorR c<yQ Uvoi getata()RcoutSS&c < &Q

cincQgetat()QUvoi ispata()RcoutSS c Qispat()QUUQvoi main()R# e(+J,H-)Qe.getata()Q

e.ispata()QU6emember, to create an obect, first the constructor of the base class an then theconstructor of the erive class will be calle.

@hen an obect is estroye, first the erive class estructor is invo%e an then thebase class estructor.

7oo: at the following class -class %@ 

public =

  int h

  int b

  C

 Lsing % as base class( ,erive two classes( 5ectangle an, Triangle/ Both ofthese shoul, have a function calcarea#) that calculates an, ,isplas the area of

the rectangle or triangle( respectivel/ $efine parameteriAe, constructors toinitialiAe the values of height an, base/

(! Marks)

(Ans)Xinclue S iostream.h 

class AR

public 2

int hQ

int bQ

Page 35: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 35/102

UQ

class 6ectangle 2 public A

R

public2

6ectangle(int x, int y)R

h < xQ

b < yQ

U

voi calcarea()R

int a<h C bQ

coutSS&Area of the rectangle < &SS aQ

U

UQ

class Triangle 2 public A

R

public2

Triangle(int x, int y)R

h < xQ

b < yQ

U

voi calcarea()R

float a<(h C b)C?.0Q

coutSS&Area of the Triangle < &SS aQ

U

UQ

voi main()R

Triangle ot(++,\)Q

Page 36: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 36/102

6ectangle or(+J,)Q

ot.calcarea()Q

or.calcarea()Q

U

What are the errors in the given co,e?

Minclu,e D iostream/hN JJline;

class %@ JJline8

int a; JJline6

  protecte, = JJlineO

  int a8 JJline<

  public = JJlineP

  int a6 JJlineQ

C JJlineR

class B = public % JJlineS

@ JJline;>

  public= JJline;;

  voi, func#)@ JJline;8

  int b;(b8(b6 JJline;6

  b;1a; JJline;O

  b81a8 JJline;<

  b61a6 JJline;P

 C JJline;Q

C JJline;R

class & = % JJline;S

@ JJline8>

  public= JJline8;

  voi, func#)@ JJline88

Page 37: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 37/102

  int c;(c8(c6 JJline86

  c;1a; JJline8O

  c81a8 JJline8<

  c61a6 JJline8P

  C JJline8Q

C JJline8R

  JJline8S

voi, main#)@ JJline6>

  int x((A JJline6;

  B ob JJline68

  x1ob/a; JJline66

  1ob/a8 JJline6O

  A1ob/a6 JJline6<

  & oc JJline6P

  x1oc/a; JJline6Q

  1oc/a8 JJline6R

  A1oc/a6 JJline6S

C JJlineO>

(! Marks)

(Ans)a) *ine +-, a+ is a private member of A, so cannot be accesse

b) *ine J-, a+ is a private member of A, so cannot be accessec) *ine HH, a+ is a private member of A, so cannot be accesse) *ine H-, aJ is a protecte member of ", so cannot be accessee) *ine H, a+ is a private member of A, so cannot be accessef) *ine H, aJ is a private member of 7, so cannot be accesseg) *ine H\, aH is a private member of 7, so cannot be accesse

7oo: at the co,e below an, answer the uestions that follow/

class Uehicle@

  int maxspee,

Page 38: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 38/102

  protecte, =

  int maxseats

  public =

  voi, get,at#int( int)

  voi, ,isp,at#)

C

class 3eav = protecte, Uehicle

@ int mileage

  protecte, =

  int loa,

  public=

  voi, get,#int( int)

  voi, ,isp,#)

C

class Uan = private 3eav

@

  int weight

  public=

  voi, get,ata#int)

  voi, ,isp,ata#)

C

 

a) 4ame the base class an, ,erive, class names for class 3eav/b) Which functions can be accesse, b ,isp,ata#)?

c) Which functions can be accesse, b ob9ects of class 3eav?,) Which functions can be accesse, b ob9ects of class Uan?

(# Marks)

(Ans)

a) "ase class is Lehicle an erive class is Lan for class $eavy b) >unction ispata() can access getata(), get(), isp(), getat() an ispat()

Page 39: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 39/102

c) 'bects of class $eavy can access get() an isp()) 'bects of class Lan can access getata() an ispata()

7oo: at the co,e below an, answer the uestions that follow/  class %@

  voi, afun#)  protecte, = int a;(a8

public = voi, get%#)  voi, ,isp%#)  Cclass 3 = protecte, %@

int h;(h8protecte, = int h6(hO 

voi, get3#)

  public=

  voi, ,isp3#)

C

class U = public 3

@

  int v;

  protecte, =

  int v8

  voi, getU#int)

  public=

  voi, ,ispU#)

C

 

a) 4ame the base class an, ,erive, class names for class 3/b) 4ame all protecte, members of class U/

c) Which ,ata members can be accesse, b function getU#)?,) Which functions can be accesse, b ob9ects of class U?

 

Page 40: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 40/102

(# Marks)

(Ans)a) "ase class is A an erive class is L for class $ b) 5rotecte members are vJ, getL(), hH,h-, get$(), a+, aJ, getA(), ispA()c) >unction getL() can access v+, vJ, hH, h-, a+,aJ) 'bects of class L can access ispL() an isp$()

&reate a base class Buil,ing that stores the number of floors an, the number of rooms the buil,ing has/ 'rom this( ,erive a class 'lats that stores the numberof bathrooms an, open terraces/ 'rom Buil,ing( ,erive another class .fficesthat stores the number of 'ire Hxits/

(# Marks)

(Ans)

Jinclude@ iostream.h Kclass uildin"4

int floors5int rooms5

 public'$oid "etd()4cout@@nNo. of #loors 6 5cinKKfloors5cout@@nNo. of +ooms 6 5cinKKrooms5

8$oid dispd()4cout@@nNo. of #loors 6 @@ floors5cout@@nNo. of +ooms 6 @@ rooms58

85class #lats ' public uildin"4int baths5int terraces5 public '$oid "etdat()4"etd()5

cout@@nNo. of athrooms 6 5cinKKbaths5cout@@nNo. of erraces 6 5cinKKterraces58$oid dispdat()4

dispd()5cout@@nNo. of athrooms 6 @@ baths5cout@@nNo. of erraces 6 @@ terraces5885class ffices ' public uildin"4

int fire%its5 public '$oid "etdata()4"etd()5cout@@nNo. of #ire 3%its 6 5cinKKfire%its5

8

$oid dispdata()4dispd()5

Page 41: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 41/102

cout@@nNo. of #ire 3%its 6 @@ fire%its5885

$oid main()4#lats of5ffices oo5

of."etdat()5of.dispdat()5oo."etdata()5

oo.dispdata()58

Data File #andlin"

What is meant b stream? (1 Mark)

(Ans)A stream is a seuence of bytes, or, flow of ata. /t acts as an interface between the filean program.Which classes are use, for file input an, output operations? 

(1 Mark)

(Ans)The classes use are ifstream, ofstream an fstream.4ame an two functions use, in file input-output error han,ling/

(1 Mark)

(Ans)int ba() an int fail() are use for error hanling.Wh shoul, we chec: for en, of file?

(1 Mark)

(Ans)@e chec% for en of file to prevent attempts to rea in case the file has ene.3ow are text files ,ifferent from binar files?

( Marks)

(Ans)Text files are also calle A17// files. They stores information in the form of A17//characters. There are +J ifferent A17// coes. Also, text files contain lines of text aneach of these has an enDofDline (#'*) mar%er automatically appene whenever youinicate that you have reache the en of a line. @hen a file is opene in text moe,various character translations ta%e place. /n case of binary files, information is store in

the same format in which it is store in the memory. o character translation ta%es placewhen a binary file is opene, because of which binary files can be rea an written fasterby the computer.3ow is get#) ,ifferent from getline#) ?

( Marks)

(Ans)"oth get() an getline() can rea characters from the input stream into an array till thespecifie number of characters are entere or till the elimiting character isencountere( Nn9 by efault). The ifference is that, in case of getline() this character isremove from the input stream but get() leaves it in the input stream.3ow is the file mo,e ios==ate ,ifferent from ios==app?

( Marks)

(Ans)@hen a file is opene in the moe ios22ate or ios22app , the file pointer is positione at

Page 42: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 42/102

the en of the file. @ith ios22app we can a ata only at the en of the file, but withios22ate, we can write anywhere in the file.$escribe two member functions from fstream class/ 

( Marks)

(Ans)1ome member functions of fstream class are see%p(), see%g(), tellg() an tellp().>unctions see%g() an tellg() are use with the input stream. 7ommon forms of thesefunctions are 3

a) ifstream [ see%g(long)Qb) ifstream [ see%g(long, pos) Qc) long tellg()Q/n form a) see%g() positions the get pointer at an absolute position given by the longinteger./n form b) see%g() positions the get pointer at a position given by the long integer anby the value of pos.

 pos can be ios '' be" 99 from be"innin" of file

ios '' cur 99 from current positionios '' end 99 from the end

/n form c) tellg() gives the byte position of the get pointer in the file as a long integer.

3ow is get#) ,ifferent from rea,#)? ( Marks)

(Ans)>unction get() reas one character at a time but rea() can rea chun%s li%e structuresan obects at one go.

When shoul, the file mo,e ios==nocreate be use,? ( Marks)

(Ans)ormally, in a program, when we give a file name to be opene, it is available. /f it is notthere an the program is going to output ata to the file, it gets create by the givenname. At times, if the file is not there, we on9t want it create 3 in situations li%e thiswe use ios 22 nocreate.What are the two was of opening a file?

( Marks)

(Ans)A file can be opened in two ways

a) Lsin" the constructor of the stream class– this method is useful when only one file is used in the stream.Constructors of the stream classes ifstream! ofstream and fstream are used to initiali2e the file stream ob>ect withthe file name.

#or e%ample! to open a file Names.Hat for readin" i.e. input! we create a stream ob>ect of class ifstream and passon the filename to it! as – 

ifstream readfile(Names.HatO)5

 b) Lsin" the function open() this method is useful when we want to use different files in the stream. If two ormore files are to be processed simultaneously! separate streams must be declared for each.

ifstream ifl5 99input stream ifl created

ifl.open(Names.HatO)5 99 file Names.Hat lin;ed with ifl

 Now! usin" ifl! the file can be read.

hen we open a file usin" function open()! alon" with the filename we can also "i$e the file mode. he "eneralform of the function open() with two ar"uments is – 

Page 43: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 43/102

streamob>ect. open(filenameO! filemode)5

/f the file moe is not given, the efaults are assume. /f ifstream is use, the efaultmoe is ios 22 in. /f ofsream is use, the efault moe is ios 22 out. fstream oes notprovie a moe by efault an so we have to specify the moe when we use the functionopen ().Hxplain using an example how we chec: for en, of file/

  ( Marks)

(Ans)The function eof() is use to etect en of file. /t returns a non zero value when en offile is reache. Another way to chec% for en of file is whether the stream obect returnszero or not. /t returns zero when the en of file is reache.ifstream finQfin.open(E/tems.4atF, ios22in]ios22binary)Qwhile(fin) BBas long as it is non zeroR fin.rea((char C)[ /, sizeof(/T#M))QYYY..U

The value in fin becomes zero when the en of file is reache, an the loop ens. 1incereaing occurs insie the loop, there will be no more attempts to rea the file.

What is the ,ifference between ifstream an, ofstream classes? ( Marks)

(Ans)"oth ifstream an ofstream are erive from class fstreambase. 7lass ifstream is use tocreate an input stream to rea ata from the file an contains functions for reaing atafrom the file.7lass ofstream is use to create an output stream to write ata to the filean contains functions for writing to the file.What is the ,ifference between seuential an, ran,om access? 

( Marks)(Ans)/n seuential files, recors are store one after the other in seuence. To rea anyrecor, all the preceing recors must be rea. /n case of ranom access, the reaoperation ta%es place exactly where the recor to be accesse is. To calculate the exactaress in memory, a %ey fiel is transforme into the relative aress.$escribe the streams use, for input an, output with a file/ 

(! Marks)

(Ans)here are < ;inds of streams – input! output and inputoutput.

If we want to use the file for input i.e. readin"! we must create an input stream! usin" class ifstream. #or

e%ample! ifstream ifl5

If we want to use the file for output i.e. writin"! we must create an output stream! usin" class ofstream. #ore%ample! ofstream ofl5

/f we want to use the file for input as well as output, we must create a streamperforming both input an output, using class fstream. >or example, fstream ioflQ

$escribe the ,ifferent file opening mo,es( in brief/ (! Marks)

(Ans)#ile mode describes how the file is to be used. hen we open a file usin" function open()! alon" with the

filename we can also "i$e the file mode. he "eneral form of the function open() with two ar"uments is –  

streamob>ect. open(filenameO! filemode)5

he different file modes are –

Page 44: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 44/102

ios '' in to open the file for readin"

ios '' out to open the file for writin". If the file e%ists! its contents are discarded.

ios '' app to append output at the end of the file

ios '' ate to "o to end of file on openin"! input 9 output can be anywhere within the file

ios '' trun; to delete the contents of the file

ios '' binary to open a file in binary mode. Hefault is te%t mode.

ios '' nocreate if the file does not already e%ist! it will not be created! open() will fail

ios '' noreplace if the file already e%ists! it will not be used! open() will fail

/f the file moe is not given, the efaults are assume. /f ifstream is use, the efaultmoe is ios 22 in. /f ofsream is use, the efault moe is ios 22 out. fstream oes notprovie a moe by efault an so we have to specify the moe when we use the functionopen (). >ile moes can be combine using the bitwise 'r operator (the ] symbol).

Given a structure 2ember( as below( open the file 2H27T/$%T that alrea,stores ,ata of 2ember( an, a,, a recor, at the en,/

struct 2ember@ int co,e

  char nameV8>  int age  char sexC

 

(! Marks)

(Ans)Xinclue S fstream.h 

struct MemberRint coeQchar nameOJ?PQint ageQchar sexQUQvoi main()RMember mQchar cQofstream oflQofl.open(&M#M*/1T.4AT&, ios22app]ios22binary)QcoutSS&nMember 7oe 2 &Qcinm.coeQc<cin.get()Q

coutSS&nMember ame 2 &Qcin.getline(m.name,J?)QcoutSS&nAge 2 &Qcinm.ageQc<cin.get()QcoutSS&nMember 1ex (MB>) 2 &Qcinm.sexQofl.write((charC)[m,sizeof(Member))Qofl.close()Q

U

Write a program that opens a file name, &7%/$%T an, ,isplas the number of characters in it/

Page 45: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 45/102

(! Marks)

(Ans)Xinclue S fstream.h 

voi main()Rint num<?Qchar cQifstream iflQifl.open(&7*A11.4AT&,ios22in)Qwhile(ifl)Rifl.get(c)QcoutSS cQnum;;QcoutSS numQUifl.close()QcoutSS&Total characters < &SS numQ

UWrite a program to use the class Boo: ,eclare, in the previous uestion an,

the file Boo:s/$at/ $ispla all the ,ata in the file/

(! Marks)

(Ans)Xinclue S fstream.h 

Xinclue S string.hclass "oo%Rint boo%coeQchar boo%nameOJ?PQpublic2voi getat()RcoutSS&n"oo% 7oe 2 &Qcinboo%coeQchar c<cin.get()QcoutSS&n"oo% ame 2 &Qcin.getline(boo%name,J?)QUvoi ispat()RcoutSS&n"oo% 7oe 2 &SS boo%coeQcoutSS&n"oo% ame 2 &SS boo%nameQUint match(int c)Rif(c<<boo%coe)return +Qelse

return ?QUUQvoi main()R"oo% bQifstream iflQifl.open(&"oo%s.at&,ios22in]ios22binary)Qif(^ifl) RcoutSS&Wnable to open file D 6eturning&QreturnQUwhile(ifl)Rifl.rea((char C)[b,sizeof("oo%))Q

b.ispat()QU

Page 46: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 46/102

U

&onsi,er class Hmploee in the previous uestion/ %ccept the filename again

an, ,ispla all the ,ata in it/ (! Marks)

(Ans)Xinclue S fstream.h 

class #mployeeRint empcoeQchar empnameOJ?PQchar epartOJ?PQpublic2voi getat()RcoutSS&n#mployee 7oe 2 &QcinempcoeQchar c<cin.get()QcoutSS&n#mployee ame 2 &Qcin.getline(empname,J?)QcoutSS&n4epartment 2 &Qcin.getline(epart,J?)QUvoi ispat()RcoutSS&n#mployee 7oe 2 &SS empcoeQcoutSS&n#mployee ame 2 &SS empnameQcoutSS&n4epartment 2 &SS epartQUUQvoi main()R#mployee eQ

int num<?Qchar fnameO+HPQcoutSS&#nter file name &QcinfnameQifstream iflQifl.open(fname, ios22in]ios22binary)Qif(^ifl)RcoutSS&7annot open file &SS fnameQreturnQUwhile(ifl) Rifl.rea((charC)[e,sizeof(#mployee))Q

e.ispat()QUifl.close()Q

U

$escribe how the two file pointers can be manipulate,/ (# Marks)

(Ans)The two file pointers are the get pointer an the put pointer. The get pointer is use witha file that is open for input an put pointer is use with a file open for output. A file isrea from the position mar%e by the get pointer. /n the same way, when a file is

written, it is at the position mar%e by the put pointer.

Page 47: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 47/102

These two pointers can be manipulate to move irectly to a location in the file to reaor write. The functions use for this are see%g() an see%p(). Two more functions maybe useful here, tellg() an tellp(). >unction tellg() gives the position of the get pointer inthe file an tellp() gives the position of the put pointer in the file. 1uppose the file NT#1T.4AT9 is open for input, lin%e with the input stream ifl.

ifl.see;"(7)5 99 will mo$e the "et pointer to byte number 7 in the file.

ifl.see;"(1! ios''be")5 99 will mo$e the "et pointer to the 1th byte from the be"innin" of the file

ifl.see;"(! ios''end)5 99 will mo$e the "et pointer bac; bytes from the end of the file

ifl.see;"(/1! ios''cur)5 99 will mo$e the "et pointer to the /1th byte from the current position

lon" p6ifl.tell"()5 99 store position of "et pointer in p

ifl.see;"(p!ios''be")5 99 mo$e "et pointer p bytes from the be"innin"

1uppose the file NT#1T.4AT9 is now open for output, lin%e with the output stream ofl.

ofl.see;p(7)5 99will mo$e the put pointer to byte number 7 in the file.

ofl.see;p(1! ios''be")5 99 will mo$e the put pointer to the 1th byte from the be"innin" of the file

ofl.see;p(! ios''end)5 99 will mo$e the put pointer bac; bytes from the end of file

ofl.see;p(/1! ios''cur)5 99 will mo$e the put pointer to the /1th byte from the current position

lon" p6ofl.tellp()5 99 store position of put pointer in p

ofl.see;p(p!ios''be")5 99 mo$e put pointer p bytes from the be"innin"

Write a program to use the structure 2ember( as below( open the file2H27T/$%T that alrea, stores ,ata of 2ember( an, ,ispla the ,etails of a

member whose co,e is given/struct 2ember@

  int co,e  char nameV8>

  int age  char sexC

 

(# Marks)

(Ans)Xinclue S fstream.h 

Xinclue S string.hstruct MemberRint coeQchar nameOJ?PQint ageQ

char sexQUQvoi main()RMember mQchar cQint cQifstream iflQifl.open(&M#M*/1T.4AT&, ios22in]ios22binary)QcoutSS&#nter coe to fin &QcincQc<cin.get()Qwhile(ifl)R

ifl.rea((char C)[m,sizeof(Member))Qif(c<<m.coe)RcoutSS&nMember 7oe 2 &SS m.coeQ

Page 48: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 48/102

coutSS&nMember ame 2 &SS m.nameQcoutSS&nAge 2 &SS m.ageQcoutSS&nMember 1ex 2 &SS m.sexQbrea%QUU

ifl.close()QU

Write a program to create a class Boo: that stores the boo: co,e an, name/$efine functions necessar to accept ,ata( ,ispla ,ata an, chec: formatching/ .pen the ,ata file Boo:s/$at an, ,elete the recor, where boo: co,ematches the entere, co,e/ 

(# Marks)

(Ans)Xinclue S fstream.h 

Xinclue S stio.hclass "oo%Rint boo%coeQchar boo%nameOJ?PQpublic2voi getat()RcoutSS&n"oo% 7oe 2 &Qcinboo%coeQchar c<cin.get()QcoutSS&n"oo% ame 2 &Qcin.getline(boo%name,J?)QUvoi ispat()R

coutSS&n"oo% 7oe 2 &SS boo%coeQcoutSS&n"oo% ame 2 &SS boo%nameQUint match(int c)Rif(c<<boo%coe)return +Qelsereturn ?QUUQvoi main()R"oo% bQ

int cQint foun<?Qofstream oflQofl.open(&temp.tmp&, ios22out]ios22binary)Qifstream iflQifl.open(&"oo%s.at&,ios22in]ios22binary)QcoutSS&n#nter "oo% 7oe &QcincQwhile(ifl)Rifl.rea((char C)[b,sizeof("oo%))Qfoun<b.match(c)Qif(foun<<?)

ofl.write((char C)[b,sizeof("oo%))QUifl.close()Q

Page 49: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 49/102

ofl.close()Qremove(&"oo%s.4at&)Qrename(&temp.tmp&, &"oo%s.4at&)Q

U

&onsi,er class Hmploee with ,ata members empco,e( empname an, ,epart/$efine necessar functions to accept an, ,ispla ,ata/ Write a program toaccept ,ata for ,ifferent emploees an, write to the file whose name isprovi,e, b the user/

(# Marks)

(Ans)Xinclue S fstream.h 

class #mployeeRint empcoeQchar empnameOJ?PQchar epartOJ?PQpublic2voi getat()RcoutSS&n#mployee 7oe 2 &QcinempcoeQchar c<cin.get()QcoutSS&n#mployee ame 2 &Qcin.getline(empname,J?)QcoutSS&n4epartment 2 &Qcin.getline(epart,J?)QUvoi ispat()RcoutSS&n#mployee 7oe 2 &SS empcoeQcoutSS&n#mployee ame 2 &SS empnameQ

coutSS&n4epartment 2 &SS epartQUUQvoi main()R#mployee eQint num<?Qchar fnameO+HPQcoutSS&#nter file name &QcinfnameQofstream oflQofl.open(fname, ios22app]ios22binary)Qif(^ofl)R

coutSS&7annot open file &SS fnameQreturnQUcoutSS&$ow many employeesV &QcinnumQfor(int i<+QiS<numQi;;)Re.getat()Qofl.write((charC)[e,sizeof(#mployee))QUofl.close()Q

U

$ointers

Page 50: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 50/102

What are pointers? (1 Mark)

(Ans)

ointers are $ariables that store memory addresses.3ow are pointers ,ifferent from reference variables? 

(1 Mark)(Ans)A reference variable is an alias or another name for an existing variable while a pointer isa variable that stores an aress. The reference oes not occupy memory space but apointer oes. The eclaration too is ifferent 3int aQBB variable name a 

int [alsoa < aQ BB reference alsoa create, is an alias for aQint CpaQ BB pointer pa createpa<[aQBB aress of a store in pa 

The value at the aress in the pointer is accesse using the NC9 operator, calleereferencing. /n case of references, there is no such nee, they irectly give the value.What is 'ree tore ? 

(1 Mark)(Ans)>ree 1tore is also calle $eap. /t is unallocate memory that is use uring programexecution. Memory that is ynamically allocate from this free store is unname an ismanipulate through the aress i.e. pointers.3ow is a,,ition carrie, out with pointers? 

(1 Mark)

(Ans)#very pointer has a base ata type. /t hols the aress of variables of that ata type.@hen + is ae to a pointer, the size of the ata type is ae to it. 1uppose pointer pa

hols the aress of integer variable a( as +??+. Aing + to pa will give +??H. This isbecause the size of int is J.

1uppose pf is a pointer that hols the aress of float variable f( as JH??. Aing H to pf will a H times the size of float i.e. +J, to the aress in pf , ma%ing it JH+J.Write statements to ,ispla the a,,ress of a float tpe variable name, rate/ 

(1 Mark)

(Ans)float rateQfloat CfpQ fp < [rateQcoutSS fpQGive the prototpe of a function name, funstring that returns a string an, ta:esa string as argument( using pointers/ 

(1 Mark)

(Ans)char C funstring(char C)QHxplain( using an example( how ob9ects can be passe, to a function asreference an, how a function can return reference to an ob9ect/ 

( Marks)

(Ans)XinclueS iostream.h 

class #mpRint coeQpublic 2voi getat(int x)Rcoe<xQUvoi ispat()RcoutSS &coe < &SS coeQUUQ#mp[ func(int x, #mp[ #m)R

Page 51: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 51/102

#m.getat(x)QcoutSS &Lalue passe&Qreturn #mQUvoi main()R#mp e+, eJQ

eJ.getat(H)Qfunc(0,e+) < eJQ BBfunction calle+.ispat()QeJ.ispat()QU

/n this program an integer an an obect as reference, are passe to function func().6eference to the obect is returne by the function. The function call places the functionon the left sie of the < sign. The returne variable is assigne the obect eJ. @hen theobects are isplaye, e+ an eJ both have the same output.

3ow is the memor organiAe, when a program is execute,? 

( Marks)(Ans)>our logically separate areas are create after a 7;; program is compile.− 'ne area hols all the program statements that are to be execute i.e. the compileprogram coe.− The next area hols all the global variables being use.− The thir area, also calle 1tac%, stores all local variables, arguments passe to

functions an the return aress when functions are calle.− The fourth area, calle $eap or >ree 1tore, is free memory which is ynamicallyallocate uring program execution.

3ow is static memor allocation ,ifferent from ,namic memor? ( Marks)

(Ans)1tatic Memory Allocation 2 when memory to be allocate is %nown beforehan, it isallocate uring compilation. !enerally in a program, variables are eclare along withata type an arrays are eclare with size an memory is allocate accoringly.4ynamic Memory Allocation 2 when the amount of memory reuire is not %nownbeforehan, it is allocate while the program is running, an is %nown as ynamicmemory allocation. Two operators are use D new an elete. Memory for allocation atruntime is obtaine from the free store or heap.3ow is the operator new use,? Hxplain with examples/ 

( Marks)(Ans)The Nnew9 operator allocates memory ynamically an returns a pointer that stores thearess of the location where memory has been allocate. The general form of allocatingis 2pointervariablename < new atatypeQ $ere, ata type can be any vali ata type, incluing structures an classes. "ytes areallocate accoring to the ata type an the aress is store in the pointer variable ofthe same ata type.>or example 2 int CpaQpa < new intQCpa<+JQ BB +J is store at the aress in pa

$ere, J bytes will be allocate for an integer which will be accesse through the aressin pointer pa.The allocate memory can be initialize at the time of allocation itself,

Page 52: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 52/102

char CpcQpc < new char(NA9)QThe above statement allocates memory for a char type value an stores NA9 in it. Thearess is store in pointer pc.To ynamically allocate memory for a +D4 array,pointervariablename < new atatypeOsizePQ

where size is number of elements in a +D4 array.int CA< new intO+?PQ

will allocate memory for a +? element integer array whose aress is in A. ow, arrayelements can be referre as AO?P, AO+P, A OJP an so on.To ynamically allocate memory for a JD4 array,pointervariablename < new atatypeOrows C columnsPQwhere rows is the number of rows an columns the number of columns in the array.

Wh is the operator ,elete use,? ( Marks)

(Ans)

The Nelete9 operator frees (eDallocates) the memory pointe to by the pointer.The memory allocate using new remains allocate until it is free using the ,elete operator. /f the allocate memory is not eDallocate, then with every run of the programthe amount of available memory ecreases. The general form of using the eleteoperator is, elete pointervariablenameQ

elete paQ BB frees memory pointe to by paelete O+?P AQBB frees memory allocate to array A, array size is optional

elete O P 8QBB frees memory allocate for array 83ow are F an, Y use, with pointers? 

( Marks)

(Ans)

The NC9 is also calle the in,irection operator an N[9 is also calle a,,ress of  operator.@hen a pointer is eclare, the NC9 is use 2D int CpaQ@hen an aress is to be store the N[9 is use 2D pa < [aQ@hen the value at the aress in the pointer is to be accesse (i.e. ereference), the

 NC9 is use, as in, coutSSCpaQ3ow are arras an, pointers relate,? 

( Marks)

(Ans)The name of an array is regare as a pointer. /t hols the aress of the first elementof the array. 7onsier the statements below D 

int AO+?P < R+,J,H,-,0,I,,,\,+?UQA is the array name, it hols the aress of the first element AO?P.coutSS AQ BBisplays the aress of the first elementcoutSS CAQ BBisplays value at that aress i.e. +coutSS A;+Q BBisplays another aresscoutSS C(A;+)Q BBisplays value at that aress i.e. JAs you can see, A behaves ust li%e a pointer.$escribe an arra of pointers/ 

( Marks)

(Ans)An array of pointers is an array, each element of which is a pointer.An array of integer pointers woul be eclare as 3 int CO0PQow, each of the array elements, O?P, O+P, OJP, OHP an O-P woul hol thearess of an integer variable. *oo% at the statements below 3int a < +JQint b < JHQ

Page 53: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 53/102

int c < H-Qint < -0Qint e < 0IQO?P < [aQO+P < [bQOJP < [cQ

OHP < [QO-P < [eQThe two following statements woul give the same output.coutSS aQcoutSS CO?PQ*ets loo% at another example using a string.char OP<E4iscover @illifeFQcoutSS QcoutSS CQcoutSS C(;+)Q'utput of these lines2 4iscover @illife4i(coe cont.)

char Cp<QcoutSS pQcoutSS CpQcoutSS C(p;+)Q

'utput of these lines2 4iscover @illife4iAgain, the array name behaves exactly li%e the pointer.

What is the ,ifference between constant pointers an, pointers to constants? ( Marks)

(Ans)A constant pointer means that the aress in it cannot be change. 

int a<+JQ BB integer variable with value +Jint Cpa < [aQBB pointer pa stores aress of a;;paQ BB increment (aress in) paint Cconst cpa<[aQ BB constant pointer name cpa stores aress of a;;cpaQ BBerror, constant pointer cannot be change

A pointer to a constant means that the pointer hols the aress of a constant.const int cnum<JHQ BB constant cnum eclareconst int Cpcnum < [cnumQ BB pointer to a constant stores aress of cnum;;cnumQ BB #rror, cnum is a constant

;;pcnumQ BB increment aress in pcnum

3ow is passing references to a function ,ifferent from passing pointers? ( Marks)

(Ans)/n both the cases, the original ata changes after the function call.@hen reference is passe, the prototype is something li%e 3

voi func+(int [, int [)QThe actual parameters are simply given new names an accesse through them. Thefunction call is the same as the call when function is calle by value.@hen pointers are passe, the prototype is something li%e D

voi funcJ(int C, int C)Q@hen the function is calle, aresses are passe. These aresses are store in pointervariables by the function an the ata at these aresses is accesse.

Page 54: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 54/102

What are self referential structure? ( Marks)

(Ans)A structure that has a member that refers to the structure itself is %nown as a selfreferential structure.#xample D

 struct guestRint telQchar nameOJ?PQguest CnextQ BB pointer to type guestUQ

$ere, structure guest is a self referential structure. /t has a member, next, which storesthe aress of guest type.What is a ,namic structure? 

( Marks)

(Ans)nce a structure has been defined! $ariables! includin" pointers can be declared for it. hen memory isallocated dynamically for a structure! it is called a dynamic structure.3%ample 

struct ARint aQchar bQUQ

A $/!:$15

$16new A5

6emember, variables create using new must be elete when no longer neee, byelete.Give an example to show a function returning a pointer to an ob9ect/ 

( Marks)

(Ans)XinclueS iostream.h

class #mpRint coeQpublic 2voi getat(int x)Rcoe<xQUvoi ispat()RcoutSS &coe < &SS coeQUUQ#mpC func(int x, #mp [#m)R#mp CpQ#m.getat(x)QcoutSS &Lalue passe&Q

p < [#mQreturn pQUvoi main()R#mp e+, eJQ#mp CepQeJ.getat(H)Qep < func(0,e+)Q BB function calle+.ispat()QeJ.ispat()QepDispat()QU

5ointer p is assigne the aress of the obect in the function func(), an returne.@hen the function ispat() is calle with the pointer, the arrow operator is use.

Page 55: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 55/102

how how pointers to structure can be passe, to a function/ ( Marks)

(Ans)

XinclueS iostream.hstruct itemRint code5

int priceQUQitemC func(item Cptr)RcinptrDcoeQcinptrDpriceQreturn ptrQUvoi main()Ritem i+,CpiQpi < func([i+)Q BB function callcoutSS &from 5ointer &SS piDcoeSS piDpriceQcoutSS &from variable &SS i+.coeSS i+.priceQU

$ere, i+ is a structure variable an pi is a pointer. Aress of i+ is passe to the functionthat accepts values an returns a pointer.What is the this pointer? 

( Marks)

(Ans)The member functions of a class exist at one place in memory an are use by all theobects. @hen an obect calls a function, the function is automatically passe a pointer tothat obect. Thus, the function has the aress of the obect an can use its ata. This

pointer is calle the this pointer.#xample 3XinclueS iostream.hclass stuRint rnoQint mar%sQpublic2stu(int a, int b)Rrno<aQmar%s<bQUvoi isp(stu s)RcoutSS thisDrnoQcoutSS thisDmar%sQcoutSS &n5asse 'bect&QcoutSS s.rnoQcoutSS s.mar%sQUUQvoi main()Rstu s+(+?,+??)Qstu sJ(++,\)QsJ.isp(s+)QU

The output of this program clearly shows that sJ is the obect associate with Nthis9 when

sJ calls the member function. As Nthis9 is a pointer, it uses the arrow operator -N annot the ot / operator to access members.

Page 56: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 56/102

What is the ,ifference between -int Fp; 1 new int#;8)

  an,int Fp8 1 new int V;8 

( Marks)

(Ans)/n statement D int Cp+ < new int(+J)Q"ytes are allocate in memory, to store an integer an initialize to +J, the aress ofthis memory location is store in pointer p+./n statement D int CpJ < new int O+JPQ"ytes are allocate in memory for a +J element integer array. The aress of thismemory location is store in pointer pJ. ow, pJ can be use ust li%e the array name.What is the ,ifference between %V6 an, F#% " 6)? 

( Marks)

(Ans)

AOHP refers to the value in array A with inex number H.C(A ; H) refers to the value at the aress A ; H./n both the cases here, the same element is accesse.

When % is an arra ( the expression %"" is invali,/ Wh? ( Marks)

(Ans)A is the aress where the system has place the array an it will stay here till the enof the program. As it is the base aress of the array, it is a constant an cannot bechange. $owever, we can eclare a pointer an assign A to it. ow, the pointer variablecan be incremente if reuire. 

int AOP<R+,J,H,-,0UQint CpQp<AQ

;;pQ

What is pointer to voi,? ( Marks)

(Ans)ormally when we eclare a pointer, we give it a type which is the same as the type ofthe variable whose aress it will store. i.e. int CptrQ will create pointer ptr which willhol aresses of integer variables.

5ointer to voi is li%e a general purpose pointer that can store aress of any ata type./t is use only in certain situations.To eclare a pointer to voi, give the statement D voiC ptrQWhat is memor lea:? What causes it? 3ow can it be avoi,e,? 

(! Marks)

(Ans)@hen memory is allocate ynamically using the new operator, it remains occupieeven when the program is over. 1uch occupie memory bloc%s are %nown as orphanememory bloc%s . !raually, as the number of such bloc%s increases, there is lessmemory available to the program which affects its wor%ing. This situation is calleMemory *ea%.1ome reasons for memory lea% are D

• there is no elete in the program to free ynamically allocate memory• the statement with elete is bypasse in certain situations

Page 57: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 57/102

•  Nnew9 assigns the value to a pointer which alreay hols an aressMemory lea% can be avoie by 3

• always freeing the ynamically allocate memory• assigning the aress passe by 9new9 to a fresh pointer.

Write a function that accepts a string as argument( removes all blan:s from itan, returns it/ 

(# Marks)

(Ans)XinclueS iostream.h 

voi main()Rchar AO?PQchar CstrQcharC funblan%(charC)Q BB function prototypecoutSS &#nter string &Qcin.getline(A,?)Q

str<funblan%(A)Q BB function callcoutSS ASS enlQcoutSS strSS enlQUcharC funblan%(charC t)Rchar CtmpQint i<?Qwhile(Ct ^<G�G)Rif(Ct^<G G)RtmpOiP<CtQ;;iQU;;tQUtmpOiP<G�GQreturn tmpQ

U

Write a function that accepts a string as argument( removes all blan:s from itan, returns it/ 

(# Marks)

(Ans)XinclueS iostream.h 

voi main()R

char AO?PQchar CstrQcharC funblan%(charC)Q BB function prototypecoutSS &#nter string &Qcin.getline(A,?)Qstr<funblan%(A)Q BB function callcoutSS ASS enlQcoutSS strSS enlQUcharC funblan%(charC t)Rchar CtmpQint i<?Qwhile(Ct ^<G�G)Rif(Ct^<G G)RtmpOiP<CtQ;;iQ

Page 58: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 58/102

U;;tQUtmpOiP<G�GQreturn tmpQ

U

Write a program to store < names in an arra of pointers( name, list( an, then

reverse the or,er of these names in the arra/ (# Marks)

(Ans)

XinclueS iostream.hvoi main()

R

char CtmpQ int i,Qchar ClistOP<R&Asia&, &"ahamas&,&7anaa&,&4enmar%&,&#nglan&UQfor( i<?QiS 0Qi;;)coutSS listOiPSS enlQfor( i<?,<-Q i S JQi;;,DD)Rtmp<listOiPQlistOiP<listOPQlistOP<tmpQUfor( i<?Qi S 0Qi;;)

coutSS listOiPSS enlQU

($%) What is the ,ifference between an arra an, a structure? 

(1 Mark)

(Ans)

An array is a collection of elements of the same ata type. #ach array element isreference using the inex or subscript. A structure has members of ifferent ata types.The members in the structure are accesse using the ot N.9 operator.

($%) What is the length of the given arra?

%55 V -6 // O (1 Mark)

(Ans)*ength < W" 3 *" ; + where W" (or Wpper "oun) < -*" (or *ower "oun) < DH

1ize < - D ( DH) ;+<

Page 59: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 59/102

$%) What is the prereuisite for Binar earch metho,? 

(1 Mark)

(Ans)

The array shoul be sorte for "inary 1earch to wor%. Also, the upper an lower bounsfor the array shoul be %nown, as mi point is calculate. 

($%) What will be the a,,ress of the elements %55V8 an, %55V-; in an arra

%55V-< // S that has the base a,,ress O<>> an, element siAe 8? ( Marks)

(Ans)Address of A++PiQ 6 & (i – R) 

where is ase Address! is element si2e and R is Rower ound of the array.

6 B77 6 1

i 6 1 R 6

Address of A++P i Q 6 B77 & 1( 1 – ())

6 B/B

6 B77 6 1

i 6 / R 6

Address of A++P i Q 6 B77 & 1( / – ())

6 B7D

($%)What is an arra? 3ow are one-,imensional arras ,ifferent from two-

,imensional arras? ( Marks)

(Ans)An array is a collection of finite elements of the same data type! placed conti"uously in memory. 3ach arrayelement can be referenced usin" inde% or subscript numbers.

Arrays can be onedimensional or multidimensional.

A one–dimensional array is declared with one si2e specification. 3ach element is accessed usin" the array nameand inde% number which refers to its location. In array AP/7Q! the elements can be accessed as AP7Q! AP/Q and so

on.

A two–dimensional array can be re"arded as an array of arrays. It re-uires 1 si2e specifiers. It is a ;ind of multidimensional array. o declare an inte"er array named A* with B rows and D columns! "i$e

int A*PBQPDQ5

#lements can be accesse as A8OrPOcP where r is the row an c the column number.6emember in 7;;, the row an column numbers start from ?.

($%) What is the ,ifference between 7inear an, Binar earch? 

( Marks)

(Ans)hey are both searchin" techni-ues. Rinear Eearch can be used on sorted or unsorted arrays. It in$ol$escomparin" each array element with the "i$en $alue.

Page 60: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 60/102

Al"orithm for Rinear Eearch/. E3 ctr 6 799 7 is the Rower ound of the array

1. +33A E3E < to B LNIR ctr K L 99 chec; each element of the array

<. I# APctrQ 6 Sal T3N99 compare $alue and array element

4

+IN Sal! located at ! ctr , =

8B. ctr 6 ctr & / 99 increment counter 

.I# ctr K L T3N

+IN Sal! Not in arrayO=. 3NH

"inary 1earch can be use only on sorte arrays. /t is consiere more efficient than*inear 1earch as the number of comparisons is much less. /t first compares the valuean the mile element of the array. As it is a sorte array, if the value is less than the

mile element, the elements in the left half shoul be chec%e otherwise if the value isgreater than the mile element, the right half of the array shoul be chec%e. Thisprocess is one repeately till the element is locate or eclare Nnot foun9.

Al"orithm for inary Eearch with array sorted in ascendin" order 

/. E3 low 6 R! up 6 L 99 L and R are upper and lower bounds

1. +33A E3E < to = LNIR low K up 99 repeat until low "oes beyond up

<. m 6 IN( low & up) 9 1 99 find mid point of array

B. I# AP m Q 6 Sal T3N 99 compare $alue and array element

4 +IN Sal! located at ! m & /

, F

8. I# A P m Q @ Sal T3N

low 6 m & /

=. I# AP m Q K Sal T3N

up 6 m /

. #4

%n arra is given below/ Give the status at the en, of each pass using selection

sort metho,/8 O P R ; 6 < Q

( Marks)

(Ans)

After / D + - I J H 0 After // D+ J I - H 0  After /// D+ J H - I 0 After /L D+ J H - I 0 After L D+ J H - 0 I After L/ D+ J H - 0 I After L// D+ J H - 0 I

Page 61: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 61/102

Lsing the arra below( give the status at the en, of each pass using bubble sortmetho,/8 O ;P 8R ;; 6 8< 8Q 

( Marks)

(Ans)

After /D J - +I ++ H J0 J JAfter // DJ - ++ H +I J0 J J  After /// DJ - H ++ +I J0 J JAfter /L DJ H - ++ +I J0 J JAfter L DJ H - ++ +I J0 J JAfter L/ DJ H - ++ +I J0 J JAfter L// DJ H - ++ +I J0 J JAfter L/// DJ H - ++ +I J0 J JLsing the arra below( give the status at the en, of each pass using insertionsort metho,/ ;8 8O 8P 8R ;; ;6 8< 8Q 

( Marks)

(Ans)

After / D +J J- JI J ++ +H J0 J

After // D +J J- JI J ++ +H J0 J  After /// D +J J- JI J ++ +H J0 JAfter /L D ++ +J J- JI J +H J0 JAfter L D ++ +J +HJ- JI J J0 JAfter L/ D +++J +HJ- J0 JI J JAfter L// D +++J +HJ- J0 JI J J3ow are two-,imensional arras implemente, in memor? 

( Marks)

(Ans)An array is allocated conti"uous stora"e in memory. #or this! the 1H array is lineari2ed. his can be done in twoways – +ow Ma>or or Column Ma>or.

/n 6ow Maor form, the first row is store followe by the secon row an so on. /n7olumn Maor, the first column is store followe by the secon column an so on. Thecomputer %eeps trac% of the starting aress of the array (base aress) an accessesthe element by calculating its aress.X is a 8$ arra ,efine, as V-8 // O( -6 // O/ Hach element of the arra ta:es up8 btes/ ts base a,,ress is given as 8>>>/ &alculate the a,,ress of XV8(6( if

the arra is store, in row ma9or form/ ( Marks)

(Ans)Address of *P i Q P > Q 6 & ( nc(i – R+) & (> – RC))Tere! 6 1777 nc 6 D 

6 1 R+ 6 1

i 6 1 RC 6 <

 > 6 <

Address of APi ! >Q 6 1777 & 1( D( 1 (1) ) & (< (<) )

< J?I

Hach element of the arra %V-;> // <( < // ;< ta:es ; bte/ ts base a,,ress isgiven as ;>>>/ &alculate the a,,ress of %V -<( R/ The arra is in column

ma9or/ ( Marks)

Page 62: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 62/102

(Ans)Address of AP i Q P > Q 6 & ( nr( > – RC) & ( i – R+))Tere! 6 /777 nr 6 /= 

6 / R+ 6 /7

i 6 RC 6

 > 6 D

Address of AP! DQ 6 /777 & /( /=(D ) & ( – (/7) )

6 /7<

What ,o ou means b ,ata structures? $escribe ,ifferent tpes of ,atastructure/ 

(! Marks)

(Ans)he fundamental data types (char! int! float! double!$oid) can be "rouped to"ether and treated as a unit. his"rouped unit is a data structure.Hata structures ha$e been classified into two cate"ories

&i'ple ata &tr*tre – these are built usin" the fundamental data types i.e. char! int! float anddouble.

3%amples arrays and structureso'pon, ata &tr*tre – these are built usin" simple data structures. hese are further di$ided into – linear and nonlinear.

inear ,ata str*tres are those whose elements form a se-uence. 3%amples – Etac;s! Uueues and Rin;edRists.

4on-7inear ,ata structures are those whose elements are at ifferent levels. #xampleD trees.$escribe in brief( the ,ifferent operations that are performe, on an arra/ 

(! Marks)

(Ans)he basic operations performed on arrays are – 

.ra/ersing  $isitin" each element for some processin". 

&ear*hing – tra$ersin" the array to see if a certain "i$en $alue e%ists in it or not. wo commonly used methodsare – Rinear Eearch and inary Eearch. Rinear search can be used on unsorted arrays. inary Eearch is doneonly on sorted arrays.

0nsertion – his can be done if there is space a$ailable in the array. In an unsorted array! the new element can be placed at the end. If the array is sorted! the element is "i$en its proper position in the sorted se-uence! byshiftin" other elements.

eletion If the element to be deleted e%ists in the array! then the element should be remo$ed and the elementsthat follow shifted so that the rest of the se-uence remains undisturbed.

&orting  Array elements may be arran"ed in ascendin" or descendin" order. Eome sortin" techni-ues are

 bubble sort! selection sort! insertion sort! shell sort! heap sort! -uic; sort.

Merging – two arrays may be combined to form a third array. If the two arrays are sorted! then usin" mer"e –

sort techni-ue! we can create the third array! sorted.Write a function linear#) that accepts an integer arra an, the value to search

an, returns the position at which it is foun,#if foun,)( using the 7inear earchtechniue/ 

(! Marks)

(Ans)int linear(int A O P, int n)Rint i, pos < D+Qfor(i<?Q i S +? Q i;;)if(AO i P << n)Rpos < i;+Qbrea%Q

U

Page 63: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 63/102

return posQU Write a function binar#) that accepts an integer arra an, the value to searchan, returns the position at which it is foun,#if foun,)( using the Binar earchtechniue/ 

(! Marks)

(Ans)int binary(int AO P, int n)int pos, l, u, mQ 

pos<D+Ql<?Qu<\Qwhile(l S< u)Rm<(u ; l)BJQif(AOmP<<n)Rpos<m;+Qbrea%QU

if(AOmPn)u<mD+Qelseif(AOmP S n)l<m;+QUreturn posQ

U

3ow can a value be inserte, into an arra? $escribe the ,ifferent was/ Givethe algorithm for an one/ 

(# Marks)(Ans)Insertion of another $alue can be done if there is space a$ailable in the array. If the array is unsorted i.e.elements are not placed in any particular se-uence! the new element can be made the last element. If the array issorted! the element must be "i$en its proper position in the sorted se-uence.

Algorith' or 0nsertion in a &orte, Arra2 3 As*en,ing or,er

/. E3 i 6 7 

1. +33A E3 < AE RN, AE AP i Q @ Sal

<. I# AP i Q @ Sal T3N

i 6 i & /5

B. E3 pos 6 i5

. E3 i 6 L

=. +33A E3 F LNIR i 6 pos

F. 4 AP i Q 6 AP i/ Q5

i 6 i – /

8

D. AP pos Q 6 Sal5

G. 3NH

Write a program that ,eletes all occurrences of a value from an integer arra%V8> an, shifts the rest of the elements to the right/ 

Page 64: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 64/102

(# Marks)

(Ans) BB to elete all occurrences from sorte array an shift rightXinclue S iostream.hXinclue S conio.hvoi main()Rclrscr( )Qint i, , %, n, pos, AOJ?PQcoutSS&n#nter integers for the array, in ascening orer&Qfor(i<?QiS J?Qi;;)cinAO i PQcoutSS&n#nter integer to elete 2 &QcinnQ% < ?Qpos < D+Qfor(i<?Q i S J?Q i;;)Rif (AO i P << n)R BB if foun, shift all in front, bac%pos < iQ

for(<posQ ?Q DD)AO P < AO D + PQAO % P < ?Q;;%QUUif (pos<<D+)coutSS&n ot foun in array n&Qfor(i<?Q i S J?Q i;;)coutSS AO i PSS G GQgetch()Q

U

Write a program to ,ispla the sum of elements on both the ,iagonals in a8,imensional arra/ 

(# Marks)

(Ans)

99 o display sum of both dia"onals separatelyJinclude @ iostream.hKJinclude @ conio.hK

$oid main()4

clrscr()5int i! >! *PBQPBQ! sl 6 7! sr 6 75cout@@n3nter inte"ers for the array5for(i675 i @ B5 i&&) 99 accept /= nos. into array *

for(>675 > @ B5 >&&)4cinKK*P i Q P > Q5cout@@n Eum of left dia"onal 6 58for(i675 i @ B5 i&&) 99 add left dia"onal

4sl 6 sl & *P i Q P i Q5cout@@ sl5

cout@@n Eum of ri"ht dia"onal 6 58

Page 65: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 65/102

for(i675 i @ B5 i&&)99 add ri"ht dia"onalfor(>675 > @ B5 >&&)4

if( i &> 66 <)sr 6 sr & *P i Q P > Q5cout@@ sr5

88

) Write a program to accept integers into a ; ,imensional arra an, then place

all the even numbers before all the o,, numbers/ (# Marks)

(Ans) BB to shift even nos before oXinclue S iostream.h 

Xinclue S conio.hvoi main()Rclrscr()Qint i, , AO+?P, "O+?PQcoutSS&n#nter integers for the array&Qfor(i<?Q iS+?Q i;;) BB accept +? elements into array AcinAO i PQ

 <?Qfor(i<?Q iS+?Q i;;)R BB place even nos. in array "if(AO i P_J<<?)R"O P < AO i PQ;;QUUfor(i<?Q i S +?Q i;;)R BB place o nos. in array "

if(AO i P_J<<+)R"O P < AO i PQ;;QUUfor( i<?Q iS+?Q i;;) BB copy array " to array AAO i P < "O i PQfor(i<?QiS+?Qi;;) BB isplay array AcoutSS AO i PSS G GQ

U

Write a program to accept integers into a 8$ arra an, then replace all theelements below the ,iagonal with >/ 

(# Marks)

(Ans)

 BB To replace elements below left iagonal with ?sXinclue S iostream.hXinclue S conio.hvoi main()Rclrscr()Qint i, , 8O-PO-PQcoutSS&n#nter integers for the array&Qfor(i<?Q i S -Q i;;) BB accept +I elements into array

Page 66: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 66/102

for(<?Q S -Q ;;)cin8O i P O PQfor(i<?Q i S -Q i;;) BB assign ? if below iagonalfor(<?Q S -Q ;;)Rif ( i )

R8O i P O P < ?QcoutSS &n >inal Array n&QUUfor(i<?Q i S -Q i;;)RBB isplay final arrayfor(<?Q S -Q ;;)Rcout SS 8O i P O PSS & &QcoutSS&n&QU

UU

What is merge-sort? Write a program to merge-sort 8 arras into a thir, one/The two arras are sorte, in ,escen,ing or,er an, the resultant arra shoul,

be in ascen,ing or,er / (" Marks)

(Ans)Mer"e – sort is when two sorted arrays are mer"ed to create the third array which is also sorted.In this techni-ue! the current $alues of the two arrays are compared and the one smaller is put into the new array.

he mar;er in the array used mo$es ahead one element. A"ain the current elements of the two arrays arecompared and the smaller $alue put into the new array. his process continues till one of the arrays ends andthen the remainin" elements of the other array are placed in the new array.

99Mer"e sort ascendin" with component arrays in descendin" order 

Jinclude @ iostream.hK

$oid main()4

int ia! ib! ic! AP=Q! P=Q! CP/1Q5

cout@@n3nter = inte"ers! in desc order 5 99first array

for(ia675 ia @ =5 ia&&)

cinKKAP ia Q5

cout@@n3nter = more inte"ers! in desc order 5 99 second array

for(ia675 ia @ =5 ia&&)

cinKKPiaQ5

for(ia6!ib6!ic675 iaK67 VV ibK675 ) 99 creation of third array

4

if(APiaQ K PibQ)4

CPicQ 6 PibQ5

&&ic5

ib5

8

else4

Page 67: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 67/102

CPicQ 6 APiaQ5

&&ic5

ia5

8

8 99 end of for loop

if(ia @ 7)

while(ibK67)4

CPicQ 6 PibQ5

&&ic5

ib5

8

if(ib @ 7)

while(ia K6 7)4

CPicQ 6 APiaQ5

&&ic5ia5

8

cout@@n Mer"ed Array n5

for(ic675 ic@/15 ic&&)

cout@@ CPicQ@@ 0 05

8 99 end of main function

Structured %uer& 'an"ua"e

Write a uer on table H2+ to ,ispla output as below-Hmp4ame is on +ro9ect +ro9&o,e 5aman is on +ro9ect $el;;8aran is on +ro9ect Zai;88

(1 Mark)

(Ans)1#*#7T #mpame, N is on 5roect N, 5ro7oe >6'M empQ

What is $ata $ictionar? (1 Mark)

(Ans)A 4ata 4ictionary is a atabase containing ata about all the atabases an obectstherein, that ma%e up a atabase system. /t is often thought of as Eata about the ataFor EmetaataF.What is 4L77? 

(1 Mark)

(Ans)ull is a %eywor implying an empty value. Two W**s cannot be ae, subtracte orcompare. A W** can not be euate with ? or blan% spaces. To use in uery, write asbelow 3

1#*#7T C>6'M stuent@$#6# grae /1 W**Q

Page 68: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 68/102

Write a uer on table H2+ to ,ispla output as below-

Hmp4ame is on +ro9ect +ro9&o,e 5aman is on +ro9ect $el;;8aran is on +ro9ect Zai;88 

(1 Mark)

(Ans)1#*#7T #mpame, N is on 5roect N, 5ro7oe >6'M empQGive the statement to ,ispla the number of emploees with 9ob as &ler: fromtable H2+7.!HH/ 

(1 Mark)

(Ans)1#*#7T 7'WT(#mpame) >6'M employeewhere `ob < N7ler%9Q 3ow is pattern matching carrie, out using [7 statements? 

(1 Mark)

(Ans)

*/K# searchescharacter ata to see if any part of it matches a pattern. The characterpatternDmatching operation is calle wilcar search. Two symbols are use to ma%e thesearch string3 _(5ercent) D it represents any seuence of zero or more characters.

 (Wner 1core) D it represents any single character.To loo% at the etails of all stuents whose name starts with NA9 we can give2

1#*#7T C >6'M stuent@$#6# name */K# NA_9 Q

'utput 36'**' AM# MA6K1 !6A4# 7*A11J An%ur .0 A 8// A

H Abhinav I0.0 " 8// A

The uery gives NA_9 as a pattern to match in column name D NA9 which may be followeby any character.To loo% at the etails of all stuents whose name starts with one un%nown letter that isfollowe by Naurav9 we can give 3

1#*#7T C >6'M stuent@$#6# name */K# Naurav9Q

'utput 36'**' AM# MA6K1 !6A4# 7*A11\ !aurav . A 8// "

++ 1aurav . " 8// 7The unerscore character, N9, represents one character, followe by Naurav9. O4 WBDP

What is 4L77 ? (1 Mark)

(Ans)ull is a %eywor implying an empty value.Two W**s cannot be ae, subtracte orcompare. A W** can not be euate with ? or blan% spaces.To use in uery, write as below 31#*#7T C>6'M stuent @$#6# grae /1 W**QGive the statement to ,ispla the number of emploees with 9ob as &ler: fromtable H2+7.!HH ? 

(1 Mark)

(Ans)1#*#7T 7'WT(#mpame) >6'M employee where `ob < N7ler%9 Q

Page 69: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 69/102

Give the [7 statement to create a table H2+7.!HH with the structure as givenbelow -

 Hmp&o,e O ,igit number Hmp4ame up to ;> characters longZob up to ;> characters longalar Q ,igits inclu,ing 8 ,ecimal ,igits+ro9&o,e P characters 

( Marks)

(Ans)76#AT# TA"*# employee (#mp7oe number(-), #mpame varcharJ(+?), `obvarcharJ(+?), 1alary number(,J), 5ro7oe varcharJ(I))Q3ow can a table be create, from an existing table ?  

( Marks)

(Ans)A new table can be create from an existing one by using the 76#AT# an 1#*#7Tstatements in a uery.#xample 2&5H%TH T%B7H newtab % # H7H&T Hmp&o,e( +ro9&o,e '5.2 emplo W3H5HZob 1 2anager)Table newtab will have J columns, #mp7oe an 5ro7oe, an ata pic%e up from rowswhere `ob was Manager, in the table employ./f the @$#6# clause is left out, ata fromall the rows will be inserte.

$escribe the +rimar Ke constraint use, on a table ? 

( Marks)(Ans)The 5rimary Key uniuely ientifies each row. /t can not have W** values or repeatevalues in it. A table can have only one 5rimary Key. @hen it is place as a constraint ona column (or a set of columns), the column has to store values in %eeping with theserules.#xample 2 76#AT# TA"*# stuent (rollno number (J) 'T W** 56/MA6: K#:, namechar(+0), mar%s number(0,+), grae char(+), class char(0))Q3ow can rows be inserte, into a table from another table ? 

( Marks)

(Ans)4ata rows are ae to atable using the /1#6T comman./1#6T comman can also be

use to ta%e values from one table an a them to another. /n place of the valuesclausean appropriate uery is given an the resulting rows are ae into the target table.

#xample 2 4H5T 4T.temp H7H&T name( class '5.2 stu,ent W3H5Hmar:sNQ<

$ere, rows where mar%s 0 will be consiere from table 1TW4#T an the AM# an7*A11 columns will be inserte into table T#M5.To insert using a uery, %eep in min that 2(i) "oth the tables must be alreay create.(ii)The columns of the tables being inserte into, must match the columns output by thesub uery. 

$escribe the +rimar Ke constraint use, on a table/  ( Marks)

Page 70: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 70/102

(Ans)The 5rimary Key uniuely ientifies each row. /t can not have W** values or repeatevalues in it. A table can have only one 5rimary Key. @hen it is place as a constraint ona column (or a set of columns), the column has to store values in %eeping with theserules.

#xample 276#AT# TA"*# stuent (rollno number (J) 'T W** 56/MA6: K#:,name char(+0), mar%s number(0,+), grae char(+), class char(0))Q$escribe the .r,er B clause/ 

( Marks)

(Ans)The '64#6 ": clause allows you to impose an orer on your output. Wsing this clausewill isplay your uery results in a sorte manner, by one or more columns. The sortingcan be one either in ascening or escening orer,ascening being the efault orer.@hen writing the uery, it is generally place last.

The example below 31#*#7T name, mar%s>6'M stuent'64#6 ": mar%sQ isplays output as 3AM# MA6K1

"ri I?.0Abhinav I0.0!aurav .4hruv \.0An%ur .0

The output is in ascening orer of mar%s.

1#*#7T C>6'M stuent

'64#6 ": name 4#17QThe above uery isplays ata in escening orer of names, alphabetically.

$escribe the 3aving clause/ ( Marks)

(Ans)The $AL/! clause places conitions on groups in contrast to @$#6# clause that placesconitions on iniviual rows. @hile @$#6# conitions cannot inclue aggregatefunctions, $AL/! conition can.

1#*#T !rae, MA8 (mar%s) 

>6'M stuent!6'W5 ": grae

$aving MA8 (mar%s)0QWhat is the ,ifference between W3H5H an, 3%U4G clause? 

( Marks)

(Ans)The $AL/! clause places conitions on groups in contrast to @$#6# clause that placesconitions on iniviual rows. @hile @$#6# conitions cannot inclue aggregatefunctions, $AL/! conition can o so.

This meanswe can not o some thing li%e the followingD 1#*#7T !rae, MA8(mar%s)>6'M stuent

@$#6# MA8(mar%s)0

Page 71: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 71/102

!6'W5 ": !raeQ@$#6# woul apply to iniviual rows li%e 3

1#*#7T !rae, mar%s>6'M stuent

@$#6# mar%s0 QTo see the maximum mar%s for each grae, if over 0, you woul use the $AL/!

clause. The $AL/! clause efines the criteria to select the output of certain groups.1#*#T !rae, MA8(mar%s)>6'M stuent!6'W5 ": grae

$aving MA8 (mar%s)0Q3ow is a table ,elete,? Ln,er what con,ition can a table be ,elete,?

( Marks)

(Ans)@e can not elete a table until it is empty as we can elete only empty tables. @e canremove the entire table using 46'5 TA"*# comman.'nce a table is remove, it cannotbe retrieve. The comman to remove the table stuent permanently from the atabaseis2

46'5 TA"*# stuentQGive the [7 statement to create a table H2+7.!HH with the structure as givenbelow -

Hmp&o,e O ,igit number Hmp4ame up to ;> characters longZob up to ;> characters longalar Q ,igits inclu,ing 8 ,ecimal ,igits

  +ro9&o,e P characters ( Marks)

(Ans)76#AT# TA"*# employee(#mp7oe number(-), #mpame char(+?),`ob char(+?), 1alary number(,J),5ro7oe char(I))QWhat is the ,ifference between – count#)( count#F)( count#co,e)(count#$T4&T ,ept) an, count#%77 ,ept)? 

( Marks)

(Ans)The functions can be istinguishe as follows2 

/. count() 3 is a function to count, it nees an argument. 1. count(C) 3 to count the number of rows in a table. 

<. count(coe) 3 to count the number of nonDnull values in column coe. B. count(4/1T/7T ept) D to count the number of istinct entries, i.e. to count a

particular entry only once even if it appears many times. 

. count(A** ept) 3 to count the number of nonDnull values in column ept, i.e.counting repetitions too. 

Give the statement to a,, a row of ,ata to table H2+7.!HH as given-%;>; as Hmpco,e( ham as Hmpname( &ler: as Zob( <>>> as alar an,

7L&888 as +ro9&o,e/  ( Marks)

Page 72: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 72/102

(Ans)/1#6T /T' employee (#mp7oe, #mpame, `ob, 1alary, 5ro7oe) LA*W#1 (NA+?+9,

 N1hyam9, N7ler%9, 0???, 9*W7JJJ9)Q

3ow can rows be inserte, into a table from another table?  ( Marks)

(Ans)4ata rows are ae to a table using the /1#6T comman. /1#6T comman can alsobe use to ta%e values from one table an a them to another. /n place of the valuesclause an appropriate uery is given an the resulting rows are ae into the targettable.

#xample 2/1#6T /T' temp1#*#7T name, class>6'M stuent@$#6# mar%s0Q

$ere, rows where mar%s 0 will be consiere from table 1TW4#T an the AM# an7*A11 columns will be inserte into table T#M5.

To insert using a uery, %eep in min that 2(i) "oth the tables must be alreay create.(ii)The columns of the tables being inserte into, must match the columns outputby the sub uery.

3ow can a table be create, from an existing table? ( Marks)

(Ans)A new table can be create from an existing one by using the 76#AT# an 1#*#7T

statements in a uery. #xample 2 

76#AT# TA"*# newtab A1(1#*#7T #mp7oe, 5ro7oe >6'M employ @$#6# `ob < NManager9 )QTable newtab will have J columns, #mp7oe an 5ro7oe, an ata pic%e up from rowswhere `ob was Manager, in the table employ. /f the @$#6# clause is left out, ata fromall the rows will be inserte.3ow is a table ,elete,? Ln,er what con,ition can a table be ,elete, ? 

( Marks)

(Ans)

'nly empty tables can be elete.@e can remove the entire table an once remove, thetable cannot be retrieve.The comman to remove the table stuent permanently fromthe atabase is 2$5.+ TA"*# stuentQ

What are $$7( $27 an, $&7 ? (! Marks)

(Ans)$ata $efinition 7anguage #$$7) is one of the maor components of the 1tructureuery *anguage (1*). /t is use to create ata structures li%e atabases, tables, viewsan inexes. 1ome of the commans comprising 44* are 76#AT# TA"*#, 46'5 TA"*#

an 76#AT# /4#8.$ata 2anipulation 7anguage #$27) is a category of 1* use to manipulate ata 3

Page 73: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 73/102

uery, insert, upate etc. #xamples of 4M* commans are 1#*#7T, /1#6T, 4#*#T# .$ata &ontrol 7anguage #$&7) is a subset of 1*, use to control access to ata in aatabase. #xamples of 47* commans inclue2!6AT D to allow specifie users toperform specifie tas%s, 6#L'K# to cancel previously grante or enie permissions.What is a view? 3ow is it ,ifferent from a table? What are the a,vantages ofusing views? 

(! Marks)(Ans)A view is a logical table that contains no ata of its own. /ts contents are ta%en fromother tables through the execution of a uery. As the values is those tables change, soautomatically, will the values in the view.

The table on which a view is base is calle a base table. Liews are li%e winows throughwhich you view information that is actually store in a base table.Avantages of using a L/#@ 3• Liews isplay ata selectively an so restrict access to ata• Liews are use to get results of complicate ueries, especially where multiple tables

are use.• 'ne view can be use to isplay ata from several tables.

What are the ,ifferent operators an, how are the use, in [7 statements? (! Marks)

(Ans)At times you woul li%e to see only certain rows accoring to your reuirement instea of all the rows all the time. The @$#6# clause lets you give a conition which restricts therows. @hile specifying the conition, operators are use. There are three types of operators 3

♦ 6elational 'perators♦ *ogical operators♦ 1pecial operators

+elational perators are used for comparison between two $alues.'perator Meaning

< #ual to

!reater than

< !reater than or eual to

S *ess than

S< *ess than or eual to

S ot eual to#xample1#*#7T C >6'M stuent@$#6# mar%s0Q$ere output rows will be selecte base on the conition mar%s0, being a relationaloperator.Ro"ical perators are used to combine two or more conditions to produce a sin"le result. he

conditions are e$aluated to rue or #alse and a row is considered only if the final result is

rue. Ro"ical operators may also be used to ne"ate the results of a sin"le condition.

'perator Meaning

A4 6eturns True if both component conitions are True

'6 6eturns True if any one component conition is True'T 6eturns True if the conition is >alse

#xample1#*#7T C >6'M stuent@$#6# grae<9A9 A4 class<98// A9Q

Page 74: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 74/102

$ere the first conition is grae < NA9 an the secon conition is class<98// A9. The A4between them means that all the rows for which both conitions are true will be part ofthe result.#xample1#*#7T C >6'M stuent@$#6# grae<9A9 '6 class<98// A9Q

$ere the first conition is grae < NA9 an the secon conition is class<98// A9. The '6between them means that all the rows for which any one conition is true will be part ofthe result.#xample1#*#7T C >6'M stuent@$#6# 'T grae<9A9$ere the conition grae < NA9 is to be negate. The rows where grae is not NA9 are seenin the output.Epecial operators are used to "i$e other comparison conditions.

'perator Meaning

"#T@## YA4 Y

"etween two values (inclusive)

/ (set) Match any value in the list

*/K# Match a character pattern/1 W** /s a null value

Wsing "#T@##2D /t isplays rows base on a range of values.#xample

1#*#7T C >6'M stuent@$#6# mar%s "#T@## 0 A4 \?Q

The output will be rows that have the value for column mar%s between 0 an \?.Wsing /2D /t tests for a value in a specifie set of values.#xample1#*#7T C >6'M stuent

@$#6# name /(N"ri9, N4hruv9, NAnu9, N1urbhi9)QThe output rows have the value in column name as one of those given in the list withinparenthesis.Wsing */K#2D */K# can be applie only to columns of 7$A6 atatype. */K# searchescharacter ata to see if part of it matches a pattern . Two symbols are use to ma%e thesearch string 3_(5ercent) D it represents any seuence of zero or more characters.

 (Wnerscore) D it represents any single characterTo loo% at the etails of all stuents whose name starts with NA9 we can give 3

1#*#7T C >6'M stuent@$#6# name */K# NA_9Q

$ere we have specifie only NA9 which may be followe by any character, as implie bythe _ sign.To loo% at the etails of all stuents whose name starts with an un%nown letter but isfollowe by Naurav9 we can give 3

1#*#7T C >6'M stuent@$#6# name */K# Naurav9QWhat is a &onstraint ? $iscuss the ,ifferent constraints in brief ? 

(" Marks)

(Ans)Constraint is a restriction or a chec; that is applied to the columns of the table. hey pre$ent in$alid data entryinto tables as the data they store must satisfy the chec;s or conditions placed. Constraints are specified when thetable is defined. Constraints may be defined at the column le$el or the table le$el.

&o'e *o''onl2 se, *onstraints that 'a2 be applie, are 3 'T W** D column cannot contain null values 

W/W#D value must be uniue in all rows

Page 75: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 75/102

Page 76: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 76/102

place in context, it becomes meaningful an it becomes /nformation. A 4atabaseManagement 1ystem or 4"M1 is a software system that allows access to ata containein atabases./t provies an effective an convenient metho of storing, retrieving anupating information.6hat are the ,ierent ,ata 'o,els ?

(1 Mark)

(Ans)4ifferent ata moels escribe how ata structures may be efine an atarelationships an constraints maintaine. The three most wiely accepte ata moelsare the 6elational, etwor% an $ierarchical moels.

What are the a,vantages of using $B2 ?

( Marks)

(Ans).he a,/antages pro/i,e, b2 a 5M& are 3  /.+eduction of +edundancy.Lnnecessary duplication of data is a$oided.It reduces the e%tra stora"e re-uired!eliminates the e%tra processin" in$ol$in" lar"e masses of data! eliminates inconsistencies which can e%ist inmultiple copies.

1.Eharin" of Hata. he database allows sharin" of data by se$eral users.<.Inte"rity of Hata Maintainedhis means that data is accurate and consistent.Chec;s can be built in to ensuredata is correct.B.Inconsistency of Hata Controlled.his is lin;ed closely to minimi2in" redundancy sharin" of data..Eecurity of Hata Maintained.Confidential data must not be accessed by unauthori2ed persons so!access of data by different users can be controlled.

=.Hata Independence. he way data is stored in the database does not affect access of data from the database.

$escribe the ,ifferent Kes in a relation? ( Marks)

(Ans)Keys are of the following types D

5rimary Key 3 A column (or columns) in a table that uniuely ientifies each row.Aprimary %ey value is uniue an cannot be null.There is only one primary %ey for a table.>oreign %ey DA column (or a set of columns) that refers to the primary %ey in anothertable i.e. it is use as a lin% to a matching column in another table.7aniate %ey D A column (or columns) that uniuely ientifies rows in a table. Any ofthe ientifie caniate %eys can be use as the tableGs primary %ey. Any of thecaniate %eys that is not part of the primary %ey is calle an alternate %ey.

What are the a,vantages of using $B2? ( Marks)

(Ans)

The avantages provie by a 4"M1 are 3/. 6euction of 6eunancy'Wnnecessary uplication of ata is avoie. /t reuces theextra storage reuire, eliminates the extra processing involving large masses of ata,an eliminates inconsistencies which can exist in multiple copies.J. 1haring of 4ata2D The atabase allows sharing of ata by several users.H. /ntegrity of 4ata Maintaine2D This means that ata is accurate an consistent.7hec%s can be built in to ensure ata is correct.-. /nconsistency of 4ata 7ontrolle2D This is lin%e closely to minimizing reunancysharing of ata.0. 1ecurity of 4ata Maintaine2D 7onfiential ata must not be accesse by unauthorizepersons so, access of ata by ifferent users can be controlle.I. 4ata /nepenence2D The way ata is store in the atabase oes not affect access of 

ata from the atabase.

Page 77: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 77/102

$escribe the 4etwor: ,ata mo,els in brief ? ( Marks)

(Ans)In this data model! data is represented by a collection of records and the relationships are represented by lin;s.3ach record is a collection of fields (attributes) each of which contains only one data $alue. A lin; is anassociation between two records.

3ow is the select operation use, ? ( Marks)

(Ans)Eelect operation selects tuples(rows) that satisfy a certain condition(or predicate)! from a relation.It "i$es ahori2ontal subset from the relation where each row satisfies the "i$en condition.he select operation is denoted

 by the small ,ree; letter si"ma.

If we write! EalesK1777(EAR3EM3N) the result will be those rows from relation EAR3EM3N where Ealesis more than 1777.

3ow is a ,atabase management sstem ,ifferent from a file processingsstem?

( Marks)

(Ans)In a file processin" system! data is stored in $arious files.In order to access or modify the data

in these files! pro"rams ha$e to be written. Eome problems that commonly arise in such

systems are data redundancy! data inconsistency! loss of data inte"rity! incorrect data!

insecure data and data that is not accordin" to set standards. he database mana"ement

system is inherently for sharin" of data and pro$ides controls so that the problems

encountered in the earlier mentioned system are eliminated or minimi2ed.

Hxplain the terms – 5elation( Hntit( $omain( $egree ? ( Marks)

(Ans)Relation – it is a table! with rows and columns to store data.

4ntit2 – it is somethin" that e%ists! for which data is stored.#or e%ample a person! place! department etc.

o'ain – it is the set of permitted entries in a column.#or e%ample!a column CRL+! may ha$e the domain4red! "reen!blue8 where these are the only permitted $alues.

egree 3 it is the number of columns (or attributes) in a table. 

3ow is the pro9ect operation use, ?

( Marks)

(Ans)he ro>ect operation selects attributes(columns) from a relation. It is denoted by the ,ree; letter pi i.e. Z. heresult is a $ertical subset of the "i$en relation. Any duplicate rows are automatically remo$ed. he columnsappear as subscript to Z and the table name appears in parenthesis.

If we write!

Z Zone, Sales (1A*#1M#)

the result woul be, columns =one an 1ales of the relation 1A*#1M#. The columnsappear in the result in the same orer in which given in the proection expression. 

6hat is 'eant b2 nion-*o'patible?

( Marks)

Page 78: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 78/102

(Ans)The union operation reuires two relations an prouces another relation that containstuples from both the relations. >or this operation, both relations must be unioncompatible. This means both relations must have the same number of attributes(columns) or egree. The omains of the i th attribute of the first relation an theomains of the ith attribute of the secon relation must be the same for all i.Breif out ,ifferent ,ata mo,els ?

( Marks)

(Ans)'ut the three ata moels, the $ierarchical moel is the olest./t has been in use onmainframe computers involving, large uantities of ata an lot of ata processing.Theetwor% moel is preferre if the user or the eveloper is to be given control over theata storage.The 6elational moel is preferre by people who feel that the mechanismsto access ata must be hien from users, an the system must be easy to unerstanan construct.%re there an ,isa,vantages of using a ,atabase ?

( Marks)

(Ans)1ince ata sharing is an integral part of the atabase, some problems may arise ifcontrols are not properly built into it. 1ome issues that nee special attention in thisregar are maintaining ata security an maintaining ata integrity. 1ystem harwarean operational costs may be high.*arge systems maybe complex complicate tomaintain.What are views ?

( Marks)

(Ans)Liews are virtual tables. They only exist as ata erive from tables on which they arebase.A view is not store as a table, rather, only its efinition is store./t is an excellentway to restrict ata access to people. 

Hxplain the et $ifference .peration ?( Marks)

(Ans)Wsing the set ifference operation we can fin tuples that exist in one relation but in theother. /t is represente by the 3 (minus) sign. 7onsier th example below. The twotables are A an ". The operation A 3 " gives another relation which is the result of thisoperation.The two relations must be compatible i.e. of the same egree an the omainsof the corresponing columns must be the same.A "

The result of A D " is

Hxplain the et ntersection .peration ? ( Marks)

(Ans)Wsing the set intersection operation we can fin tuples that are common to two relations./t is represente by the ∩ sign. 7onsier th example below. The two tables are A an ".The operation A ∩ " gives another relation which is the result of this operation. /t is thesame as writing A 3 (A 3 "). The two relations must be compatible i.e. of the sameegree an the omains of the corresponing columns must be the same.A "

7lass ame Age// A1$/1$ /// 6A`AT

7lass ame Age/// 5W/T

Page 79: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 79/102

The result of A ∩ " is

3ow is ,ata securit ensure, in a ,atabasemanagement sstem ?

( Marks)

(Ans)4ata is vital to any organization an some of it may be confiential. 7onfiential atamust not be accesse by unauthorize persons.A atabase management system hasauthentication schemes lai own, giving ifferent levels of users ifferent permissionsto access ata. Accoring to this, user may be allowe moify the ata or simply rea itwithout ma%ing any changes.The ata that can be seen is also controlle .$escribe the 3ierarchical ,ata mo,el in brief ? 

(! Marks)

(Ans)

In the Tierarchical data model too data is represented by a collection of records and the relationships arerepresented by lin;s! somewhat similar to the Networ; model. 3ach record is a collection of fields (attributes)each of which contains only one data $alue. Tere! howe$er! records are or"ani2ed as tree instead of arbitrary"raphs.

he fi"ure below shows a possible $iew of a database.

he record at the top of the tree is called the root.perations li;e retrie$al! deletion! modification etc. are

 performed throu"h a data manipulation lan"ua"e.What is &artesian pro,uct ?

(! Marks)

(Ans)Cartesian product is denoted by the X% si"n. he Cartesian product of two relations r/ and r1 is written as r/ %r1. he resultin" relation has columns from both the tables and rows that "i$e all possible combinations of rows between the two tables. he number of attributes in the resultin" table is the sum of the number of attributes in both the tables. he number of tuples in the resultin" table is the product of the number of tuples in both the

tables. 

able I3M below has < attributes able ELRI3+ below has1

attributesand

tuples.and< tuples.

If we write

I3M %ELRI3+ 

theresultin"

table! as below! has attributes(< & 1) and/ tuples

( : <)

7lass ame Age// A1$/1$ /// 6A`AT

7lass ame Age// A1$/1$

/// 6A`AT

+?D`WD? J?D`WD?

>4J?+ `AMA/7A / 4A5$# 4A M#66/#6 +?

M+JJ MA4A JHJHJH--

/7oe /ame 5rice>0?0 >ruit 7a%e +??>I0 "anana "rea +0?>J?H @alnut 5ie J0?T+-0 1hampoo +J?T+0I `asmine 1oap H0

17oe 1ame1+?+ Aman 1uppliers

1JJH uality proucts1+-0 1uman [ 7o.

/7oe /ame 5rice 17oe 1ame>0?0 >ruit 7a%e +?? 1+?+ Aman 1uppliers>0?0 >ruit 7a%e +?? 1JJH uality proucts>0?0 >ruit 7a%e +?? 1+-0 1uman [ 7o.>I0 "anana "rea +0? 1+?+ Aman 1uppliers>I0 "anana "rea +0? 1JJH uality proucts>I0 "anana "rea +0? 1+-0 1uman [ 7o.>J?H @alnut 5ie J0? 1+?+ Aman 1uppliers>J?H @alnut 5ie J0? 1JJH uality proucts>J?H @alnut 5ie J0? 1+-0 1uman [ 7o.T+-0 1hampoo +J? 1+?+ Aman 1uppliersT+-0 1hampoo +J? 1JJH uality prouctsT+-0 1hampoo +J? 1+-0 1uman [ 7o.T+0I `asmine 1oap H0 1+?+ Aman 1uppliersT+0I `asmine 1oap H0 1JJH uality prouctsT+0I `asmine 1oap H0 1+-0 1uman [ 7o.

Page 80: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 80/102

$escribe the 5elational ,ata mo,els in brief ? (" Marks)

(Ans)In the +elational Hata Model data is or"ani2ed into tables with rows and columns.3ach column has a uni-uename and is called an attribute.A row of the table represents a relationship amon" a set of $alues.As the table isa collection of such rowsit has a close relationship with the mathematical concept of relation! from where thismodel ta;es its name. 

he e%ample below shows 1 tables of a database.

Etudent andAcademic '– Etudent(Admno! Name! hone! H! Ee%)Academic(Class! +ollNo! erm/! erm1! #inal)

Etudent

Academic

In the table Etudent! each student has a uni-ue admission number.Lsin" this number any row can be identified.

his column! Admno is therefore the primary ;ey in the table.he table has four tuples (rows) and fourattributes (columns).Eimilarly! the other table has a primary ;ey (Class & +ollNo) that can identify each row ofthe table.hese tables can be used to insert more rows! modify data in the rows! delete unwanted rows and to-uery the tables.

Communication And (et)or* Concepts

What are the goals of 4etwor:ing? ( Marks)

(Ans)The main goals of networ%ing have always been to share resources an to provie a

meium for communications.haring 5esources 3 among these are inclue not only printers an fax machines, but

Admno Name hone Ee%

GF7/1 +a>at Mali; 11<B=F M

GF/17 +a>at Mali; 17=FDG #

GD7FD Waran Waushi; <B=1<B M

GD/77 rayatn Wumar 1=FDFDG M

Class +ollno erm/ erm1 #inal

DA /1 DG G7 G1

D /1 FD DD D=

FA < == F= F

GA /B DD DG DG

Page 81: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 81/102

other evices li%e moems an servers. 1oftware an ata on the server maybeaccesse an share by ifferent users. 5e,ucing &ost 3 it saves money to have a powerful server to store common files ratherthan have separate computers , each with its own set of files. 1haring other resourcestoo saves on cost.5eliabilit D /f a machine goes own, another can ta%e over. 7opies of important files

can be maintaine easily.pee, D >ast communication of ata an messages.

What is R> – 8> rule of 4etwor: ,esigning? ( Marks)

(Ans)/n a properly esigne small to meiumDsize networ%, ? percent of the traffic on agiven segment shoul be local, an not more than J? percent shoul nee to moveacross a bac%bone lin%.

Give 8 a,vantages an, 8 ,isa,vantages of wireless communication/ ( Marks)

(Ans)@ireless communication oes not use a meium, li%e cables, for transmission. There areavantages an isavantages of this moe.%,vantages 3 +. 7an be use where cable or wires cannot be lai 3 over mountains,sea etc. J. Allows mobility, communication can generally be from anywhere, anytime$isa,vantages 3 +. /t is not secure as anyone with the right receiver can catch thesignalsJ. 1ensitive to atmospheric conitions, li%e rain, storm etc.

What is cbercrime? &berlaw?  ( Marks)

(Ans)&bercrime is criminal activity one using computers an the /nternet. This incluesanything from illegally ownloaing music files to stealing sensitive ata.&ber law (or &berlaw) escribes the legal issues relate to use of informationtechnology. 1ome topics it covers inclue intellectual property, privacy, freeom ofexpression, an urisiction.3ow is e-mail ,ifferent from chatting? 

( Marks)

(Ans)#mail or electronic mail is a way of sening electronic messages using the computer an

over a networ%. The recipient oes not have to be online for the email to reachsuccessfully. $eBshe can rea the mail when he is online.7hatting is textual conversation between J or more people who are simultaneouslyonline. This communication goes on in real time.Write a note on W77/ 

( Marks)

(Ans)@** (Wireless local loop) provies wireless communication from fixe locations suchas, homes or offices.The uality of service is very goo an it supports fax an moemcommunication, internet an can connect to a 5ublic 7all 'ffice. $ere, there is a wirelesslin% as the &last mile B first mile& to connect to the telephone service or to broabaninternet. The signal transmissions occur through the air over a terrestrial microwave

platform instea of through copper or fiber cables."ase stations are set up with multiDchannel transmitters an receivers an customers

Page 82: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 82/102

are provie an interface unit into which the telephone is connecte. @hen a call ismae, a signal is sent to the base station, an a connection is mae to allowcommunication. >or an incoming call, the base station ma%es a wireless connection angets the call through. The avantages of @** inclue the ability to connect with users, even in remote areaswithout the nee for laying new cables an the capacity for broa banwith that is not

impee by fiber or cable capacities.What are protocols? Give examples/ 

( Marks)

(Ans)

@hen computers communicate with each other, there nees to be a common set of rulesan instructions that each computer follows. A specific set of communication rules iscalle a protocol. "ecause of the many ways computers can communicate with eachother, there are many ifferent protocols, li%e, 555, T75B/5, 1*/5, $TT5, an >T5.

Transmission &ontrol +rotocol #T&+)( which uses a set of rules to sen an receiveinformation pac%ets with other /nternet points• nternet +rotocol #+)( which uses a set of rules to aress each message so itreaches the correct estination• 3pertext Transfer +rotocol #3TT+) which uses a set of rules to allowcommunication between a browser an server• 'ile Transfer +rotocol #'T+)( which uses a set of rules to allow transfer of files(uploaing an ownloaing) between the user9s computer an server

What is nterspace? ( Marks)

(Ans)

/nter1pace is an inicator of what the /nternet of the future will be li%e. /t has aclientBserver architecture an hosts multiple users, by incorporating realDtime auio anvieo communication that allows people to interact within a threeDimensionalenvironment./nter1pace can be use for istance learning, onDline shopping, gaming, an interactive&7yberD#vents&. /t provies a great way to meet an tal% to people from all over theworl.$escribe the client J server architecture/ 

(! Marks)

(Ans)"usinesses of various sizes have various computer nees. *arge businesses generallyhave large computer setups, such as mainframes an networ%s. The networ% usually has

a clientDserver architecture, which is a type of ivision of labour for computing.Wner the clientDserver architecture, the server functions as the &brains& of the networ%,serving a group of client computers, commonly calle wor%stations. The server will be alargeDcapacity computer, with a large amount of ata an application software store onit. The client computers are smaller an have to place reuests for ata an applicationsto the server, which then carries out these reuests.The /nternet revolves aroun the clientDserver architecture. :our computer runs softwarecalle the client an it interacts with another software %nown as the server locate at aremote computer. The client is usually a browser such as /nternet #xplorer, etscapeavigator or Mozilla. "rowsers interact with the server through protocols. Theseprotocols help in the accurate transfer of ata through reuests from a browser anresponses from the server.

What is the ,ifference between a web page( web site an, web portal? (! Marks)

Page 83: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 83/102

Page 84: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 84/102

cover networ% technologies incluing !1M, 74MA, @74MA, T4MA an @iMA8. Themobile networ% inustry is %een to aopt H! as it feels that multimeia base content isuic%ly becoming the norm. This inclues services li%e D Music ownloas ,MappingBnavigation, /nstant messaging, @eb surfing, #mail services an !aming.H! allows high banwith, pac%et base transmission at high ata rates. #4!#(#nhance 4ata rates for !lobal #volution) is an interface that will ma%e it possible for

H! evices to have high ata transfer rates.$iscuss vi,eo conferencing/ 

(! Marks)

(Ans)Through vieo conferencing, two or more people who are far apart can communicate inreal time, as though sitting face to face for a meeting. "esies the auio an visualtransmission of activities, vieoconferencing can be use to share ocuments, computerDisplaye information, an whiteboars.The core technology use in a vieoDteleconference system is igital compression ofauio an vieo streams in real time. The harware or software that performscompression is calle a coec (coerBecoer). 7ompression rates of up to +20?? can beachieve. The resulting igital stream of +s an ?s is subivie into labelle pac%ets,

which are then transmitte through a igital networ%.What is the ,ifference between worm an, virus? 

(! Marks)

(Ans)Liruses an worms are malicious programs that can cause amage to the computer, butthere are ifferences between them.A computer virus attaches itself to a file enabling it to sprea from one computer toanother, leaving infections as it travels.Almost all viruses are attache to an executable file, which means the virus may exist onyour computer but it actually cannot infect unless you run or open the maliciousprogram. 6emember, a virus cannot be sprea without a human action, such as runningan infecte program.A worm is similar to a virus by esign an is consiere to be a subDclass of a virus.@orms sprea from computer to computer, but unli%e a virus, it has the capability totravel without any human action. A worm ta%es avantage of file or informationtransport features on your system, which allows it to travel.The worm has the capability to replicate itself on your system, so your computer cansen out hunres of copies of the worms instea of a single worm, creating aevastating effect. >or example, a worm can sen a copy of itself to everyone liste inyour eDmail aress boo%. Then, the worm replicates an sens itself out to everyoneliste in each of the receiverGs aress boo%, an this continues.A worm consumes too much system memory causing @eb servers, networ% servers aniniviual computers to stop responing.What is the ,ifference between nternet an, WWW? 

(! Marks)(Ans)'ften, people use the terms /nternet an @orl @ie @eb interchangeably, but they aretwo separate but relate things.

The /nternet is a massive networ% of networ%s, a networ%ing infrastructure. /t forms anetwor% in which any computer can communicate with any other computer as long asthey are both connecte to the /nternet. /nformation that travels over the /nternet oesso via a variety of N protocols9.

The @orl @ie @eb, or simply @eb, is a way of accessing information over the meiumof the /nternet. /t is an informationDsharing moel that is built on top of the /nternet.The @eb uses the $TT5 protocol to transmit ata. The @eb also utilizes browsers, such

as /nternet #xplorer or >irefox, to access @eb ocuments calle @eb pages that are

Page 85: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 85/102

lin%e to each other via hyperlin%s. @eb ocuments also contain graphics, souns, textan vieo.

The @eb is ust one of the ways that information can be istribute over the /nternet.The /nternet, not the @eb, is also use for eDmail, Wsenet news groups, instantmessaging an >T5. 1o the @eb is ust a portion of the /nternet, though a large one.

What is the ,ifference between G2 an, &$2%? (! Marks)

(Ans)!1M an 74MA are iffering technologies use for wireless communication. 'ne of thebasic things that ifferentiates !1M an 74MA is the way they hanle banwith anivie up the signals between multiple users.G2 (!lobal 1ystem for Mobile communication) uses a Time 4ivision metho. Thismeans that each evice on the local networ% is allocate a time slice where it &owns& thebanwith, an it can senBreceive its ata. /f there are available time slices in a givencycle, each phone woul then get +Bth of every cycle in which it coul sen an receivesignals. #ach user9s ata is igitize an compresse an sent in his own time slot. 4atais encrypte for security. The 1/M (1ubscriber /entity Moule) is an important

component of the !1M cellular evice an contains connection ata, memory for ataan applications, an a processor.&$2% (7oe 4ivision Multiple Access) is technology that was first use uring @orl @ar//. 74MA wor%s on the principle of 1prea spectrum.The ata is sent in small pieces over a number of freuencies available for use. #achuser9s ata is encrypte in a particular way an at the receiving en, ecrypting is oneto recover the actual signal.$escribe T&+J+/ 

(# Marks)

(Ans)The Transmission 7ontrol 5rotocol (T75) is one of the core protocols of the /nternet5rotocol suite, often simply referre to as T75B/5. Wsing T75, applications on ifferent

networ%e hosts can create connections to one another, over which they can exchangestreams of ata. The protocol guarantees reliable an inDorer elivery of ata fromsener to receiver. T75 provies connections that nee to be establishe before seningata. T75 connections have three phases2+.connection establishmentJ.ata transferH.connection terminationAt the receiver9s en, the T75 arranges the receive pac%ets in proper seuence aniscars uplicate pac%ets while at the seners en, T75 ma%es sure any lost oramage pac%ets are resent, so that the message is properly communicate.The /nternet 5rotocol (/5) is a ataDoriente protocol use for communicating ataacross a pac%etDswitche internet wor%.

/5 (/nternet 5rotocol ) is a connectionless protocol. This means that /5 oes not establisha hansha%e with connecte hosts in orer to start generating ata. The functions of /5can be simply put as2D $anling aress mapping for the transmitting an receiving hosts.D 7reating the most basic unit of transmission, a atagram. A atagram has a particularformat an size.What is the ,ifference between switch an, hub?

(# Marks)

(Ans)Although hubs an switches both lin% the 57s in a networ%, a switch is more expensivean a networ% built with switches is generally consiere faster than one built with hubs.@hen a hub receives a pac%et of ata at one of its ports from a 57 on the networ%, it

transmits the pac%et to all of its ports an, thus, to all of the other 57s on the networ%./f two or more 57s on the networ% try to sen pac%ets at the same time a collision is

Page 86: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 86/102

sai to occur. @hen that happens all the 57s have to go though a process escribe in71MAB74 to resolve the conflict. #ach #thernet Aapter has both a receiver an atransmitter. "ecause they have to operate at half uplex (ata flows one way at a time)an a hub retransmits ata from one 57 to all of the 57s, the maximum banwith is+?? Mhz an that banwith is share by all the 57Gs connecte to the hub. The result is,when a person ownloas a large file from another computer, the networ% becomes

congeste.Two computers can be connecte irectly together in an #thernet with a crossover cable.A crossover cable oesnGt have a collision problem. /t harwires the #thernet transmitteron one computer to the receiver on the other. 4ata can be sent in both irectionssimultaneously. The maximum available banwith is J?? Mbps, +?? Mbps each way,an there are no other 57Gs with which the banwith must be share.An #thernet switch automatically ivies the networ% into multiple segments, acts as ahighDspee, selective brige between the segments, an supports simultaneousconnections of multiple pairs of computers. @hen the switch receives a pac%et, it reasthe estination aress in the pac%et, establishes a temporary connection between thesource an estination ports, sens the pac%et on its way, an then terminates theconnection.

$ighDspee electronics in the switch automatically connect the ports from a seningcomputer to the receiving computer on a per pac%et basis. Multiple connections li%e thiscan occur simultaneously.

Define the following terms with respect to data communication

a) Datab) Signalsc) Signaling

d) Transmission #8 2ar:s)

(%ns) 

a) Data: A collection of facts in raw form that becomes information after processingb) Signals: Electric or electromagnetic encoding of datac) Signaling: Propagation of signals across a communication mediumd) Transmission2 7ommunication of ata achieve by the processing of signals

List the similarities between FDDI and Token Ring.

#8 2ar:s)

(%ns) 

• DD! uses a rotating ring setup in the same wa" as does the to#en ring

protocol$

• DD!%s ring operation is basicall" &er" similar to the 'o#en ing earl"

release operation in the wa" that to#ens are passed on the networ#$

Page 87: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 87/102

List the 4 disadantages of network.

#8 2ar:s)

(%ns) 

• Ser&er faults stop applications from being a&ailable

• etwor# faults can cause loss of data

• etwor# fault could lead to loss of resources

• *ser wor# dependent upon networ#

!ompare star topolog" to bus topolog".#8 2ar:s)

(%ns) 

 As compared to the bus topolog", a star networ# re+uires more de&icesand cables to complete a networ#$ 'he failure of each node or cable in astar networ# wont ta#e down the entire networ# as happens in the -ustopolog"$.owe&er, if the central connecting de&ices such as hub, switch or routerfail due to an" reason, ultimatel" the entire networ# can come down or

collapse$

#$plain the characteristics of FDDI in brief.

#8 2ar:s)

(%ns) 

DD! stands for iber Distributed Data !nterface$ 'he DD! topolog"is ring with two counter/rotating rings for reliabilit" and with no hubs$0able t"pe is fiber/optic$ 0onnectors are speciali1ed$ 'he media accessmethod is to#en passing$ 2ultiple to#ens ma" be used b" the s"stem$'he ma3imum length is 455 #ilometers$ 'he ma3imum number of nodeson the networ# is 655$ Speed is 455 2bps$ DD! is normall" used as abac#bone to lin# other networ#s$ A t"pical DD! networ# can includeser&ers, concentrators and lin#s to other networ#s$%hat is the difference between broadcast and point&to&point'

#8 2ar:s)

(%ns) 

-roadcast meanswe aresending digital signals to an" de&ice connected

to a networ#$

Page 88: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 88/102

Point/to/point meansthat we aresending digital signals from a specificpoint to a specific point (identified b" !P address or 2A0 address)$%hat are the basic elements of a communication s"stem'

#8 2ar:s)

(%ns) 

'he following are the basic re+uirements for wor#ing of a communications"stem:4$ 'he sender (source) who creates the message to be transmitted7$ A medium that carries the message8$ 'he recei&er (sin#) who recei&es the messageList the differences between FDDI and Token Ring.

#6 2ar:s)

(%ns) 

•  As opposed to 'o#en ing%s single ring, DD! uses two toachie&e better results and less chance of failure$

• !n a basic 'o#en ing networ#, at an" instant, there is a single

acti&e ring monitor which supplies the master cloc# for the ring,whereas in DD!, this approach is not ideal because of the highdata rates$ !nstead, each ring interface has its own local cloc#and outgoing data is transmitted using this cloc#$

•€*nli#e the basic 'o#en ing which is based on the use of 

priorit" and reser&ation bits, the priorit" operation of the DD!

ring uses a principle that is based on a parameter #nown as the'o#en otation 'ime or ''$

• DD! uses a timed to#en protocol where 'o#en ing uses

priorit"9reser&ation to#en access, leading to differences in frameformatandhow station traffic is handled$

#$plain the difference between analog signal and digital signal.

#6 2ar:s)

(%ns) 

(nalog Analog signals are continuous electrical signals that &ar" intime$ !n other words, anAnalog or analogue signal is an" continuoussignal for which the time &ar"ing feature (&ariable) of the signal is arepresentation of some other time &ar"ing +uantit", i$e$, analogous toanother time &ar"ing signal$ !t differs from a digital signal in terms ofsmall fluctuations in the signal which are meaningful$Digital A digital s"stem is a data technolog" that uses discrete(discontinuous) &alues$ -" contrast, non/digital (or analog) s"stems use

a continuous range of &alues to represent information$ Although digitalrepresentations are discrete, the information represented can be either

Page 89: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 89/102

Page 90: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 90/102

b)2A (2etropolitan Area etwor#): 'his is a larger networ# thatconnects computer users in a particulargeographic area or region$ ore3ample, a large uni&ersit" ma" ha&e a networ# so large that it ma" beclassified as a 2A$ 'he 2A networ# usuall" e3ists to pro&ide

connecti&it" to local !SPs, cable '<, or large corporations$ !t is far largerthan a A and smaller than a ;A$ Also, large cities li#e ondon andS"dne", Australia, ha&e metropolitan area networ#s$

c);A: (;ide Area etwor#) 'his is the largest networ# and can inter/connect networ#s throughout the world because it is not restricted to ageographical location$ 'he !nternet is an e3ample of a worldwide public;A$ 2ost ;As e3ist to connect As that are not in the samegeographical area$ 'his technolog" is high speed and &er" e3pensi&e to

setup$

%hat are the adantages of network' #$plain in detail.

#6 2ar:s)

(%ns) 

Speed Sharing and transferring files within networ#s are &er" rapid$'hus, it sa&es time while maintaining the integrit" of the file$

!ost !ndi&iduall" licensed copies of man" popular software programs

can be costl"$ etwor#able &ersions are a&ailable at considerablesa&ings$ Shared programs on a networ# allow for easier upgrading of theprogram on one single file ser&er instead of upgrading indi&idualwor#stations$

Securit" Sensiti&e files and programs on a networ# are passwordprotected (established for specific directories to restrict access toauthori1ed users) or designated as =cop" inhibit>, so that "ou do notha&e to worr" about illegal cop"ing of programs$

!entrali+ed Software *anagement Software can be loaded on onecomputer (the file ser&er) eliminating the need to spend time and energ"installing updates and trac#ing files on independent computersthroughout the building$

Resource Sharing esources such as printers, fa3 machines andmodems can be shared$

#lectronic mail E/mail aids in personal and professionalcommunication$ Electronic mail on a A can enable staff to

communicate within the building, ha&ing not to lea&e their des#$

Page 91: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 91/102

Fle$ible (ccess Access their files from computers throughout the firm

%orkgroup !omputing ;or#group software(such as 2icrosoft-ac#?ffice) allows man" users to wor# on a document or pro@ectconcurrentl"$%hat is star topolog"' ,ow does it work' %hat is the maindisadantage of it'

#6 2ar:s)

(%ns) 

Star topolog" is also #nown as star networ#$ !t is one of the mostcommon networ# setups where each of the de&ices and computers on anetwor# connects to a central hub$ !t needs more cable to be networ#edthan the usual bus topolog"$ !t is used in homes and offices$  A ma@ordisad&antage of this t"pe of networ# topolog" is that if the central hub

fails, all computers connected to that hub would be disconnected$

#$plain point&to&point communication in detail with e$amples.#O 2ar:s)

(%ns) 

 A point/to/point connection is a dedicated communication lin# betweentwo s"stems or processes$ 'hin# of a wire that directl" connects twos"stems$ 'he s"stems use that wire e3clusi&el" to communicate$ 'heopposite of point/to/point communications is broadcasting, where one

s"stem transmits to man"$ A telephone call is a circuit/oriented, point/to/point lin# between twophones$ .owe&er, calls are usuall" multiple3ed across telephonecompan" trun#s so, while the circuit itself ma" be &irtual, the users areengaging in a point/to/point communication session$ An end/to/end connection refers to a connection between two s"stemsacross a switched networ#$ or e3ample, the !nternet is made up of amesh of routers$ Pac#ets follow a hop/b"/hop path from one router to thene3t to reach their destinations$ Each hop consists of a ph"sical point/to/

point lin# between routers$ 'herefore, a routed path consistsof multiplepoint/to/point lin#s$ !n the A'2 and frame rela" en&ironment,the end/to/end path is called avirtual circuit  that crosses a pre/definedset of point/to/point lin#s$

%here is ring topolog" primaril" used'#$plain them.

#O 2ar:s)

(%ns) 

ing topolog" is used mainl" in two #inds of networ#s:

Page 92: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 92/102

a) 'o#en ing etwor#s

b) iber Distributed Data !nterface

'o#en ing etwor#s:

*nli#e Ethernet, 'o#en ing uses a ring topolog" whereb" the data issent from one machine to the ne3t and so on around the ring until it endsup bac# where it started$ !t also uses a to#en passing protocol whichmeans that a machine can onl" use the networ# when it has control ofthe 'o#en$ 'his ensures that there are no collisions because onl" onemachine can use the networ# at an" gi&en time$

iber Distributed Data !nterface :

'he iber Distributed Data !nterface or DD! is a 455 mbps line usingthe A networ# and is connected through a fiber optic cable$ 'he DD!technolog" is used where the networ#s need a high speed bandwidthand need to co&er huge distances than the copper wires usuall" co&er$'here are two #inds of networ#s in this categor" // one is the fiber opticwire based and the other is the copper wire based called the 0opperdistributed data interface$

'he inside architecture of the DD! is based on the dual rings where thedata is flowing in the opposite directions$ 'here are two le&els of rings //

the primar" and the secondar"$ 2ost of the data transmission ta#esplace using the primar" ring and the secondar" is idling$ .owe&er, incase the primar" does not wor#, the secondar" ta#es o&er the primar"sfunctionalities$

%hat is star topolog"' ,ow does it work' %hat is the maindisadantage of it'

#6 2ar:s)

(%ns) Star topolog" is also #nown as star networ#$ !t is one of the mostcommon networ# setups where each of the de&ices and computers on anetwor# connects to a central hub$ !t needs more cable to be networ#edthan the usual bus topolog"$ !t is used in homes and offices$  A ma@ordisad&antage of this t"pe of networ# topolog" is that if the central hubfails, all computers connected to that hub would be disconnected$

#$plain point&to&point communication in detail with e$amples.

#O 2ar:s)

Page 93: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 93/102

(%ns) 

 A point/to/point connection is a dedicated communication lin# betweentwo s"stems or processes$ 'hin# of a wire that directl" connects twos"stems$ 'he s"stems use that wire e3clusi&el" to communicate$ 'heopposite of point/to/point communications is broadcasting, where ones"stem transmits to man"$ A telephone call is a circuit/oriented, point/to/point lin# between twophones$ .owe&er, calls are usuall" multiple3ed across telephonecompan" trun#s so, while the circuit itself ma" be &irtual, the users areengaging in a point/to/point communication session$ An end/to/end connection refers to a connection between two s"stemsacross a switched networ#$ or e3ample, the !nternet is made up of amesh of routers$ Pac#ets follow a hop/b"/hop path from one router to the

ne3t to reach their destinations$ Each hop consists of a ph"sical point/to/point lin# between routers$ 'herefore, a routed path consistsof multiplepoint/to/point lin#s$ !n the A'2 and frame rela" en&ironment,the end/to/end path is called avirtual circuit  that crosses a pre/definedset of point/to/point lin#s$

%here is ring topolog" primaril" used'#$plain them.

#O 2ar:s)

(%ns) 

ing topolog" is used mainl" in two #inds of networ#s:

a) 'o#en ing etwor#s

b) iber Distributed Data !nterface

'o#en ing etwor#s:

*nli#e Ethernet, 'o#en ing uses a ring topolog" whereb" the data issent from one machine to the ne3t and so on around the ring until it endsup bac# where it started$ !t also uses a to#en passing protocol whichmeans that a machine can onl" use the networ# when it has control ofthe 'o#en$ 'his ensures that there are no collisions because onl" onemachine can use the networ# at an" gi&en time$

iber Distributed Data !nterface :

'he iber Distributed Data !nterface or DD! is a 455 mbps line using

the A networ# and is connected through a fiber optic cable$ 'he DD!technolog" is used where the networ#s need a high speed bandwidth

Page 94: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 94/102

and need to co&er huge distances than the copper wires usuall" co&er$'here are two #inds of networ#s in this categor" // one is the fiber opticwire based and the other is the copper wire based called the 0opperdistributed data interface$

'he inside architecture of the DD! is based on the dual rings where thedata is flowing in the opposite directions$ 'here are two le&els of rings //the primar" and the secondar"$ 2ost of the data transmission ta#esplace using the primar" ring and the secondar" is idling$ .owe&er, incase the primar" does not wor#, the secondar" ta#es o&er the primar"sfunctionalities$

#$plain the term -network topolog". /ame the four basictopologies. #$plain an" two topologies in brief.

#O 2ar:s)

(%ns) 

etwor# topolog" is defined as the ph"sical inter/connection of &ariouselements (lin#s, nodes, etc$) of a computer networ#$ etwor# 'opologiescan be ph"sical or logical$ Ph"sical 'opolog"means the ph"sical designof a networ# including the de&ices, location and cable installation$ogicaltopolog" refers to the fact as to how data actuall" transfers in a networ#as opposed to its design$

'he networ# topolog" recognises four basic topologies:

• -us topolog"

• Star topolog"

• ing topolog"

• 'ree topolog"

-us topolog":

 A bus topolog" is a method of transmission on networ#s that uses acommon &ehicle for transmissions and is, therefore, categori1ed asshared communication$ !magine a bus pic#ing up &arious people fromone stop and dropping of people as it tra&els and pic#s up a few more$'hat is what happens in a bus networ# e3actl"$

.owe&er, in a -us topolog", onl" one de&ice is allowed to transmit at agi&en point of time$ 'he DAP or the Distribute Access Protocol has theinformation about which station has to transmit the data$ 'he data that is

being transmitted has frames that will ha&e the source name and thenetwor# address$

Page 95: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 95/102

ing topolog":

!n local area networ#s where the ring topolog" is used, each computer isconnected to the networ# in a closed loop or ring$ Each machine orcomputer has a uni+ue address that is used for identification purposes$'he signal passes through each machine or computer connected to thering in one direction$ ing topologies t"picall" utili1e a to#en passingscheme, used to control access to the networ#$ -" utili1ing this scheme,onl" one machine can transmit on the networ# at a time$ 'he machinesor computers connected to the ring act as signal boosters or repeaterswhich strengthen the signals that trans&erse the networ#$ 'he primar"disad&antage of ring topolog" is that failure of one machine will causethe entire networ# to fail$ %hich topolog" allows onl" one deice to transmit at a time'#$plain in detail with its adantages and disadantages.

#O 2ar:s)

(%ns) 

-us topolog" connects each computer (node) to a single segment trun#(a communication line, t"picall" coa3 cable, that is referred to as the%bus%)$ 'he signal tra&els from one end of the bus to the other$ Aterminator is re+uired at each to absorb the signal so that it does notreflect bac# across the bus$ A media access method called 0S2A92A isused to handle the collision that occurs when two signals are placed onthe wire at the same time$ 'he bus topolog" is passi&e$ !n other words,the computers on the bus simpl" %listen% for a signal the" are notresponsible for mo&ing the signal along$ Ad&antages:

• ailure of one of the stations does not affect others$

• Bood compromise o&er the other two topologies as it allows

relati&el"high rate of data transmission

• ;ell suited for temporar" networ#s that must be set up in a hurr"

• Eas" to implement and e3tend

Disad&antages:

• e+uire a networ# to detect when two nodes are transmitting at the

same time

• Does not cope well with hea&" traffic rates

• Difficult to administer9troubleshoot

• imited cable length and number of stations

•  A cable bra#e can disable the entire networ# no redundanc"

Page 96: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 96/102

• 2aintenance cost ma" be higher in the long run

•€Performance degrades as additional computers are added$&"" 5evision Tour

4ame the hea,er file#s) that is nee,e, for successful compilation of

the following &"" co,e=

  /oi, 'ain()

  7

  *har &tring89:;

  gets(&tring);

  str*at(&tring< =5&4>);

  pts(&tring);

  C

#; 2ar:)

(%ns) 

The heaer files neee for the successful compilation of the above coe are2 string.h

an stio.h.What are the basic features of ob9ect oriente, programming?

#; 2ar:)

(%ns) 

The basic features of ob9ect oriente, programming are ata abstraction, ataencapsulation, inheritance, an polymorphism.

$etermine the output=

  a 1;

  b a++;

  *ot @@ a++;  *ot @@ (b+a);

  cout DD ""b

#; 2ar:)

(%ns) 

he output of the abo$e code is 1 B 1.

What is a mo,ular programming?

#; 2ar:)

(%ns) Moular programming is the brea%ing own of the program into smaller sub tas%s, whichin turn may be bro%en own again so that the lowestDlevel functions are as simple aspossible.What are the two tpes of functions available in &""?

#; 2ar:)

(%ns) 

The two types of functions available in 7;; are2/mplicit an #xplicit functions. 4ame the hea,er files to which the following belong=

#i) puts#) #ii) strcmp#)#; 2ar:)

Page 97: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 97/102

(%ns) 

puts() belongs to stio.h heaer file an strcmp() belongs to string.h heaer file.What are the three expressions given in the for statement?

#; 2ar:)

(%ns) 

The three expressions are the initialization expression, test expression an theincrementBecrement (reinitialization) expression. What is a recursive function?

#; 2ar:)

(%ns) 

A function that calls itself irectly or inirectly is referre to as recursive function.'in, the sntax error#s)( if an( in the following program=

  inclu,e D iostream/h N

  voi, main#)

  @

  int x( cin NN x

  for#x 1 > xD<( ""x)  cout else cout DD x DD

  C

#8 2ar:s)

(%ns) 

The correct program isX inclue S iostream.h BB7orrection +voi main()Rint x,yQ cinxQ

for(x < ?Q xS0Q ;;x) BB7orrection Jcout SS yQcoutS S x SS yQ BB7orrection HU7orrection +2 The conition is terminate by a comma(,), instea of asemicolon(Q).7orrection J2 NSS9 is missing.7orrection H2 else cannot exist without if/

Write the output of the following program=

  Minclu,eD iostream/h N

  static int i 1 ;>>

  voi, abc#)  @

  static int i 1 R

  cout DD \first 1 ] DD i

  C

  voi, main#)

  @

  static int i 1 8

  abc#) cout DD \secon, 1 ] DD i DD en,l

  C

#8 2ar:s)

(%ns) 

Page 98: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 98/102

The output isfirst < secon < J'in, the output of the following program=

  voi, main#)

  @

  int x 1 <( 1 P  cout DD x""

  cout DD \(\

  cout DD ""x

  cout DD ](\

  cout DD "" DD \(\ DD ""

  C

#8 2ar:s)

(%ns) 

The output is 0,,I,.Write the output of the following program=

  Minclu,eD iostream/h N  voi, X#int %( int YB)

  @

  % 1 %"B

  B 1 %-B

  % 1 %-B

  C

  voi, main#)

  @

  int a 1 O( b 1 ;R

  X#a(b)

  cout DD a DD \(\ DD b  C

#8 2ar:s)

(%ns) 

The output is -,-.

 What will be the output of the following program=

  M inclu,e D iostream/h N

  voi, main#)

  @  int var; 1 <( var8 1 ;>

  for# int i 1 ; iD 18 i"")

  @

  cout DD var;"" DD ^t DD --var8 DD en,l

  cout DD var8-- DD ^t DD ""var; DD en,l

  C

  C

#8 2ar:s)

(%ns) 

The output is20 \

Page 99: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 99/102

\ \Wh is main function special? Give two reasons/

#8 2ar:s)

(%ns) (i) @henever a 7;; program is execute, only the main() is execute. Theexecution of a program starts an ens at main().(ii)The main() is the river function of the program. /f it is not inclue in theprogram, no execution can ta%e place.

Hxplanation =

null

Write two a,vantages of using inclu,e compiler ,irective/

#8 2ar:s)

(%ns) (i) The X inclue compiler irective inclues esire heaer files in ourprogram.(ii) /t supports moularity, i.e., a bigger program can be ecompose interms of heaer files an later inclue as apreDprocessor irective.$ifferentiate between call b value an, call b reference of function call/

#8 2ar:s)

(%ns) 

7all by value D The values of the actual arguments are passe to the function.7all by reference D The aress of the actual arguments is use in the functioncall.

What is the purpose of the hea,er file in a program?

#8 2ar:s)

(%ns) 

$eaer files, also calle inclue files, provie function prototype eclarations for libraryfunctions.Hxplain the use of this pointer in &""/

#8 2ar:s)

(%ns) 

@hile manipulating obects for user program, 7;; maintains an internal pointer callethis, to point to the current obect being operate upon.@henever a member function of an obect is calle, the compiler places the aress ofthe obect in pointer this before invo%ing the function.Write the output of the following program=

  Minclu,eD iostream/h N

  int func#int Yx( int 1 ;>)

  @

  if#x_ 1 1>) return ""x else return `

  C

  voi, main#)

  @  int p 1 8>( 1 86

Page 100: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 100/102

Page 101: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 101/102

  int main#)

  @

  IIII/

  large#<(Q)

  IIII//

  C  voi, large#int Ya( int Yb)

  @

  if#aNb) a 1 -;

  else b 1 -;

  C

#6 2ar:s)

(%ns) 

There is no problem with the program coe.% function printchar is ,efine, as

  voi, printchar#char ch 1 F( int len 1 O>)  @

  for# int x 1 > xDlen x"") cout DD ch

  cout DD en,l

  C

  3ow will ou invo:e the function printchar for following output=

#i)  to print F O> times

#ii)  to print F 8> times

#iii)  to print 1 O> times

#iv)  to print 1 6> times

#6 2ar:s)

(%ns) 

(i) printchar()(ii) printchar(NC9, J?)(iii) printchar(N<9,-?)(iv) printchar(NC9, H?)Write a function that interchanges the value of two integers % an, B without

using an extra variable/

#O 2ar:s)

(%ns) 

/ BB>unction to swap A an " without using a thir variablevoi 1@A5(int A, int ")RA < A ; "" < A D "QA < A 3 "Qcout SS EntAfter swapping a is DF SS AQcout SS EntAfter swapping a is DF SS AQgetch()QUWrite a function which will ta:e the height of a person in inches an, return the

height in feet an, inches in two separate variables/#O 2ar:s)

Page 102: Boolean Algebra Qand Answer

8/10/2019 Boolean Algebra Qand Answer

http://slidepdf.com/reader/full/boolean-algebra-qand-answer 102/102

(%ns) 

 BB>unction to convert the inch to feetvoi feetinch(int inch)R

float feetQfeet < float(inch)B+JQ BB Typecastingcout SS EThe person9s height in inch is E SS inch SS enlQcoutSS E The person9s height in feet isF SS feetQU

Write a function which will ta:e the height of a person in inches an, return the

height in feet an, inches in two separate variables/

#O 2ar:s)

(%ns) 

 BB>unction to convert the inch to feetvoi feetinch(int inch)Rfloat feetQfeet < float(inch)B+JQ BB Typecastingcout SS EThe person9s height in inch is E SS inch SS enlQcoutSS E The person9s height in feet isF SS feetQUWrite a function to fin, the sum of series/

;"8"6"O"<"P"IIIIIIIIII/upto 4 terms/

#O 2ar:s)(%ns) 

 BB>unction to fin the sum of series +;J;H;YYYY..;int sumseries(int )Rint i, sum < ?Qfor( i < ?Q iS < Q i;;)sum < sum ; iQreturn(sum)QU