Savitribai Phule Pune University S.Y.B.Sc S.Y .B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Or iente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! Q.1) Data Structures Using ‘C’ [Total Mark 40] 1. Sort a ran)om array o2 n inte&ers $accept the value o2 n 2rom user+ in ascen)in& or)er by usin& bubble sort al&orithm. Accept ' %isplay 3unction 45!6 Bubble Sort 3unction 476 • •
2. 8rite a C pro&ram 9hich uses Binary search tree library an) implements 2ollo9in& 3unctions, Create Binary search :ree #nsert a no)e in a binary search tree %isplay a binary search rch tree$#n $#n or)e r)er :raversal+ 476 476
45!6 45!6
• • •
! Q.1) Q.1) Da Data ta Stru Struct ctur ures es Usin Using g ‘C’ ‘C’ 5. A post2ix expression o2 the the 2orm ab*c)-;ab/ is to be evaluate) a2ter acceptin& the values o2 o2 a< b< c an) ). :he value shoul) be accepte) only once once an) the same same value is to be be use) 2or repeate) occurrence o2 same symbol in the expression. 3ormulate the problem an) 9rite a C pro&ram to solve the problem by usin& appropriate )ata structures an) al&orithms. Q 2) "#ect riente$ Conce%ts an$ &rogra''ing in C(( Marks *0]
[Total
5. %e2ine a class essa&e essa&e 9ith t9o )ata )ata members one character pointer an) an) an inte&er storin& len&th. #mplement 2ollo9in& 2unctions, a+ %e2ault constructor an) Parameteri=e) constructor 4*6 b+Ov b+Over erlo loa) a) bina binary ry * oper operat ator or to repr repres esen entt conc concat aten enat atio ion n o2 mess messa& a&es es 4>6 4>6 c+ Overloa) 46 operator to return a character at a speci2ic position 416 )+ Overloa) ? operator to copy one essa&e ob(ect to another. another. 476 8rite a main 2unction that uses the above class an) its member 2unctions. 476
! . #mplement #mplement a class class @)ata @)ata to overloa) overloa) 2ollo9in 2ollo9in& & 2unctions 2unctions as as 2ollo9s, 2ollo9s, a+ int maximum$int< int+ returns the maximum bet9een the t9o inte&er ar&uments b+int maximum$int ;a< int arraylen&th+ returns the maximum inte&er 2rom an array @a c+ voi) maximum$int ;a< int arrarylen&th < int n+ )isplay all elements 2rom the array @a 9hich are &reater than &iven number @n. )+int minimum$ int< int+ returns the minimum bet9een the t9o inte&er ar&uments e+ int minimum$ int ;< int arraylen&th+ returns the minimum inte&er 2rom an array @a 2+ voi) minimum$int ;a< int arrarylen&th < int n+ )isplay all elements 2rom the array @a Slip
1
46 476 476 46 476
Savitribai Phule Pune University S.Y.B.Sc S.Y .B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Or iente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! 9hich are smaller than &iven number @n. 8rite 8rite a main 2unction 2unction that uses the above above class class an) its member member 2unctions 2unctions.. 46
Q.*)
+i,a
Q.1)
Data Structures Using ‘C’
476
[10]
[Total Marks 40]
5. Sort a ran)om array o2 n inte&ers inte&ers $accept $accept the value o2 n 2rom user+ in ascen)in& ascen)in& or)er by usin& insertion sort al&orithm. Accept ' %isplay 3unction 45!6 • #nsertion Sort 3unction • . :here are lists 9here insertion insertion shoul) ensure the or)erin& o2 )ata )ata elements. Since the elements are in ascen)in& or)er the search can terminate once eDual or &reater element is 2oun). #mplement a sin&ly lin0e) list o2 or)ere) inte&ers $ascen)in&/)escen)in&+ $ascen)in&/)escen)in&+ 9ith insert< search an) )isplay operations. Creation o2 sin&ly lin0e) list in sorte) or)er • Search< %isplay operation carries mar0s each • 416 #nsert operation • 4>6 ! Q.1) Data Structures Using ‘C’
476
45!6
5. Suppose that 9e are sellin& the services o2 a machine. Each user pays a 2ixe) Amount per use. o9ever the time nee)e) by each user is )i22erent. 8e 8e 9ish to maximi=e the returns 2rom this machine un)er the assumption that the machine is not to be 0ept i)le unless no user is available. 8henever 8henever the machine becomes available< the user 9ith the smallest time reDuirement is selecte). 8hen a ne9 user reDuests the machine< machine< he has to 9ait i2 there are pen)in& reDuests. 3ormulate the problem an) 9rite a C pro&ram to solve the problem by usin& appropriate )ata structures an) al&orithms.
Q.2) "#ect riente$ &rogra''ing &rogra''ing Using C((
[Total [Total Marks *0]
5. %e2ine a class essa&e essa&e 9ith t9o )ata )ata members one character pointer an) an) an inte&er storin& len&th. #mplement 2ollo9in& 2unctions, a+ %e2ault constructor an) Parameteri=e) constructor b+Ov b+Over erlo loa) a) bina binary ry * oper operat ator or to repr repres esen entt conc concat aten enat atio ion n o2 mess messa& a&es es Slip
2
4*6 4>6 4>6
Savitribai Phule Pune University S.Y.B.Sc S.Y .B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Or iente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! 9hich are smaller than &iven number @n. 8rite 8rite a main 2unction 2unction that uses the above above class class an) its member member 2unctions 2unctions.. 46
Q.*)
+i,a
Q.1)
Data Structures Using ‘C’
476
[10]
[Total Marks 40]
5. Sort a ran)om array o2 n inte&ers inte&ers $accept $accept the value o2 n 2rom user+ in ascen)in& ascen)in& or)er by usin& insertion sort al&orithm. Accept ' %isplay 3unction 45!6 • #nsertion Sort 3unction • . :here are lists 9here insertion insertion shoul) ensure the or)erin& o2 )ata )ata elements. Since the elements are in ascen)in& or)er the search can terminate once eDual or &reater element is 2oun). #mplement a sin&ly lin0e) list o2 or)ere) inte&ers $ascen)in&/)escen)in&+ $ascen)in&/)escen)in&+ 9ith insert< search an) )isplay operations. Creation o2 sin&ly lin0e) list in sorte) or)er • Search< %isplay operation carries mar0s each • 416 #nsert operation • 4>6 ! Q.1) Data Structures Using ‘C’
476
45!6
5. Suppose that 9e are sellin& the services o2 a machine. Each user pays a 2ixe) Amount per use. o9ever the time nee)e) by each user is )i22erent. 8e 8e 9ish to maximi=e the returns 2rom this machine un)er the assumption that the machine is not to be 0ept i)le unless no user is available. 8henever 8henever the machine becomes available< the user 9ith the smallest time reDuirement is selecte). 8hen a ne9 user reDuests the machine< machine< he has to 9ait i2 there are pen)in& reDuests. 3ormulate the problem an) 9rite a C pro&ram to solve the problem by usin& appropriate )ata structures an) al&orithms.
Q.2) "#ect riente$ &rogra''ing &rogra''ing Using C((
[Total [Total Marks *0]
5. %e2ine a class essa&e essa&e 9ith t9o )ata )ata members one character pointer an) an) an inte&er storin& len&th. #mplement 2ollo9in& 2unctions, a+ %e2ault constructor an) Parameteri=e) constructor b+Ov b+Over erlo loa) a) bina binary ry * oper operat ator or to repr repres esen entt conc concat aten enat atio ion n o2 mess messa& a&es es Slip
2
4*6 4>6 4>6
Savitribai Phule Pune University S.Y.B.Sc S.Y .B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Or iente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! c+ Overloa) 46 operator to return a character at a speci2ic position )+Overloa) ? operator to copy one essa&e ob(ect to another. another. 8rite a main main 2unction 2unction that that uses uses the above class an) its member member 2unctions. 2unctions. 476
• • •
416 476
! .A boo0$#SBF+ boo0$#SBF+ an) C%$)ata capacity+ are both types o2 me)ia$i)< title+ ob(ects. A person person buys 5! me)ia items< items< each each o2 9hich can can be either boo0 or C%. %isplay the list o2 all boo0s an) C%s C%s bou&ht. %e2ine the classes classes an) appropriate member 2unctions to accept accept an) )isplay )ata. Use pointers an) concepts o2 polymorphism $virtual 2unctions+. Accept an) )isplay 2or class me)ia< boo0 an) C% - each 2unction carries mar0s 456 Use o2 polymorphism$virtual 2unction+ 416 main 2unction 9ith use o2 pointers an) )isplay )isplay list o2 all boo0s an) C%s. C%s. 45!6 Q.*)
+i,a
[10]
Slip
3
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! Q.1) Data Structures Using ‘C’
[Total Marks 40]
5. Gea) the )ata 2rom the 2ile Hemployee.txtI an) sort on a&e usin& insertion sort. Gea)in& ' %isplay the 2ile • #nsertion sort3unction •
45!6 476
. 8rite a C pro&ram that accepts a )irecte) &raph as an a)(acency matrix an) converts it to a)(acency list representation #mplement 2unctions to print out )e&ree o2 any vertex i$ta0e i as parameter to the 2unction+ 2rom a)(acency list Gea) a &raph as a)(acency atrix 476 • Creation o2 a)(acency "ist ' %isplay • 4>*6 Calculate out )e&ree o2 any vertex i 45!6 •
! Q.1) Data Structures Using ‘C’ 5. An #n2ix expression o2 the 2orm a;$b*c+;$$)-a+/b+ nee) to be converte) to post2ix 2orm usin& usual prece)ence o2 operators. 3ormulate the problem an) 9rite a C pro&ram to solve the problem by usin& appropriate )ata structures an) al&orithms.
Q 2) "#ect riente$ Conce%ts an$ &rogra''ing in C(( Marks *0]
[Total
5. #mplement a class essa&e havin& t9o )ata members a pointer to character an) an inte&er storin& len&th o2 the strin&. #mplement a class Jey havin& t9o )ata members a character array o2 si=e ! an) an inte&er storin& actual len&th o2 the strin&. :he restrictions on Jey are that the len&th shoul) be less than ! but minimum si=e 1 an) havin& atleast one )i&it an) one upper case character in it. 8rite a 2rien) 2unction to encrypt a essa&e usin& 0ey $use some encryption al&orithm+ an) )ecrypt the encrypte) text an) )isplay it. • Accept an) %isplay 2unction 2or essa&e ' Jey class each carries 7 mar0s 45!6 3rien) 2unction to encrypt the messa&e usin& encryption al&orithm an) )isplay • encrypte) text. 45!6 %ecrypt the encrypte) text an) )isplay it. 476 • 8rite a main 2unction that uses the above class an) its member 2unctions. • 476
! . #mplement a class @print)ata to overloa) @print 2unction as 2ollo9s, a+ voi) print$int+ - outputs value - KintL< that is< value 2ollo9e) by the value o2 the inte&er. Slip
4
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! e&. print$5!+ outputs value -K5!L 476 b+ voi) print $int< int+ outputs value 4KintL< KintL6< that is< value 2ollo9e) by the t9o inte&ers separate) by comma in sDuare brac0ets. 476 e& print$<+ outputs value-4KL
Q.*)
+i,a
476
[10]
Slip
5
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! Q.1) Data Structures Using ‘C’
[Total Marks 40]
5. Gea) the )ata 2rom the 2ile Hemployee.txtI an) sort on a&e usin& Bubble sort. Gea)in& the contents o2 3ile ' %isplay 3unction 45!6 • Bubble sort 3unction • 476 . 8rite a C pro&ram that accepts the &raph as an a)(acency matrix an) converts it to a)(acency list representation. #mplement 2unctions to print out )e&ree o2 any vertex i $ta0e i as parameter to the 2unction+ 2rom a)(acency list Gea) a &raph as a)(acency atrix • Creation o2 a)(acency "ist • Calculate out )e&ree o2 any vertex i •
476 45!6 45!6
! Q.1)
Data Structures Using ‘C’ 5. Suppose that 9e are sellin& the services o2 a machine. Each user uses the machine 2or a 2ixe) amount o2 time. o9ever the people are rea)y to pay )i22erent amounts 2or the service. 8e 9ish to maximi=e the returns 2rom this machine un)er the assumption that the machine is not to be 0ept i)le unless no user is available. 8henever the machine becomes available< the user 9ith the hi&hest payin& amount is selecte). 8hen a ne9 user reDuests the machine< he has to 9ait i2 there are pen)in& reDuests. 3ormulate the problem an) 9rite a C pro&ram to solve the problem by usin& appropriate )ata structures an) al&orithms.
Q 2) "#ect riente$ Conce%ts an$ &rogra''ing in C(( Marks *0]
[Total
5. #mplement the 2ollo9in& class hierarchy, Stu)ent, i)< name< Stu)entExam $)erive) 2rom Stu)ent+, 9ith n sub(ects $n can be variable+ Stu)entGesult $)erive) 2rom Stu)entExam+, 9ith percenta&e< &ra)e %e2ine a parameteri=e) constructor 2or each class an) appropriate 2unctions to accept an) )isplay )etails. Create n ob(ects o2 the Stu)entGesult class an) )isplay the mar0list usin& suitable manipulators. • Parameteri=e) constructor< accept an) )isplay 2or each class-each 2unction carries mar0s 4516 4>6 • %isplay mar0list 9ith Use o2 manipulators 8rite main 2unction that uses the above class an) its member 2unctions. 476
! . %e2ine a class name) Cloc0 9ith three inte&er )ata members 2or hours< minutes an) Slip
6
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! secon)s. %e2ine parameteri=e) an) )e2ault constructors. Overloa) increment an) )ecrement operators appropriately. Overloa) extraction an) insertion operators. 8rite appropriate )isplay 2unction. Consi)er hr 2ormat. 4*6 • %e2ault constructor an) Parameteri=e) constructor 4!6 • Overloa)in& o2 each operator carries 7 mar0s 46 • %isplay 3unction 8rite a main 2unction that uses the above class an) its member 2unctions. 46
Q.*) +i,a [10] Q.1) Data Structures Using ‘C’ [Total Marks 40] 5. Gea) the )ata 2rom the 2ile Hemployee.txtI an) sort on names in alphabetical or)er $use strcmp+ usin& bubble sort Gea)in& the contents o2 3ile ' %isplay 3unction 45!6 Bubble sort 3unction 476 . 8rite a C pro&ram that accepts a )irecte) &raph as an a)(acency matrix an) converts it to a)(acency list representation. 8rite a 2unction to )isplay the &raph in a)(acency list 2orm. Gea) a &raph as a)(acency atrix 476 Creation o2 a)(acency "ist 45!6 %isplay a)(acency "ist ' out )e&ree o2 any vertex i $ta0e i as parameter to the 2unction+ each carries 7 mar0s 45!6 ! Q.1) Data Structures Using ‘C’ 5. A 2actory has many machines an) many (obs that reDuire processin& on some o2 the machines. Each (ob has a (ob car) 9hich contains all the attributes o2 a (ob inclu)in& the machines on 9hich it nee) to be processe) an) the processin& time. 3or simplicity let us assume that there are ten machines numbere) !<5< ...M < each (ob is processe) 2or 2ixe) amount o2 time an) the (ob car) number is co)e) in such a 9ay that the machine reDuirements can be accesse). 3or example i2 (ob car) number is 71< it means (ob reDuires processin& on machines 7< < an) 1. :he (ob can be processe) simultaneously on these machines. o9ever each machine can process (obs one at a time an) ta0es up the ne9 (ob 9hen it becomes i)le. 3ormulate the problem an) 9rite a C pro&ram to solve the problem by usin& appropriate )ata structures an) al&orithms • •
• • •
•
Q 2) "#ect riente$ Conce%ts an$ &rogra''ing in C(( [Total Marks *0] 5. %e2ine a class name) Complex 2or representin& complex numbers. A complex number has the &eneral 2orm a * ib< 9here a- the real part< b - the ima&inary part are both real numbers an) i ?5. %e2ine parameteri=e) an) )e2ault constructor. Overloa) *< - an) ; operators 9ith usual meanin&. %e2ault constructor ' Parameteri=e) constructor-each carries mar0s 46 Slip
7
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! Overloa)in& o2 * operator ' - operator- each carries 7 mar0s 4M6 • Overloa)in& o2 ; operator 8rite a main 2unction that uses the above class an) its member 2unctions. ! . Niven the 2ollo9in& inheritance hierarchy< implement each o2 the classes. •
45!6 476
:he person class has parameteri=e) constructor< accept an) )isplay 2unctions. :he employee i) is auto &enerate) 2rom the last allotte) value store) in employee class. 8rite constructors< accept an) )isplay 2unctions 2or )erive) classes. %e2ine member 2unction computepay 2or employee an) overri)e appropriately in )erive) class. 8rite main pro&ram to ill ustrate use o2 the classes • Parameteri=e) constructor< accept an) )isplay 2or each class carries -$*5*5+ mar0s 456 • Computepay$+ 2or employee 456 Overri)in& o2 computepay$+ in )erive) classes-2unction in each class carries mar0s 416 • 8rite a main 2unction that uses the above class an) its member 2unctions. 476 Q.*) +i,a [10]
Q.1) Data Structures Using ‘C’ [Total Marks 40] 5. Gea) the )ata 2rom the 2ile Hemployee.txtI an) sort on names in alphabetical or)er $use strcmp+ usin& #nsertion sort Gea)in& the contents o2 3ile ' %isplay 3unction 45!6 #nsertion sort 3unction 476 • •
. 8rite a C pro&ram that accepts the &raph as an a)(acency matrix an) chec0s i2 the &raph is un)irecte). :he matrix 2or un)irecte) &raph is symmetric. Also calculate in )e&ree o2 all vertices Gea) a &raph as a)(acency atrix 476 • Chec0 the matrix is symmetric or not • Calculate in )e&ree o2 all vertices 45!6 •
45!6
! Q.1)
Data Structures Using ‘C’
5. A 2ile mana&er i)enti2ies each 2ile usin& an ino)e-no. A )irectory is also a 2ile i)enti2ie) by an ino)e-no. %irectory is a list o2 2iles each represente) by an ino)e-no. :he list has the hea)er containin& the ino)e-no o2 the parent that is the )irectory itsel2. A separate table in)exe) by ino)e-no maintains attributes o2 2iles inclu)in& the name o2 the 2ile. 3ormulate the problem an) 9rite a C pro&ram to solve the problem by usin& appropriate )ata Slip
8
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! structures an) al&orithms. Q 2) "#ect riente$ Conce%ts an$ &rogra''ing in C(( [Total Marks *0] 5. #mplement the 2ollo9in& class hierarchy
%e2ine constructors an) appropriate 2unctions to accept an) )isplay )etails. Parameteri=e) constructor< accept an) )isplay 2or each class carries-$**+ mar0s • 46 8rite main 2unction to accept )etails o2 @n :eachin&-Assistants an) )isplay the )etails.
46
! . #mplement a class H2ileI 9ith 2our )ata members< a strin& storin& the name o2 the 2ile an) inte&ers storin& the number o2 characters< 9or)s an) lines in the 2ile. 8rite the 2ollo9in& member 2unctions, a+ :he constructor ta0es only the 2ile name as the ar&ument an) opens the 2ile< counts the characters< 9or)s an) lines an) initiali=es the other )ata members. 416 #2 the 2ile )oes not exist creates a blan0 2ile 9ith the name an) other )ata members are initiali=e) to =ero. 476 b+ member 2unctions that count number o2 blan0 lines 46 c+ searches 2or occurrence o2 9or) in the 2ile 46 8rite main 2unction that uses the above class an) its member 2unctions. 476 Q.*) +i,a [10] Q.1) Data Structures Using ‘C’ [Total 40 Marks] 5. Sort a ran)om array o2 n inte&ers $accept the value o2 n 2rom user+ in ascen)in& or)er by usin& a recursive er&e sort al&orithm. Accept ' %isplay 3unction 416 er&e Sort 3unction 4>6 • •
. 8rite a C pro&ram 9hich uses Binary search tree library an) implements 2ollo9in& 3unctions • Create Binary search :ree 45!6 Search a no)e in binary search tree 45!6 • Slip
9
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! %isplay a binary search tree$Pre- Or)er :raversal+ 476 ! Q.1) Data Structures Using ‘C’ 5. Polynomials 9ith varyin& )e&ree can be represente) usin& lin0e) list. A term in a polynomial is represente) by a no)e 9ith structure. Coe22icient exponent "in0 3or example a polynomial x5!!! * x7! * 7 x can be represente) as ea)er 5 5!!! 7! 7 :he number o2 no)es reDuire) to represent the polynomial is same as the number o2 terms in the polynomial 9ith an a))itional no)e 2or the hea)er. :he no)es are maintaine) in the )escen)in& or)er o2 exponents. One nee) to accept< )isplay polynomial an) also per2orm other operation on polynomials such as a))ition. 3ormulate the problem an) 9rite a C pro&ram to solve the problem by usin& appropriate )ata structures an) al&orithms. •
Q 2) "#ect riente$ Conce%ts an$ &rogra''ing in C(( [Total Marks *0] 5. 8rite the )e2inition 2or a class calle) @time that has hours< minutes ' secon)s as inte&er )ata members. Consi)er hr 2ormat. :he class has the 2ollo9in& member 2unctions, a+ voi) settime$int< int< int+ to set the speci2ie) values o2 hours< minutes an) secon)s in ob(ect . 476 b+ voi) sho9time$+ to )isplay contents o2 time ob(ect. 476 c+ time a))$time+ a)) the correspon)in& values o2 hours< minutes an) secon)s $K!+ in time ob(ect ar&ument to current time ob(ect an) ma0e appropriate conversions an) return time. 416 )+ time )i22$time+ subtract values o2 hours< minutes an) secon)s in time ob(ect ar&ument 2rom current time ob(ect a2ter ma0in& appropriate conversions an) return time )i22erence. 416 8rite a main pro&ram to illustrate the use o2 above class an) member 2unction. 46 ! . 8rite the )e2inition 2or a class calle) Gectan&le that has 2loatin& point )ata embers len&th an) 9i)th. :he class has the 2ollo9in& member 2unctions, a+ voi) setlen&th$2loat+ to set the len&th o2 )ata member 46 b+ voi) set9i)th$2loat+ to set the 9i)th o2 )ata member 46 c+ 2loat perimeter$+ to calculate an) return the perimeter o2 the rectan&le 46 )+ 2loat area$+ to calculate an) return the area o2 the rectan&le 46 e+ voi) sho9$+ to )isplay the len&th an) 9i)th o2 the rectan&le 46 2+ Overloa) compare$+ to compare t9o rectan&les by len&th an) 9i)th 4>6 compare t9o rectan&les by area 416 8rite main 2unction to create t9o rectan&le ob(ects an) )isplay each rectan&le an) its area an) perimeter 476 Q.*) +i,a [10] • •
Slip 10
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! Q.1) Data Structures Using ‘C’
[Total Marks 40]
1. Sort a ran)om array o2 n inte&ers $accept the value o2 n 2rom user+ in ascen)in& or)er by usin& recursive uic0 sort al&orithm. Accept ' %isplay 3unction 416 uic0 Sort 3unction 4>6 • •
. 8rite a C pro&ram 9hich uses Binary search tree library an) implements 2ollo9in& 3unctions $use Gecursion+. Create Binary search :ree Count all lea2 no)es in Binary search tree Post or)er :raversal 476
45!6 45!6
• • •
! Q.1) Data Structures Using ‘C’ 5.:he osephus problem is the 2ollo9in& &ame. F people< numbere) 5 to F are sittin& in a circle. Startin& at person 5< a hot potato is passe)< A2ter passes< the person hol)in& the hot potato is eliminate)< the circle closes ran0s< an) the &ame continues 9ith the person 9ho 9as sittin& a2ter the eliminate) person pic0in& up the hot potato. :he last remainin& person 9ins. :hus< #2 ?! an) F?7< players are eliminate) in or)er< an) player 7 9ins. #2 ?5 an) F?7< the or)er o2 elimination is < < 5< 7 an) the player 9ins. :he osephus problem nee)s to be solve) 2or &eneral values o2 an) F $F L 5!!!!+. 3ormulate the problem an) 9rite a C pro&ram to solve the problem by usin& appropriate )ata structures an) al&orithms. Q 2) "#ect riente$ Conce%ts an$ &rogra''ing in C(( Marks *0]
[Total
5. %e2ine a class name) Cloc0 9ith three inte&er )ata members 2or hours< minutes an) secon)s. %e2ine parameteri=e) an) )e2ault constructors. Overloa) increment an) )ecrement operators appropriately. Overloa) extraction an) insertion operators. Consi)er hr 2ormat. 4*6 • %e2ault constructor an) Parameteri=e) constructor 4!6 • Overloa)in& o2 each operator carries 7 mar0s 46 • %isply 3unction 8rite a main 2unction that uses the above class an) its member 2unctions. 46
!
a+
. 8rite the )e2inition 2or a class calle) Gectan&le that has 2loatin& point )ata embers len&th an) 9i)th. :he class has the 2ollo9in& member 2unctions, voi) setlen&th$2loat+ to set the len&th o2 )ata member 46 b+voi) set9i)th$2loat+ to set the 9i)th o2 )ata member 46 c+2loat perimeter$+ to calculate an) return the perimeter o2 the rectan&le )+2loat area$+ to calculate an) return the area o2 the rectan&le e+voi) sho9$+ to )isplay the len&th an) 9i)th o2 the rectan&le Slip 11
46 46 46
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! 2+Overloa) compare$+ to 4>6 •compare t9o rectan&les by len&th an) 9i)th 416 •compare t9o rectan&les by area 8rite main 2unction to create t9o rectan&le ob(ects an) )isplay each rectan&le an) its area an) perimeter. 476
Q.*)
+i,a
[10]
Slip 12
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! Q.1) Data Structures Using ‘C’ [Total Marks 40] 5. Gea) the )ata 2rom the @employee.txt 2ile an) sort on a&e usin& er&e sort an) 9rite the sorte) )ata to another 2ile Qsorte)empona&e.txtQ. Gea)in& ' %isplay the 2ile 45!6 er&e sort 3unction 476 • •
. 8rite a C pro&ram 9hich uses Binary search tree library an) implements 2ollo9in& 3unctions Create Binary search :ree 45!6 #n or)er :raversal 476 Search a no)e in binary search tree Count all no)es in binary search tree •
• • •
476 476
! Q.1) Data Structures Using ‘C’ 5. Consi)er the )atabase o2 boo0s maintaine) in a library system 8hen a user 9ants to chec0 9hether a particular boo0 is available< a search operations is calle) 2or. #2 the boo0 is available an) is issue) to the user< a )elete operation can be per2orme) to remove this boo0 2rom the set o2 available boo0s. 8hen the user returns the boo0< it can be inserte) bac0 into the set o2 available boo0s. #t is essential that 9e are able to support the above mentione) operations as e22iciently as possible as since these operations are per2orme) Duite 2reDuently. 3ormulate the problem an) 9rite a C pro&ram to solve the problem by usin& appropriate )ata structures an) al&orithms. Q 2) "#ect riente$ Conce%ts an$ &rogra''ing in C(( *0]
[Total Marks
5. #mplement a class @)ata to overloa) 2ollo9in& 2unctions as 2ollo9s, a+ int maximum$int< int+ returns the maximum bet9een the t9o inte&er ar&uments 46 b+ int maximum$int ;a< int arraylen&th+ returns the maximum inte&er 2rom an array @a 476 c+ voi) maximum$int ;a< int arrarylen&th < int n+ )isplay all elements 2rom the array @a 9hich are &reater than &iven number @n. 476 )+ int minimum$ int< int+ returns the minimum bet9een the t9o inte&er ar&uments 46 e+ int minimum$ int ;< int arraylen&th+ returns the minimum inte&er 2rom an array @a 476 2+ voi) minimum$int ;a< int arrarylen&th < int n+ )isplay all elements 2rom the array @a 9hich are smaller than &iven number @n. 476 8rite a main 2unction that uses the above class an) its member 2unctions. 46 Slip 13
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1!
• • •
! . A boo0$#SBF+ an) C%$)ata capacity+ are both types o2 me)ia$i)< title+ ob(ects. A person buys 5! me)ia items< each o2 9hich can be either boo0 or C%. %isplay the list o2 all boo0s an) C%s bou&ht. %e2ine the classes an) appropriate member 2unctions to accept an) )isplay )ata. Use pointers an) concepts o2 polymorphism $virtual 2unctions+. Accept an) )isplay 2or class me)ia< boo0 an) C% - each 2unction carries mar0s 456 Use o2 polymorphism$virtual 2unction+ 416 main 2unction 9ith use o2 pointers an) )isplay list o2 all boo0s an) C%s. 45!6
Q.*)
+i,a
[10]
Q.1) Data Structures Using ‘C’ [Total Marks 40] 5.Gea) the )ata 2rom the @employee.txt 2ile an) sort on a&e usin& uic0 sort an) 9rite the sorte) )ata to another 2ile Qsorte)empona&e.txtQ. Gea)in& ' %isplay the 2ile 45!6 uic0 sort 3unction 476 . 8rite a C pro&ram 9hich uses Binary search tree library an) implements 2ollo9in& 3unctions Create Binary search :ree 45!6 Search a no)e in binary search tree 45!6 %isplay a binary search tree $#n or)er :raversal+ 476 ! Q.1) Data Structures Using ‘C’ • •
• • •
5. An A))ress boo0 contains the name an) other )etails o2 2rien)s. User 9ants to chec0 2or a particular name an) &et the )etails such as phone number or email a))ress o2 his 2rien). Fe9 A))resses are a))e) to the a))ress boo0. :he contact in2ormation may also reDuire 2reDuent up)ation. Certain important contact numbers $a small number+ 9hich are 2reDuently reDuire) shoul) be accessible very 2ast. :hese contacts may be important $2avourites+ at some point in time but may not continue to remain so an) have to be remove). 3ormulate the problem an) 9rite a C pro&ram to solve the problem by usin& appropriate )ata structures an) al&orithms.
Q 2) "#ect riente$ Conce%ts an$ &rogra''ing in C(( *0] 5. #mplement a class @invert)ata to overloa) @invert 2unction as 2ollo9s, a+int invert $ int+ - returns the inverte) inte&er. E&. invert$71+ 9ill return 17 b+char ; invert $ char ;+ returns the reverse) strin& reverse$HcompI+ 9ill return IpmocI Slip 14
[Total Marks
45!6 416
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! c+voi) invert$ int ; + 9ill reverse the array or)er An array 47< >< 5< 6 9ill be inverte) to 4< 5< >< 76. 8rite a main 2unction that uses the above class an) its member 2unctions. 476
4>6
! . #mplement the 2ollo9in& class hierarchy, Stu)ent, i)< name< Stu)entExam $)erive) 2rom Stu)ent+, 9ith n sub(ects $n can be variable+ Stu)entGesult $)erive) 2rom Stu)entExam+, 9ith percenta&e< &ra)e %e2ine a parameteri=e) constructor 2or each class an) appropriate 2unctions to accept an) )isplay )etails. Create n ob(ects o2 the Stu)entGesult class an) )isplay the mar0list usin& suitable manipulators. • Parameteri=e) constructor< accept an) )isplay 2or each class-each 2unction carries mar0s 4516 4>6 • %isplay mar0list 9ith Use o2 manipulators 8rite main 2unction that uses the above class an) its member 2unctions. 476
Q.*)
+i,a
[10]
Slip 15
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! Q.1) Data Structures Using ‘C’ [Total Marks 40] 1. Create a ran)om array o2 n inte&ers. Accept a value x 2rom user an) use linear search al&orithm to chec0 9hether the number is present in the array or not an) output the position i2 the number is present. Accept ' %isplay 3unction 416 "inear Search 3unction 4>6 • •
. #mplement a stac0 library $)ystac0.h+ o2 inte&ers usin& a )ynamic $lin0e) list+ implementation o2 the stac0 an) implementin& the Push
Q 2) "#ect riente$ Conce%ts an$ &rogra''ing in C(( Marks *0]
[Total
5. #mplement the 2ollo9in& class hierarchy, Stu)ent, i)< name< Stu)entExam $)erive) 2rom Stu)ent+, 9ith n sub(ects $n can be variable+ Stu)entGesult $)erive) 2rom Stu)entExam+, 9ith percenta&e< &ra)e %e2ine a parameteri=e) constructor 2or each class an) appropriate 2unctions to accept an) )isplay )etails. Create n ob(ects o2 the Stu)entGesult class an) )isplay the mar0list usin& suitable manipulators. • Parameteri=e) constructor< accept an) )isplay 2or each class-each 2unction carries mar0s 4516 4>6 • %isplay mar0list 9ith Use o2 manipulators 8rite main 2unction that uses the above class an) its member 2unctions. 476
! . -rite a C(( %rogra' to i'%le'ent te /olloing %e2ine a class @city 9ith )ata members name an) S:% co)e. Accept @n cities 9ith S:% co)es 2rom user. Store this )ata in the 2ile @cities.txt. 8rite a pro&ram that rea)s the )ata 2rom 2ile cities.txt into the array. Output the list o2 city 9ith S:% co)es. 8rite a search Slip 16
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! • • • •
2unction to search a city by name an) )isplay its S:% co)e. accept an) )isplay 2unction )e2inition-each carries mar0s 9ritin& )ata to a 2ile an) rea)in& )ata 2rom a 2ile-each carries 7 mar0s %isplay list o2 cities 9ith S:% co)es 2rom 2ile Search 2unction 8rite main 2unction that uses the above class an) its member 2unctions. 476 Q.*) +i,a
46 45!6 476 46
[10]
Q.1) Data Structures Using ‘C’ [Total Marks 40] 1. Gea) the )ata 2rom 2ile Qcities.txtQ containin& names o2 5! cities an) their S:% co)es. Accept a name o2 the city 2rom user an) use linear search al&orithm to chec0 9hether the name is present in the 2ile an) output the S:% co)e< other9ise output Hcity not in the listI. Accept ' %isplay 3unction 416 "inear Search 3unction 4>6 2. :here are lists 9here ne9 elements are al9ays appen)e) at the en) o2 the list. :he list can be implemente) as a circular list 9ith the external pointer pointin& to the last element o2 the list. #mplement sin&ly lin0e) circular list o2 inte&ers 9ith appen) an) )isplay operations. :he operation appen)$"< n+< appen)s to the en) o2 the list< n inte&ers either accepte) 2rom user or ran)omly &enerate) Creation o2 circular "in0 "ist ' Appen) 3unction each carrires5! mar0s 4!6 %isplay 3unction 476 ! Q.1) Data Structures Using ‘C’ 5. #n )epth 2irst search o2 a Nraph 9e start at vertex v an) mar0 it as havin& been visite). :he exploration o2 the vertex involves visitin& all the a)(acent vertices ho9ever the exploration o2 a vertex is suspen)e) as soon as a ne9 vertex is reache) an) the exploration o2 a ne9 vertex be&ins. 8hen the exploration o2 ne9 vertex is over< the exploration v is resume). %3S can be best implemente) as a recursive 2unction. A topolo&ical sort o2 a )irecte) acyclic &raph is a linear or)erin& o2 all its vertices such that i2 N contains an e)&e $u< v+< then u appears be2ore v in the or)erin&. 3or topolo&ical or)erin& %3S is calle) on the &raph an) every vertex explore) is a))e) onto the 2ront o2 a lin0e) list that 2orms the topolo&ical or)er. 3ormulate the problem an) 9rite a C pro&ram to solve the problem by usin& appropriate )ata structures an) al&orithms Q 2) "#ect riente$ Conce%ts an$ &rogra''ing in C(( [Total Marks *0] 5.8rite the )e2inition 2or a class calle) Hcuboi)Soli)I that has len&th< brea)th< hei&ht an) mass has 2loat )ata members. :he class has the 2ollo9in& member 2unctions. a+ Accept$+ an) %isplay$+ 2unctions each carries 7mar0s 45!6 b+ 2loat &etRolume$+ that returns the volume o2 the metal 476 • •
• •
Slip 17
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! c+ 2loat &etSur2aceArea$+ that returns the sur2ace area )+ 2loat &et%ensity$+ that returns the )ensity 8rite a main pro&ram to illustrate the use o2 above class an) member 2unction.
476
476
! . %e2ine a class account 9ith 2ollo9in& speci2ications , private )ata members , account nu'"er automatically &enerate) six )i&it account number< 2irst t9o )i&it are use) 2or ban0 co)e $assume the value 1+ an) next 2our )i&its 2or account number$use static 0ey9or)+ < account t%e it can be one o2 the 2ollo9in& type savin&< current< 2ixe)< recurrin&T< a'ount lon& inte&er 2or the balance amount< ner a'e name o2 the o9ner Public )ata members, a+ Accept $+ 9ith vali) account number an) Use o2 static 0ey9or) 4>6 Accept$+ 9ith vali)ation 2or account type 46 Other )ata members 46 b+ %isplay account in2ormation 476 c+ %eposit an amount in an account 46 )+ 8ith)ra9 an amount a2ter chec0in& the minimum balance con)ition 46 8rite a main pro&ram to accept in2ormation 2rom user an) open @n accounts $Use )ynamical memory allocation+ an) )isplay their in2ormation. 416 Q.*) +i,a [10]
Slip 18
476
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1!
Q.1) Data Structures Using ‘C’
[Total Marks 40]
5. Gea) the )ata 2rom 2ile @sorte)cities.txt containin& names o2 5! cities an) their S:% co)es. Accept a name o2 the city 2rom user an) use binary search al&orithm to chec0 9hether the name is present in the 2ile an) output the S:% co)e< other9ise output Hcity not in the listI. Accept ' %isplay 3unction 416 • Binary Search 3unction •
4>6
2. #mplement a list library $sin&lylist.h+ 2or a sin&ly lin0e) list o2 characters 9ith the insert< )elete< search< )isplay operations. 8rite a menu )riven pro&ram to call the operations. Creation o2 Sin&ly lin0 list 46 •
Slip 19
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! • • •
#nsert< %elete carries mar0s each %isplay 3unction Search 3unction
456 46 476
! Q.1)
Data Structures Using ‘C’
1. A post2ix expression o2 the 2orm ab*c)-;ab/ is to be evaluate) a2ter acceptin& the values o2 a< b< c an) ). :he value shoul) be accepte) only once an) the same value is to be use) 2or repeate) occurrence o2 same symbol in the expression. 3ormulate the problem an) 9rite a C pro&ram to solve the problem by usin& appropriate )ata structures an) al&orithms. Q 2) "#ect riente$ Conce%ts an$ &rogra''ing in C(( Marks *0] 5. #mplement a class @invert)ata to overloa) @invert 2unction as 2ollo9s, a+int invert $ int+ - returns the inverte) inte&er. e&. invert$71+ 9ill return 17 b+char ; invert $ char ;+ returns the reverse) strin& e&. reverse$HcompI+ 9ill return IpmocI c+voi) invert$ int ; + 9ill reverse the array or)er An array 47< >< 5< 6 9ill be inverte) to 4< 5< >< 76. 8rite a main 2unction that uses the above class an) its member 2unctions.
[Total
45!6 416 4>6 476
! 5. %e2ine a class name) Cloc0 9ith three inte&er )ata members 2or hours< minutes an) secon)s. %e2ine parameteri=e) an) )e2ault constructors. Overloa) increment an) )ecrement operators appropriately. Overloa) extraction an) insertion operators. Consi)er hr 2ormat. 4*6 • %e2ault constructor an) Parameteri=e) constructor • Overloa)in& o2 each operator carries 7 mar0s 4!6 8rite a main 2unction that uses the above class an) its member 2unctions. 476
Q.*)
+i,a
[10]
Q.1) Data Structures Using ‘C’ [Total Marks 40] 5. #mplement a stac0 library $ststac0.h+ o2 inte&ers usin& a static implementation o2 the stac0 an) Slip 20
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! implementin& the #nit$+
Q 2) "#ect riente$ Conce%ts an$ &rogra''ing in C(( [Total Marks *0] 5. #mplement a class @print)ata to overloa) @print 2unction as 2ollo9s, a+ voi) print$int+ - outputs value - KintL< that is< value 2ollo9e) by the value o2 the inte&er. e&. print$5!+ outputs value -K5!L 476 b+ voi) print $int< int+ outputs value 4KintL< KintL6< that is< value 2ollo9e) by the t9o inte&ers separate) by comma in sDuare brac0ets. 476 e& print$<+ outputs value-4KL
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! 2our )ata members< three inte&ers 2or hour< minutes an) secon)s an) a character array o2 si=e storin& am/pm. %e2ine constructor 9ith )e2ault ar&uments $mi)ni&ht+. %e2ine accept an) )isplay 2unctions. #mplement a secon) class :ime 9hich stores time in hr 2ormat $hh< mm< ss+. #t has three )ata members< three inte&ers 2or hours< minute' secon)s. #mplement 2ollo9in& 2unctions, a+ 3rien) 2unction iseDual$+ to compare time in 5 hr 2ormat to time in hr 2ormat 416 b+ convert time in 5 hr 2ormat to hr 2ormat 46 476 • constructor o2 class :ime5 9ith )e2ault ar&ument • Accept ' )isplay 3unction 476 8rite a main 2unction that uses the above class an) its member 2unctions. 46 Q.*) +i,a [10]
Q.1) Data Structures Using ‘C’ [Total Marks 40] 5. Create a ran)om array o2 n inte&ers. Accept a value x 2rom user an) use linear search al&orithm to chec0 9hether the number is present in the array or not an) output the position i2 the number is present. Accept ' %isplay 3unction 416 "inear Search 3unction 4>6 • •
. #mplement a stac0 library $)ystac0.h+ o2 inte&ers usin& a )ynamic $lin0e) list+ implementation o2 the stac0 an) implementin& the init
Pee0 ' #s empty operation carries mar0s each 416
! Q.1) Data Structures Using ‘C’ 5. #n brea)th 2irst search $B3S+ o2 a Nraph 9e start at vertex v an) mar0 it as havin& been visite). All unvisite) vertices a)(acent 2rom v are visite) next. :he v is thus completely explore). :he visite) but at unexplore) vertices are ta0en up next 2or exploration. Exploration continues until no unexplore) vertex is le2t. #2 B3S is use) on a connecte) un)irecte) &raph N< then all vertices in N &et visite) an) the &raph is completely traverse). :hus B3S can be use) to chec0 9hether &raph is connecte). 3ormulate the problem an) 9rite a C pro&ram to solve the problem by usin& appropriate )ata structures an) al&orithms. Slip 22
456
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! Q 2) "#ect riente$ Conce%ts an$ &rogra''ing in C(( *0]
• • • •
• • •
[Total Marks
5. 8rite a C** pro&ram to implement the 2ollo9in&, %e2ine a class @city 9ith )ata members name an) S:% co)e. Accept @n cities 9ith S:% co)es 2rom user. Store this )ata in the 2ile @cities.txt. 8rite a pro&ram that rea)s the )ata 2rom 2ile cities.txt into the array. Output the list o2 city 9ith S:% co)es. 8rite a search 2unction to search a city by name an) )isplay its S:% co)e. Accept an) )isplay 2unction )e2inition-each carries mar0s 4 6 8ritin& )ata to a 2ile an) rea)in& )ata 2rom a 2ile-each carries 7 mar0s 45!6 %isplay list o2 cities 9ith S:% co)es 2rom 2ile 476 Search 2unction 46 8rite main 2unction that uses the above class an) its member 2unctions. 476
! . %e2ine a class name) Complex 2or representin& complex numbers. A complex number has the &eneral 2orm a * ib< 9here a- the real part< b - the ima&inary part are both real numbers an) i ?-5. %e2ine parameteri=e) an) )e2ault constructor. Overloa) *< - an) ; operators 9ith usual meanin&. %e2ault constructor ' Parameteri=e) constructor-each carries mar0s Overloa)in& o2 * operator ' - operator- each carries 7 mar0s 45!6 Overloa)in& o2 ; operator 4M6 8rite a main 2unction that uses the above class an) its member 2unctions. Q.*)
+i,a
46
476
[10]
Q.1) Data Structures Using ‘C’
[Total Marks 40]
5. #mplement a list library $sin&lylist.h+ 2or a sin&ly lin0e) list o2 inte&er 9ith the operations create< %elete )isplay. 8rite a menu )riven pro&ram to call these operations. Create ' %elete at 2ront< %isplay Operation Carries 7 ar0s each. • 4576 ,
. #mplement a Dueue library $)yDueue.h+ o2 inte&ers usin& a )ynamic $circular lin0e) list+ implementation o2 the Dueue an) implementin& the above #nsert<%elete<#s Empty operations. 8rite a menu )riven pro&ram that inclu)es Dueue library an) calls )i22erent Dueue operations. #nsert<%elete
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! consistin& o2 inimum< aximum< e)ian< 5st an) r) uantile. 3ormulate the problem an) 9rite a C pro&ram to solve the problem by usin& appropriate )ata structures an) al&orithms.
Q 2) "#ect riente$ Conce%ts an$ &rogra''ing in C(( Marks *0]
[Total
5. #mplement a class essa&e havin& t9o )ata members a pointer to character an) an inte&er storin& len&th o2 the strin&. #mplement a class Jey havin& t9o )ata members a character array o2 si=e ! an) an inte&er storin& actual len&th o2 the strin&. :he restrictions on Jey are that the len&th shoul) be less than ! but minimum si=e 1 an) havin& atleast one )i&it an) one upper case character in it. 8rite a 2rien) 2unction to encrypt a essa&e usin& 0ey $use some encryption al&orithm+ an) )ecrypt the encrypte) text an) )isplay it. •Accept an) %isplay 2unction 2or essa&e ' Jey class each carries 7 mar0s 45!6 •3rien) 2unction to encrypt the messa&e usin& encryption al&orithm an) )isplay encrypte) text. 45!6 •%ecrypt the encrypte) text an) )isplay it. 476 •8rite a main 2unction that uses the above class an) its member 2unctions. 476
! . #mplement the 2ollo9in& class hierarchy
%e2ine constructors an) appropriate 2unctions to accept an) )isplay )etails. • Parameteri=e) constructor< accept an) )isplay 2or each class carries-$**+ mar0s 46 8rite main 2unction to accept )etails o2 @n :eachin&-Assistants an) )isplay the )etails. 46
Q.*) +i,a Q.1) Data Structures Using ‘C’
[10] [Total Marks 40] Slip 24
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! 5. #mplement a list library $sin&lylist.h+ 2or a sin&ly lin0e) list o2 inte&ers 9ith the operations create< search< )isplay. 8rite a menu )riven )river pro&ram to call these operations. Create
Q 2) "#ect riente$ Conce%ts an$ &rogra''ing in C(( [Total Marks *0] 5. 8rite the )e2inition 2or a class calle) @time that has hours< minutes ' secon)s as inte&er )ata members. Consi)er hr 2ormat. :he class has the 2ollo9in& member 2unctions, a+ voi) settime$int< int< int+ to set the speci2ie) values o2 hours< minutes an) secon)s in ob(ect . 476 b+ voi) sho9time$+ to )isplay contents o2 time ob(ect. 476 c+ time a))$time+ a)) the correspon)in& values o2 hours< minutes an) secon)s $K!+ in time ob(ect ar&ument to current time ob(ect an) ma0e appropriate conversions an) return time. 416 )+ time )i22$time+ subtract values o2 hours< minutes an) secon)s in time ob(ect ar&ument 2rom current time ob(ect a2ter ma0in& appropriate conversions an) return time )i22erence. 416 8rite a main pro&ram to illustrate the use o2 above class an) member 2unction. 46 ! . 8rite the )e2inition 2or a class calle) Gectan&le that has 2loatin& point )ata embers len&th an) 9i)th. :he class has the 2ollo9in& member 2unctions, a+voi) setlen&th$2loat+ to set the len&th o2 )ata member b+voi) set9i)th$2loat+ to set the 9i)th o2 )ata member c+2loat perimeter$+ to calculate an) return the perimeter o2 the rectan&le )+2loat area$+ to calculate an) return the area o2 the rectan&le Slip 25
46 46 46 46
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! e+voi) sho9$+ to )isplay the len&th an) 9i)th o2 the rectan&le 2+Overloa) compare$+ to- compare t9o rectan&les by len&th an) 9i)th 4>6 -compare t9o rectan&les by area 8rite main 2unction to create t9o rectan&le ob(ects an) )isplay each rectan&le an) its area an) perimeter.
Q.*)
+i,a
46 416 476
[10]
Slip 26
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! Q.1) Data Structures Using ‘C’ [Total Marks 40] 5. #mplement a list library $)oublylis.h+ 2or a )oubly lin0e) list o2 inte&ers 9ith create< #nsert ' )isplay operations. 8rite a menu )riven pro&ram to call these operations. Create #nsert at en)< %isplay carries 7 mar0 each 4576 •
. #mplement a Dueue library $stDueue.h+ o2 inte&ers usin& a static implementation o2 the Dueue an) implementin& the #nsert<%elete<#sEmpty<#s3ull<#nit
! Q.1)
Data Structures Using ‘C’
5. A spell chec0er is a pro&ram that loo0s at a )ocument an) compares each 9or) in the )ocument to 9or)s store) in a )ictionary. #2 it 2in)s 9or)s in the )ictionary< it moves on to the next 9or)< #2 it )oes not 2in) the 9or)< it reports the user about the misspelle)$possibly+ 9or). 3ormulate the problem an) 9rite a C pro&ram to solve the problem by usin& appropriate )ata structures an) al&orithms.
Q 2) "#ect riente$ Conce%ts an$ &rogra''ing in C(( Marks *0]
[Total
5.
%e2ine a class essa&e 9ith t9o )ata members one character pointer an) an inte&er storin& len&th. #mplement 2ollo9in& 2unctions, a+%e2ault constructor an) Parameteri=e) constructor 4*6 b+Overloa) binary * operator to represent concatenation o2 messa&es 4>6 c+Overloa) 46 operator to return a character at a speci2ic position 416 )+Overloa) ? operator to copy one essa&e ob(ect to another. 476 8rite a main 2unction that uses the above class an) its member 2unctions. 476
!
a+ b+ c+
. 8rite the )e2inition 2or a class calle) @time that has hours< minutes ' secon)s as inte&er )ata members. Consi)er hr 2ormat. :he class has the 2ollo9in& member 2unctions, voi) settime$int< int< int+ to set the speci2ie) values o2 hours< minutes an) secon)s in ob(ect . voi) sho9time$+ to )isplay contents o2 time ob(ect. time a))$time+ a)) the correspon)in& values o2 hours< minutes an) secon)s Slip 27
476 476
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1!
)+
$K!+ in time ob(ect ar&ument to current time ob(ect an) ma0e appropriate conversions an) return time. time )i22$time+ subtract values o2 hours< minutes an) secon)s in time ob(ect ar&ument 2rom current time ob(ect a2ter ma0in& appropriate conversions an) return time )i22erence. 8rite a main pro&ram to illustrate the use o2 above class an) member 2unction. 46
Q.*)
+i,a
416
416
[10]
Q.1) Data Structures Using ‘C’ [Total Marks 40] 5. #mplement a list library $)oublylis.h+ 2or a )oubly lin0e) list o2 inte&ers 9ith create< %elete ' )isplay operations. 8rite a menu )riven pro&ram to call these operations. Create <)elete at en) < )isplay operation carries 7 mar0 each 4576 •
8rite a 2unction that chec0s 9hether a strin& o2 characters is palin)rome or not. :he 2unction shoul) use a stac0 library $cststac0.h+ o2 stac0 o2 characters usin& a static implementation o2 the stac0. Push
45!6 476
! Q.1)
Data Structures Using ‘C’
5. Niven a )ata set consistin& o2 n inte&ers< a 2ive point summary is to be pro)uce) consistin& o2 inimum< aximum< e)ian< 5st an) r) uantile. 3ormulate the problem an) 9rite a C pro&ram to solve the problem by usin& appropriate )ata structures an) al&orithms.
Q 2) "#ect riente$ Conce%ts an$ &rogra''ing in C(( Marks *0]
[Total
5. #mplement a class essa&e havin& t9o )ata members a pointer to character an) an inte&er storin& len&th o2 the strin&. #mplement a class Jey havin& t9o )ata members a character array o2 si=e ! an) an inte&er storin& actual len&th o2 the strin&. :he restrictions on Jey are that the len&th shoul) be less than ! but minimum si=e 1 an) havin& atleast one )i&it an) one upper case character in it. 8rite a 2rien) 2unction to encrypt a essa&e usin& 0ey $use some encryption al&orithm+ an) )ecrypt the encrypte) text an) )isplay it. 45!6 • Accept an) %isplay 2unction 2or essa&e ' Jey class each carries 7 mar0s Slip 28
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! 3rien) 2unction to encrypt the messa&e usin& encryption al&orithm an) )isplay encrypte) text. 45!6 476 • %ecrypt the encrypte) text an) )isplay it. 8rite a main 2unction that uses the above class an) its member 2unctions. 476 •
! . %e2ine a class name) Complex 2or representin& complex numbers. A complex number has the &eneral 2orm a * ib< 9here a- the real part< b - the ima&inary part are both real numbers an) i ?-5. %e2ine parameteri=e) an) )e2ault constructor. Overloa) *< - an) ; operators 9ith usual meanin&. 46 • %e2ault constructor ' Parameteri=e) constructor-each carries mar0s 45!6 • Overloa)in& o2 * operator ' - operator- each carries 7 mar0s 4M6 • Overloa)in& o2 ; operator 8rite a main 2unction that uses the above class an) its member 2unctions.
Q.*)
+i,a
476
[10]
Q.1) Data Structures Using ‘C’ [Total Marks 40] 5. #mplement a list library $)oublylis.h+ 2or a )oubly lin0e) list o2 inte&ers 9ith create< search ' )isplay operations. 8rite a menu )riven pro&ram to call these operations. Create
. 8rite a 2unction that reverses a strin& o2 characters. :he 2unction shoul) use a stac0 library $cststac0.h+ o2 stac0 o2 characters usin& a static implementation o2 the stac0. Push
Slip 29
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! Q 2) "#ect riente$ Conce%ts an$ &rogra''ing in C(( Marks *0]
• • • •
[Total
5.%e2ine a class @3raction havin& inte&er )ata members numerator an) )enominator. %e2ine parameteri=e) an) )e2ault constructors $)e2ault values ! an) 5+. Parameteri=e) constructor shoul) store the 2raction in re)uce) 2orm a2ter )ivi)in& both numerator an) )enominator by &c)$&reatest common )ivisor+. 8rite a private 2unction member to compute &c) o2 t9o inte&ers. 8rite 2our member 2unctions 2or a))ition< subtraction. multiplication an) )ivision o2 2raction ob(ects. Each 2unction 9ill have t9o 2raction ob(ects as ar&uments. &c)$+ 2unction 46 %e2ault constructor an) Parameteri=e) constructor 45*?76 A))ition< Subtraction an) %ivision 2unction - each carries 7 mar0s 4576 ultiplication$+ 2unction 46 8rite the main 2unction to illustrate the use o2 the class an) member 2unction.
476
! . #mplement a class vector 9hich contains inte&ers in sorte) or)er. :he si=e o2 the vector varies so the memory shoul) be )ynamically allocate). #t shoul) have three )ata members vectorarray a pointer to inte&er< maxsi=e the maximum allocate) si=e to ta0e care o2 insertions an) si=e actual si=e. 8rite member 2unction 2or, a+ Parameteri=e) constructor 'copy constructor-each carries 7 mar0s. 45!6 b+ &et value at a particular position in vector 46 c+ insert values in vector to 0eep it in sorte) or)er 476 )+ print the vector 46 e+ #mplement the member 2unctions to 2orm union o2 t9o vectors. 476 8rite the main 2unction to illustrate the use o2 the class an) member 2unction. 476
Q.*)
+i,a
[10]
Slip 30
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! Q.1) Data Structures Using ‘C’ [Total Marks 40] 5. #mplement a stac0 library $ststac0.h+ o2 inte&ers usin& a static implementation o2 the stac0 an) implementin& the Push
•
Q 2) "#ect riente$ Conce%ts an$ &rogra''ing in C(( [Total Marks *0] 5. #mplement a class vector 9hich contains inte&ers in sorte) or)er. :he si=e o2 the vector varies so the memory shoul) be )ynamically allocate). #t shoul) have three )ata members vectorarray a pointer to inte&er< maxsi=e the maximum allocate) si=e to ta0e care o2 insertions an) si=e actual si=e. 8rite member 2unction, a+ Parametri=e) constructor ' copy constructor-each carries 7 mar0s 45!6 b+ Set value at a particular position in vector 46 c+ :o insert values in vector to 0eep it in sorte) or)er 476 )+ Print the vector 46 e+ #mplement the 8rite member 2unctions to 2orm intersection o2 t9o vectors. 476 8rite the main 2unction to illustrate the use o2 the class an) member 2unction. 476 ! .%esi&n a class Boo0 9ith the )ata members to hol) title< number o2 authors< #SBF number< price an) number o2 copies. :he title an) #SBF number are pointer to characters. %e2ine 2ollo9in& 2unctions, a+ parameteri=e) constructor 9ith )ynamic memory allocation 416 b+ )e2ault constructor$number o2 authors an) number o2 copies eDual to 5+. 46 Slip 31
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! c+ Copy constructor 46 )+ %isplay$+ 2unction 46 e+ 8rite a member 2unction to chec0 the vali)ity o2 the #SBF number it is a uniDue 5! )i&it number assi&ne) to a boo0. 3or 5! )i&it #SBF number< the sum o2 all the 5! )i&its< multiplie) by its inte&er 9ei&ht< )escen)in& 2rom 5! to 5< or ascen)in& 2rom 5 to 5!< is a multiple o2 55. 416 5!x5*Mx*1x*>x*x7*7x*x>*x1*xM*5x5!V ! mo) 55 Call the 2unction in the constructor be2ore initiali=in& the #SBF number. 8rite the main 2unction to illustrate the use o2 the class an) member 2unction. 476 Q.*) +i,a [10]
Q.1) Data Structures Using ‘C’
[Total Marks 40]
5 #mplement a list library $)oublylis.h+ 2or a )oubly lin0e) list o2 inte&ers 9ith create< search ' )isplay operations.8rite a menu )riven pro&ram to call these operations. Create
Q 2) "#ect riente$ Conce%ts an$ &rogra''ing in C(( Marks *0] 5. #mplement a class @print)ata to overloa) @print 2unction as 2ollo9s, a+voi) print$int+ - outputs value - KintL< that is< value 2ollo9e) by the value o2 the inte&er. e&. print$5!+ outputs value -K5!L b+voi) print $int< int+ outputs value 4KintL< KintL6< that is< value 2ollo9e) by the t9o inte&ers separate) by comma in sDuare brac0ets. 476 e& print$<+ outputs value-4KL
[Total
476
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! c+voi) print$char ;+ outputs value Hchar;I< that is< value 2ollo9e) by the strin& in )ouble Duotes. e& print$HhiI+ outputs value-HhiI 476 )+voi) print$int n< char ;+- )isplay 2irst n characters 2rom the &iven strin&. e& print$
476
! 33
. A atrix has ro9s an) columns 9hich )eci)e the number o2 elements in the matrix. #mplement a matrix class that can han)le inte&er matrices o2 )i22erent )imensions. Overloa) a))ition< subtraction an) multiplication operator to carry out usual matrix a))ition< subtraction an) multiplication. a+%e2ault constructor ' Parameteri=e) constructor 4 *6 b+Overloa)in& o2 * ' - operator-each carries mar0s 456 c+Overloa)in& o2 ; operator 416 8rite a main 2unction that uses the above class an) its member 2unctions. 476
Q.*)
+i,a
[10]
Q.1) Data Structures Using ‘C’
[Total Marks 40]
5. Create a ran)om array o2 n inte&ers. Accept a value x 2rom user an) use linear search al&orithm to chec0 9hether the number is present in the array or not an) output the position i2 the number is present. Accept ' %isplay 3unction 416 • "inear Search 3unction • .8rite a C pro&ram 9hich uses Binary search tree library an) implements 2ollo9in& 3unctions Create Binary Search :ree Search a no)e in binary search tree %isplay a binary search tree $Post or)er :raversal+ 476 ! Q.1) Data Structures Using ‘C’ • •
4>6
45!6 45!6
•
5. #n brea)th 2irst search $B3S+ o2 a Nraph 9e start at vertex v an) mar0 it as havin& been visite). All unvisite) vertices a)(acent 2rom v are visite) next. :he v is thus completely explore). :he visite) but at unexplore) vertices are ta0en up next 2or exploration. Exploration Slip 33
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! continues until no unexplore) vertex is le2t. #2 B3S is use) on a connecte) un)irecte) &raph N< then all vertices in N &et visite) an) the &raph is completely traverse). :hus B3S can be use) to chec0 9hether &raph is connecte). 3ormulate the problem an) 9rite a C pro&ram to solve the problem by usin& appropriate )ata structures an) al&orithms.
Q 2) "#ect riente$ Conce%ts an$ &rogra''ing in C(( Marks *0]
[Total
5.%esi&n a class Boo0 9ith the )ata members to hol) title< number o2 authors< #SBF number< price an) number o2 copies. :he title an) #SBF number are pointer to characters. %e2ine 2ollo9in& 2unctions, a+parameteri=e) constructor 9ith )ynamic memory allocation 416 b+)e2ault constructor$number o2 authors an) number o2 copies eDual to 5+. 46 c+Copy constructor 46 )+%isplay$+ 2unction 46 e+8rite a member 2unction to chec0 the vali)ity o2 the #SBF number it is a uniDue 5 )i&it number assi&ne) to a boo0. 3or 5 )i&it #SBF number< the last )i&it is a chec0 )i&it 9hich must ran&e 2rom ! to M an) sum o2 all the thirteen )i&its multiplie) by 9ei&hts alternatin& bet9een 5 an) is a multiple o2 5!. x5*x*x*x*x7*x*x>*x1*xM*x5!*x55*x5*x5V ! mo) 5! Call the 2unction in the constructor be2ore initiali=in& the #SBF number. 416 8rite the main 2unction to illustrate the use o2 the class an) member 2unction. 476 ! . #mplement a class @invert)ata to overloa) @invert 2unction as 2ollo9s, a+ int invert $ int+ - returns the inverte) inte&er. E&. invert$71+ 9ill return 17 45!6 b+ char ; invert $ char ;+ returns the reverse) strin& reverse$HcompI+ 9ill return IpmocI 416 c+ voi) invert$ int ; + 9ill reverse the array or)er An array 47< >< 5< 6 9ill be inverte) to 4< 5< >< 76. 4>6 8rite a main 2unction that uses the above class an) its member 2unctions. 476
Q.*)
+i,a
[10]
Q.1) Data Structures Using ‘C’ [Total 40 Marks] 5. #mplement a list library $)oublylis.h+ 2or a )oubly lin0e) list o2 inte&ers 9ith create< search ' )isplay operations. 8rite a menu )riven pro&ram to call these operations. Create
34
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! library $cststac0.h+ o2 stac0 o2 characters usin& a static implementation o2 the stac0. Push
1. Ban0s o2ten recor) transactions on an account< in or)er o2 the times o2 the transactions< but many people li0e to receive their ban0 statements 9ith cheDues liste) in or)er by cheDue number. People usually 9rite$use+ cheDues in or)er by cheDue number< an) merchants usually cash them 9ith reasonable )ispatch. :hus 2e9 cheDue numbers are usually out o2 or)er. Use an appropriate sortin& al&orithm 2or convertin& t time o2 transaction or)erin& to cheDue number or)erin&. 3ormulate the problem an) 9rite a C pro&ram to solve the problem by usin& appropriate )ata structures an) al&orithms.
• •
Q 2) "#ect riente$ Conce%ts an$ &rogra''ing in C(( [Total Marks *0] 5. #mplement a class :ime5 9hich stores time in 5 hr 2ormat $hh< mm< ss< am/pm+. #t has 2our )ata members< three inte&ers 2or hour< minutes an) secon)s an) a character array o2 si=e storin& am/pm. %e2ine constructor 9ith )e2ault ar&uments $mi)ni&ht+. %e2ine accept an) )isplay 2unctions. #mplement a secon) class :ime 9hich stores time in hr 2ormat $hh< mm< ss+. #t has three )ata members< three inte&ers 2or hours< minute' secon)s. #mplement 2ollo9in& 2unctions, a+ 3rien) 2unction iseDual$+ to compare time in 5 hr 2ormat to time in hr 2ormat 416 b+ convert time in 5 hr 2ormat to hr 2ormat 46 constructor o2 class :ime5 9ith )e2ault ar&ument 476 Accept ' )isplay 3unction 476 8rite a main 2unction that uses the above class an) its member 2unctions. 46 ! 5. #mplement a class @)ata to overloa) 2ollo9in& 2unctions as 2ollo9s, a+ int maximum$int< int+ returns the maximum bet9een the t9o inte&er ar&uments 46 b+ int maximum$int ;a< int arraylen&th+ returns the maximum inte&er 2rom an array @a 476 c+ voi) maximum$int ;a< int arrarylen&th < int n+ )isplay all elements 2rom the array @a 9hich are &reater than &iven number @n. 476 )+ int minimum$ int< int+ returns the minimum bet9een the t9o inte&er ar&uments 46 Slip 35
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! e+ int minimum$ int ;< int arraylen&th+ returns the minimum inte&er 2rom an array @a 476 2+ voi) minimum$int ;a< int arrarylen&th < int n+ )isplay all elements 2rom the array @a 9hich are smaller than &iven number @n. 476 8rite a main 2unction that uses the above class an) its member 2unctions. 46
Q.*)
+i,a
[10]
Q.1) Data Structures Using ‘C’ [Total 40 Marks] 5. #mplement a list library $sin&lylist.h+ 2or a sin&ly lin0e) list o2 inte&ers 9ith create< %elete ' )isplay operations.8rite a menu )riven pro&ram to call these operations. Create ' %elete at in bet9een< %isplay Operation Carries 7 each ar0s. 4576 . #mplement a Dueue library $stDueue.h+ o2 inte&ers usin& a static implementation o2 the Dueue an) implementin& the insert<)elete
•
•
•
•
•
• •
Q 2) "#ect riente$ Conce%ts an$ &rogra''ing in C(( [Total Marks *0] 5.%e2ine a class account 9ith 2ollo9in& speci2ications , private )ata members , account number automatically &enerate) six )i&it account number< 2irst t9o )i&it are use) 2or ban0 co)e $assume the value 1+ an) next 2our )i&its 2or account number$use static 0ey9or)+ account type it can be one o2 the 2ollo9in& type savin&< current< 2ixe)< recurrin&T amount lon& inte&er 2or the balance amount O9ner Fame name o2 the o9ner Slip 36
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! Public )ata members, a+ Accept$+ 9ith vali) account number an) Use o2 static 0ey9or) 4>6 Accept$+ 9ith vali)ation 2or account type 46 Other )ata members 46 b+ %isplay account in2ormation 476 c+ %eposit an amount in an account 46 )+ 8ith)ra9 an amount a2ter chec0in& the minimum balance con)ition 46 8rite a main pro&ram to accept in2ormation 2rom user an) open @n accounts $Use )ynamical memory allocation+ an) )isplay their in2ormation. 416 ! . %e2ine a class @3raction havin& inte&er )ata members numerator an) )enominator. %e2ine parameteri=e) an) )e2ault constructors $)e2ault values ! an) 5+. Parameteri=e) constructor shoul) store the 2raction in re)uce) 2orm a2ter )ivi)in& both numerator an) )enominator by &c)$&reatest common )ivisor+. 8rite a private 2unction member to compute &c) o2 t9o inte&ers. 8rite 2our member 2unctions 2or a))ition< subtraction. multiplication an) )ivision o2 2raction ob(ects. Each 2unction 9ill have t9o 2raction ob(ects as ar&uments. 8rite the main 2unction to illustrate the use o2 the class. &c)$+ 2unction • 46 %e2ault constructor an) Parameteri=e) constructor 45*6 • A))ition< Subtraction an) %ivision 2unction - each carries 7 mar0s • 4576 ultiplication$+ 2unction 46 • 8rite the main 2unction to illustrate the use o2 the class an) member 2unction. 476
Q.*) +i,a
[10]
Q.1) Data Structures Using ‘C’
[Total Marks 40]
5. Gea) the )ata 2rom the 2ile Hemployee.txtI an) sort on a&e usin& insertion sort. • •
Gea)in& ' %isplay the 2ile #nsertion sort3unction
45!6 476
Slip 37
Savitribai Phule Pune University S.Y.B.Sc Computer Science Practical Examination April / Oct. - ! "ab Course # $%ata Structures Usin& C ' Ob(ect Oriente) Pro&rammin& Concepts Usin& C**+ %uration, ours aximum ar0s, 1! . #mplement a list library $)oublylist.h+ 2or a )oubly lin0e) list o2 characters 9ith the insert< )elete search ' )isplay operations. 8rite a menu )riven pro&ram to call the operations. #nsert<)elete
! Q.1)
Data Structures Using ‘C’
5.#n )epth 2irst search o2 a Nraph 9e start at vertex v an) mar0 it as havin& been visite). :he exploration o2 the vertex involves visitin& all the a)(acent vertices ho9ever the exploration o2 a vertex is suspen)e) as soon as a ne9 vertex is reache) an) the exploration o2 a ne9 vertex be&ins. 8hen the exploration o2 ne9 vertex is over< the exploration v is resume). %3S can be best implemente) as a recursive 2unction. A topolo&ical sort o2 a )irecte) acyclic &raph is a linear or)erin& o2 all its vertices such that i2 N contains an e)&e $u< v+< then u appears be2ore v in the or)erin&. 3or topolo&ical or)erin& %3S is calle) on the &raph an) every vertex explore) is a))e) onto the 2ront o2 a lin0e) list that 2orms the topolo&ical or)er. 3ormulate the problem an) 9rite a C pro&ram to solve the problem by usin& appropriate )ata structures an) al&orithms.
Q 2) "#ect riente$ Conce%ts an$ &rogra''ing in C(( Marks *0]
[Total
5. %e2ine a class name) Cloc0 9ith three inte&er )ata members 2or hours< minutes an) secon)s. %e2ine parameteri=e) an) )e2ault constructors. Overloa) increment an) )ecrement operators appropriately. Overloa) extraction an) insertion operators. Consi)er hour 2ormat. 4*6 • %e2ault constructor an) Parameteri=e) constructor 4!6 • Overloa)in& o2 each operator carries 7 mar0s 8rite a main 2unction that uses the above class an) its member 2unctions. 476
! . #mplement a class H2ileI 9ith 2our )ata members< a strin& storin& the name o2 the 2ile an) inte&ers storin& the number o2 characters< 9or)s an) lines in the 2ile. 8rite the 2ollo9in& member 2unctions, a+:he constructor ta0es only the 2ile name as the ar&ument an) opens the 2ile< counts the characters< 9or)s an) lines an) initiali=es the other )ata members. 416 #2 the 2ile )oes not exist creates a blan0 2ile 9ith the name an) other )ata members are initiali=e) to =ero. 476 b+member 2unctions that count number o2 blan0 lines 46 c+ searches 2or occurrence o2 9or) in the 2ile 46 Slip 38