Endsem Paper 3
Endsem Paper 3
Endsem Paper 3
of Questions : 8]
SEAT No. :
PB3635 [Total No. of Pages :3
|6261}-42
S.E. (Computer Engincering)(Computer Science &Design
Engineering)/(Al&DS)
OBJECTORIENTED PROGRAMMING
(2019 Patern) (Semester - III) (210243)
Time: 2½ Hours) /Max. Marks: 70
Instructions to the candidates:
1) Answer 0.7or 0.2, 0.3 or Q.4 0.5 or Q.6, Q.7. or Q.8.
2) Draw Neat und Clean Diagram.
3) Assune Suitable data, if necessary.
4) Figures of the rights indicate full marks.
Q1) a) Explain need of operator overloading. What are the rules to be followed
when overloading an operator in C++?
b) How virtual functions are implemented in C+? Explain with help of a
program. [6]
c) Define a class string and use binary overloaded operator (= =) to compare
two strings. [6]
OR
c) Which header fle do we use for file handling? Explain the following file
handling functions
3 7static-238
31
seekg
ijiellg)
in) Soekp () 13091
tellp ()
exception in
05) a) What is exception in C++?Explain each keyword to handle
C++.
OR
2
|6261|-42
Q7) a) What are the various algorithms available in STL?
C++ program. Explain any one with
b) Write a programto implement map in C++. [6]
c) What is acontainer? Whatarevarious types of containers? Explainany
twocontainers in details. [7]
OR
Q8) a) What is the algorithn in STL? Explain sort function with example. (5|
b) What isasequential container? List various sequential containers.
Corjpare artays and vectors. [6]
c) 49.248.216.
What is iterator? Write a program in C++ to demonstrate the use iterator.
I7]
CEGPÖ#
248.21
PO13091
3
|6261|-42
M T WTF SS
|Page No.
YOUVA
Date:
Date
YoUVA
5. USe constconectness
6. Consid non-membeH tuntions tb Symmebir
opeuatong
7. Desine oveloaded operatrs as membeu t
on-mermbu tuntiomS, but not both guni
8- Be auoas of opeatr preeduna and a ssocok:
q: Test youH oveloadud o patot thotoughy
b) Ho rirtual tunctiong implementtd ulu
Explain oith help of a proqram
Enabling virtual tuntions
Huntime poynmrphiSm, oheu the onret
7untion to colu s deteAmi Ned at runtime rathuy
than compile time tte's a Simplicied
explanati om bf hoLo virtual tuntions
mpleenttd n Ctt.
Page N
YOUVA
Date
# incul <ioshea m)
USing amespae Std i
clas Shape 9
public
vìntual void olHa C)= 0
pbtic
int maun c S
Shape *Shape I = neuo ircle c);
Shapt * Shape 2 a neo RectangLé ();
|Date:
vOUVA
Shape l ’ drauo C);
Shape2 -) drauo);
delte shape
dulte Shape 2)
3
c) Degine clags Sbinq and uae binauy ove
opeHato CE=)to Compe huo Sbrings
class S tnng
ivate
chan* data
int length ’
Sting ()
delite [ clata
M TF
Page No.
YOUVA
Data
int main )
Sting Str| ("Hello"),
Shing Str 2 ("tHelo")
Sbing Sttr 3 (" World "ý
Out < "Strl
Cout K'str2:" <<Str2 <<endL
Cout <<"Str 3i" <<str3 <<end
YOUVA
abStra ct baße dasn C++
Q:2 a) What is
Explain with proqram
Droguam:
TO hiS eAanple i
Shape u the abgract base clas uith a pute
irtia tunction duauwc
Gruee y Rectangle a ducied clasSeg that
inheit 7rom Shape and inplement the dla
Int man c ue cLat obËlets of ircle and
Rectonge and Call the cua O kunction
throuqh a Shape pountu
The coret duau O kun ction ijis calld ct
wuntie based on the objects tupe,
dernongtrating polymphism
Page No
Date:
YouVA
dusbructo oitth the
6) Ex plain Virtual
a proqram
Program
+inlude <i 0Shreann)
USìng nameßpace st
class base
pubiC:
Base C)
COut (K "Bae congt u t z Cald'k
endlif
Cot <r "Base destucto7 (alled (endl
Page No.
YOUVA
Date
intman )§
Bage x baße ne Deuived C)
dete o bae
Counta optuatY-0
COunt
etLO this.
Page No.:
Date:
OUVA
fiend Counteu opetatrt+ (ounters
int main )
Count
cout<<" nibial count:" <<-getlount)ecd
Cout <<" Count attt --;"<KCqetlount)«er
Cout (< " Count att t+:<<cqet Dunt)kendl
0/P :
mitia count ! 0
(Dunt a t t t - - -J
YOUWA
checked
Set 7lags that Can be attu
opeuati on
Some klu I/o chunctions u
Checked to
Cod that Can be
detenMìne
b) Explain the t o ways'n ohich les can be
opened, open () and Using onstuctr uoith q
Page No.:
YOUVA
Date:
LfSheam ALeL
filel open ("example.tat")
iE CAleL is-open0)S
cOut K"Ale opeñed
Dpen) kunction "" Sucess7ully
s ng
< endl
fle2.cloße c
of Stream
ExpLaun types oSbream
what s Sbreamm iie 1sStrtam,
availate i n c+t
and ofSbream tshrtan,
abstractionthat
epresents a How of clata JEs a uau
or
ead o7 Lorite data to a device, bi le,
Stream9 provdle a convioient and tle
luttey opeuations
uy to handle input /Dutput
Theu aue seveal types of Stbrtams availaHe in
Page No
YOUVA
Date
4) ios :: ate - Open the tile and move the ile pointt
to the end ofthe kìe This mode Ght allows
yDu toStart unding on mtng rom the end
of the tile.
Page No.:
Date:
YOUVA
Example
0n te aCtt program that takes too inegs
as connmand une augumerde and én calculote
th Sum
Son:
#/ncde<ioShreaum
USing name Space Std
int man Cint auge chay * auqv DO)
cout <<" US ag << aNgvto]<c'Knuny
<num 2) "" << end li
Ex planati on
Check Lt the numbu0 qnunts( ugc)
y a 3C proqzom nome t 2num bes)
2Conveut the Sing g
M
Page No:
Date:
YOUVA
Sum: 12
iv) lp ()
Headou RLe to fle Handlig
un thu tollo urng huadu7ils
+ indud <FSheam)
# iodwudaiohêam)
4 Seek ()
Seekg () Sets the ioput position iadicatr to
Speci sied Location in the ti le
Examplas
if shream file C" example -txt")j
ile See K Cio)/set input poibon to lo +th chaactue
2 tellq()
tella () tuni the cuot input position
inddcator
Sheampo tellg );
Retn va
. The cunnt input po githon
Example
if Stream tile C"exampety t") ;
tile sedk C10) ;
wut <<ile. tellq C) <r end l; lD]P o
3: geeKp()
Seekp () sets the output posi i n indi ator
to a Spei7ieo ocation in the tile
oStreo.n qeckp (steampos p0 3)
M T W
Page No..
Date:
Patame
pos:The.po8i ion to 8et th output no
indlcato
Example
("exam pletxt"j
tile. Seakp Zio); 8et oiutput positio t
|D th chauaH
4 tellp)
telp C) tu the cwnt output poßitig
incicatos
SheampOs telp() j
Page No.:
YOUVA
Date
2. hogic ehs
Syate ehhd
2: catch
catch blocks handie exceptins throLn by tha
try bloCK
3:thOL
throo Stattments. expidty Hhro aan
ex caption
throw eKcptionobject
4: tho
e thoo Statments -thro o thu cwhns
excLption
Catcn C:)
1| Handl the exapion
etho0 Re-thsoo the exCeption
no encapt
noexcapt SpeiHel that a tuntin does
Page No.
YOUVA
Date:
Syntax:
tmpladL < typename T)
t n - type tunchan- name paamty
List ) 9 / Funcian bD dy
Date:
YOUVA
fMax int a e 9
Man dowre val9.g
templat Weite
’ la Templatis in Ctt
las templ ats
allbs you to Cate gunic cdases tht
can oork otth dittnt data bypts They
ene enates cod1 eeu and tuxibii6y
Heups
: vod nd dupication
2: mon codu kuxibiit
progming
Page Na
YOUVA
Date
Syntax :
templatu <typename T)
Clascloss Dame
WAAcUs dakiniton
Example Prognam
Unq namespae. Bbod
tumplat <hypename T)
dass
poivat
T ond
putic
I/ Consuctor
Pain' (ITE,TS) hst Ct), Second (9)2
J| Cett tnctiond
get rst () connst
T get Seond () const
/ Seter tunctianu
tio.
Void Strst (T f)tirs t =tjf
void set Sewnd(T3) Beondl = S
M
Page No.:
Date
YOUVA
Paqe No
YOUVA
Date
Chaufaun. Set fs t x)
out<<"Updateo Chas Pais: <KcharPain
qet Finst cy<<,"Z char Pan qetSecondl ()c
"Kstd endL;
DP:
Sht PouniCs,lo)
Updated Jnt Paus : C2o,lo)
Doue Pon: C3:5,7-8 )
Updated Dotte PainC3:S,9.q)
Cha Pain : (Az)
Upd cted Chau Pais Cx,2)
Q4)Ohaf do you mean Dy ethroüng
eXceptions wite a moqram to the game.
’Rerhro uing exception is a technique used
in excption handling oh an excption
Caught procasAld , and then t- thtoon
to be badled by anotheu excaption handl lca,
Lohy Rethrow EXceptions322
1 Additionad proessg : Petom addition al
tasks betone e-thtowing
2. Logginq Log the excptien to aucli ting r
duq ng
9 NotikicatiÝn - Notity othut parts o% th syst
Date.
nstane oh 9tiuntimeer
Genuic programmng
pauadiqm that allos ontina pde thdt
Can uork with oli ktent dafa typs
uoithout the need tur expliit type casting
6r 3epaat implementatiG bu each hypt
Date:
YOUWA
21 Opeuato Oveladung
Opeuaty overlogdLng alous ditinn
behaior to opuatos whenJ
Custum
Custom Lehaio
u0TKing oith 5dutned ty ps
3. Type Trat absut
Type traits poiou intomnationqennic
tupes at compile- time , ena
(oole to make decisions bUsea om tus
propeties
Proram,
# incude(io3heum>
# indude < tolex capt )
Uging namespa Stcl ;
las DiideBy 2euD ExCaptiem: pulti c
Std :: untimu ero
puc
Dì vidaby Zoxo Er cephon (conSt cha
messogl):
M
T WTF S S
Page No,
YOUVA
Date
pic:
do ubte cide cdotenun, dorte
num 2
utn pum um 2
Dutput
Excsptian (augbt Diisian lby zeo d
not alowed
W
Page No
Date
YOUVA
+he vaiOw alyoith
Q7 a) ohat aue STL 2 bxplan tny on
avalattu
hitu
’ The Stardaud Templab alqoithm8CSTL)
aous to
Ct+ provdes Heu n.
Manipwatng ata Shuctus
Cattanes and examples Os ST L
Some
alqoithms:
Jtorati w Alqoithm
-each
2 unst0m
Soring Algoithms
1 Sort
2 StateS00t
3: artial &ot
Se asching Algonttama
2- nd it
2
3: mergnpn
t
Set o BCchion
YOUVA
|Oata
<<endl
O/P
Diginau Amay : 52819g .
Sorted hray
| Page No,:
Date:
YOUVA
Std i: ghring
3ing name "Ai
Output
Map Ele nen ts
Aiee : 22
Bob :: 22|
John .
Aqe a H co 22
Updateod tqe o3 John : 25
map Elements astr deriSrletiam
Aice: 22
John: 25
T W F
Page No.:
Date:
a contaune What ae
types o Containuu 2 Explaun any
Contain er in detls
Stack
Prriomty ue
YOUVA
Date
Vecto
A dynamie @ay-ike contaun that
can qroo o7 Shiok n si ze
Element3
menoy
Pooide st random acess,ins eutim
and dltion
Vector Opeatiom
push back ( : Ad dsg element at th end
iO Set CO: tete elent at a gpecisied
positbion
Ramoei met at a Speified
position
Date
2. Set Contaunw
Set 0rdeLol contaún thatSt
An
elumurts
Etemetu a
tast lokup, insertian
Proile
dtlhon:
Set opeHations
i n g e ) n t a unique elnent
tind
tt iludls <Ret
U3ing namespac SHd CO:
Set<int>s =31, 2,3
Sinst (4);
cout <<"Elemnt tounal en dl
cot <<encdl
Page N0:
Date:
Seqntial conttaun
Q8b) What u a contanwy
vaious eanial
and ve tos
and anays
Con tauneS is a
Sequê nbial contaunens
H souen'al
(omp contaune n c+* that 3tor
elument in a uneat eanl,aln.
elument:
acces and maoiplation Dk
a gpeci hic odin
2: Vecto
4 Deq d
6 StacK LLFO
Vectos
0 Axed at comple- oynamic, Can
ti me
lCation
ohat a jtenatr? ite
Ctt to denon brato the use itHato :
Steuato
An ite ato is an obiect that allows
eel braversal oeh a ontain es elments,
proiding acces to each elament oithat
expo Sing'the undiling implenentation
Proa rammi
U3ing namespac Sfolj
# incude <vector
Date
tutuo
Out put i
Riwehst itraessal i5 43 2|