You are on page 1of 15

DPU

Dr. D. Y. Patil Institute of Technology

AssignmentNo.: 03 Date:

Assignment Name:

AWhat ispoínte., smant Pointe. and Shared poínte..Explaín


ng diagtan
andproqram.oltjaT

DlExplanthe use of explcit and mutuble. keuwords


oith suitableeKamples
MUTABUE
Jt fs used indicdte that a partfculardata
member of acoDst dass objectCdn bemodi ed.
4indudeKistream0
usina ngmespatestds ioetasutblaat
dass Test
public: Konataf bogi
int a ot
mutableint b; eti olan1)92ls
Test (int a0, inty=o)1

beyi Dnaiclon
i voidseta(intz=o) duabolans9N
q=;h
3
void setb (int y=o)
b=yi
void disp)
Cout<kerd)<<"a: "<Ka<<'b: "<<b<<endl;

Created with Scanner Pro


fi
DPU
Dr. D. Y. Patil Institute of Technology

Assignment No.: Date:

Assignment Name:

Lintmain uttaon
const Test t(o,20) hiasah sn
COUt <<ta<<""<Kt.b <KAn"
tb=l00;
cout<<t:d<c "<<tb<<\n; iclaa
retutn 0; aolanxe
gSAT
balhei tat
halh Expliotkeuuotd 200te
JF s used to markconstrucorstoot
implicitių convert types ioCttoasmnoliat
incdu de <instream>
using namespacCe std
cdass mplex
pCNate
double eal;
double ímaq;
pUblic:
Complex
Cdouble r o-0, double io.o) realCr),
nimag()
bool operqtor ==(complex rhs)

euro (red] rhs- rea) jmag= = rhs-imad);


Tba

Created with Scanner Pro


DPU
Dr. D. Y. Patil Institute of Technology

Assignment No.: Date:

Assignment Name:

íntmafnDi ikot qu
Complex
coml(3-0, o.0);ilaa ht
odk balt)
apielseiibn olaan
cout <<Not camehiy atia DAMLIU
retum o; 29d11t

io0)9dut ut

t
SamelxC)

|Dİfftentiate obh comp e. me ipolumorphlam?


iunime
polymatphísm
u
ilu j'oani
COMPILE TIME RUN TIME 22n)

The call to the functíonsThe call toa the funcions


Jhavfvg the same ndme. havivatISame
olname is
esolved at un tme
is Sresolvecdat compile
tfme
2Andion óverloadlugaD Auncion overrfdwa
Imechanism snsbd. h mechanfsmifs utedubed.
leniisti movidesfact
2911exeton. ic i
2201
tprovídesslouo
iuexetionsd
4.Alsokoun as early Also knoUn dsate
binsliug statíc bíndiug |bindiua and dinamic.
bindin,tui frt
5Less fexíble. as all Įmore texibleds all
Jdeúsíonsae taken at
at Ldeais1onsale taken at
|compile me-. un-tfme

Created with Scanner Pro


fi
fi
fl
DPU
Dr. D. Y. Patil Institute of Technology

Assignment No.: Date :

Assignment Name:

int matn OEitaL


CompleX com3-0,0.0); l
iti(tom)= -0)oa
idcout<K'same"; otat 10
elsebibihot0GaD 0DD
cout
<<'Notsame"oy tit DDL
reumo:
SamexS linhe ln t1
rt
Differenttate oblu comp e me olymorphlarm
ikUOtme polujmocphísh ooh

TIME
LiL j'pa
RUN TIME
COMPILE

The call to the functfons The call: toa the functfons


havfvg the same ngme. havíuaitsameol.name is
|is resolved at compile resolved at un tíme
Hme
2Auncion overloadiuga AunctionOUerrfdivą
mechanism fsued. L methanismic fs uted-
nlnsaIt prouidesfosti K tprovícesslou
231executfon.
i 220 oteexeition:1
4.Also kooun as early Also knon as: lcte
bindug static sirnalisg |bindiug: and dynamic.
bindintii tri
5LessHexíble.as all more fexlble ds all
deisíbns ae taken at Ldexfsions ale taken at
ompile me-. run-tfme-

Created with Scanner Pro


fi
fl
fl
DPU
Dr. D. Y. Patil Institute of Technology

Assignment No.: Date:

Assignment Name:

a)Explain ohat fs tpe castiug nplfdtutype


oastiug and explfT typeccadtfna la
pe
→TpeOcasting is the process 6onuertínq
One data type into anothes in'a prograthming
Lanquage
|Language ts afundamental
operation hen
oorkiua nith yariablesand exptessons
aftferertt tupes

•dmplfcit type astivą (Automati type casting)


Ut'ocCrs automatilallų by. he compilet2olo
he need for explicit instruchions ttorm the
programimert iholves"onvextfna, iaitivalue
|Aom one data typeto anothe. inawauy.
that doesn't result indata Loss precfsino
prectsion
Loss 10

20ctbguint a= 5
ldoubleb=d;wiod tk la

Explicit tupe tastiug,. (manual type casting,)


3tinvolvesthe pogrammeA.expleitųspetltyivą
the tqpe.ConNercion..ts used whenctheo
Omplle. cannot. perform the onversionautomaicallų
due to potenttaldata Loss or precísıonsissues:
181214
doubleaE 51;
int ų = int) u
diyet ilpnldik2g1a 229

Created with Scanner Pro


DPU
Dr. D. Y. Patil Institute of Technology

Assignment No.: Date:


Assignment Name

49luite Ctt programtot_poínters to baseclass


#Indude.<iostrearm
using- namespace. std;
dass Polugon
ptoedted'
înt wídth height
Lipublíc.: o
VoÍdset.-
Values?fnt aint b) n ai
91t u pidth=a,height= bonut
ban
iny
elass Rectnglepublic
Blugoni wyiluh
lot A

rs int orea()bono 2210


aietum uidth*
helght,
iJDNSi intt
bir4elb
h dass Triangletpublic. foluqpn
public3
s iintu
tt
area i aoiau3
etotulf reurn'iwidth*heighti2a) n
fnt
mainOf1122DDbit t
bRecánglefet;uf
Triangle tral:
lt
Polygon*ppolųl= rect;
Polygon*ppoly2= tqls
ppolul-> et values,s);
Ppoly ->.set-values (4,5);
cout<<rect.area() <<"in'
cout< tralarea);

Created with Scanner Pro


DPU
Dr. D. Y. Patil Institute of Technology

Assignment No.: n Date:


AssignmentName:

22 return 0;in'
hattaci hubai

tbaiodtbiy tai
5)ohat ís vittualAnchion?HoupÎs itditferernt
ftomfunctfon
auertidíuaun b bioz
→A vítudl tuncton Ísusa:merbetfunctíon that is
decdared uitihfn a base cass and rede nedby.
Laderiveddassannl it slut3 221
Avirtual tundicnfs a funchiondedaredio a
|base doass oththe keuOotd "ictual indícatiuą
that it maybeoverrídden byicderivedclasses
Mirtual Auncions enable dụnantc dlspatch,
allousiną the apptbpriate. ftolbelcalled based
LOntheactua)ype t theobjectiatruotime
Funcion overridiuąon he other hand: is te.
Jact& pIDvídiuaalcpeiffeuinplementation
Ifor a rtudl in a. derived dass:t
Jallous the derived dass to replaceor: extend
thebehauibus¢
the thevirtuql nherited
from the base dass

.(2
2aulot a add

Created with Scanner Pro


fi
DPU
Dr. D. Y. Patil Institute of Technology

Assignment No.: Date :

Assignment Name

223 reurn 0;

20 221

5) ohat is virtualAunctíon
?Houo fs it ditferent
fom
functfonabverridfna slr bio
A irtud) tunctionÍsamembet functfon that is
ldecdared nithin a bdse dass and rede.ffned by
la derived dass
Sit lt
JA virtual tunciun fs a Auncton derlaredin
220

|base cass with the. kejaard "irtual Sndícattg


that it mau. beiioverrfadenbytdet veddasses
Nirtual tncons ehable. dynamc dispatch.
lallousing theapplopríate fM to ibecatledbased
LODtheactua) e f thecbịectatruotinne
Funtion overridíuąon the other hand is he
act 6f pIDvtdiaaispeiic
en implementation.
for a vttual n in a derived ass:t
allouws the derive dass t replaceiot:
extend
the behauibuaG the virtual nherited
ftom the basedass:

Created with Scanner Pro


fi
DPU
Dr. D. Y. Patil Institute of Technology

AssignmentNo.: Date :

AssignmentName:

9wrte aa programto create q le feddand


uwrite the rerordinto ft. Every recotd contains
Enployee Name.,1d and&alary Store) andretieve
tbastg employe.datd-
V indude <iostream> #intude<fstream>
ucing ndmespace ctd;
dass
charName 20]:
int ID;
double. calary;1oi"st.14)9
publici H
void
accept )
cin >>ndme
ti i0 D
cin>>calarų; plg2i jo

Noid displauy)

Cout <<n Eotername: "Lnames


out <<" nEntertD: "<K ID
cout <<"\ot Enterisalanga<<salanyi

înt main)
employee of3];
fstredro 00001

int i, 0
fopen
("blG.txt"); iasz
eout <<\n HowmanyEmployeeinftnaton ?:

Created with Scanner Pro


fi
fi
DPU
Dr. D. Y. Patil Institute of Technology

AssignmentNo.: Date:
Assignment Name

cin>> n toat
iloout<<\nEnterinfo ofEMployeel u
forhCi=0i<o;itt)nhr
cout <<"In Enter intoo"K<iK<iemploge\n';
oLi).aceept(); 9)342 9
f.urite (lthar*)fo,sizeof oti);
fclose() ia
f.open( ble.txt"ios::in);a it at
isily
Cout <<"n Into ofemplbyeESis
11

for (i=0, i<n; itt) hint


f.otite ((char+) oLi] izeofotiD);
o]display);
4.cdoseCO: ustaskLiote
returo 0;
91
sP
Howmonu emlbyeeinformation

Erter nfb ofoEmployee.


Iratesh
119
Wo000
Eter info of emplbyee
1
ri
sunil
L0211tc
("tytald"n10
99U0M
2000 0

Created with Scanner Pro


DPU
Dr. D, Y, Patil Instltule gf Tethsalogy

Assignment No.: Date

AssignmentName:

Enterinfoof 2empoyee.
megha

30000
Info Ofemployee is:
rakesh
"xT. d:11

sunil

20000
ImeghadE Abr
LID3 :gibt001 r
30000 eti :iI inb
9Explain efror handlfua inle Io oith cutable.
is quite
ohile reading. data
tommoo that errotsiimaų occu.
ftom a le in Ctt or uitfug.
Jdata to a le. FaA eq, an error mau aise
due to the fellouiug
hen tryíng to reat a e. beypndindícate
2When trtíaaiito ead aui ilelbat doesntiexist..
3|1Ghen tnt ua to Use a le that has not been
cpened OL
4utheniyíug uto usel1a le inian inappopriate
0smcde.
sTuua to
t wntetba
read-onlyna tle
todhi

Created with Scanner Pro


fi
fi
fl
fi
fi
fi
fi
DPU
Dr. D. Y. Patil Institute of Technology

Assignment No.: Date:

Assignment Name:

Híndude <iosttedm>
#indude <btsstdctt h
int man)
FILE* tp;.
charfeedbackI l00;
Int i ("Geeks.TAT,"w";
fp fopen
doasot

(fp'=ULL)
pintf ("\nThe ile tould not be opened")
Openec"
exit(1);
printf " InProvide.teedbackthis_asticde"2:
Hgets (feedback to0, stdin2:
for (1=0, í<feedbaukLi]; itt)
tputc (fedbacki], fp);
sini ifftetror(fp)) ihatd
pintf ("n Eorwitiuą in ile"
fortf slic
lida
fclose (fp;
ot
-n
a
e)Explaín theitfollousing
192d
leLhandlluaf .
1:open)
toitBestablishestheconnectionbjo.a e a
le descrtiptoa Jt teates an open e. desciptíon
that reterso ha ile and sa
open e desripto
that referso that open le desuiption-

Created with Scanner Pro


fi
fi
fl
fl
fi
fl
DPU
Dr. D. Y. Patil Institute of Technology

Assignment No.: Date

Assignment Name:

2-aet()
tfegdsa single
chatacker
from et
3getine)
allons ateptiuą and feadlíug. sngle and multiple
|iine stiwqs ftom the 3p aream-

4.tellą)
Tells n position of get-pointea
22Dl)
221l 220)
iuai
5 seekg()
NT
tmovesgt pointe. t a-cpeifed locatfon

6.ceekp O 220
Jtmoves1put ipointebto stheimenionèdJocation.

4)0hatiis le.ipointe orite donote onile openíug


ledosiuą"
→he ilepoínteiponts s
The used fbr Iocotiug,
theptsftionin he le.
uheopeníug a ethenproaramestablíshesd
Ltonnestíontt dlowtuą, datatranstea Jte
lessentialto handle patential. ertots. duríugpa:this.
pmcess,like le not tound
Closiuq a ile is eguallųámp to releaseystem.
resOurel Faîlue to dose aautle maybileadto
Ldata cofruption or oss bio
Aluaya practice ef cient Hle.manaáėment to
uaintatn! the inteąrity o dato
naintaln syctem
qyctem esouce

Created with Scanner Pro


fl
fi
fl
fi
DPU
Dr. D. Y. Patil Institute of Technology

Assignment No.: Date :

Assignment Name

5)Explain sttegm casseshieratchų for ilehanlfvg.


lin Ctt
IOs

till (
b jstredmwbtst biioStreampn
Dint
ifsiream ofstream
blli
os class. staiog Tby
aaití2oaa
Tuic dass is he base class for all tegm.
clacses The stredms Can be input orlroutpute
streamsb9h
stream dass
-4oilrmae bÍstteam class. bandlesıithe tuinputsttedm
Ct+ programmív lanquAge Tlese input stteam
obịets areiusedtoiiecCand jt nterpret
Hhe. input as acequence. charäcteis
1O b92 elaion

II Handles
ostteam Jass.
Gpsstteam: Theit Cp sttedm objects
are usedo oite data asasegueħice
chalacteS oLthe iceeen: bd
22:1g
a#]ncudebctteam
ncing- namecpace std;
lSnt
malnt)
n
: ieitte

Created with Scanner Pro


DPU
Dr. D. Y. Patil Institute of Technology

Assignment No.: Aner Date:


AssignmentName:

cOut <<Tc. output ic privtedon sreen"


put"
puts ("Tic output faprintedusiną puts
fnt
cout <<"Enter a oumber":
ủn S>no;
coUt << Nursber entered:<<Do;
char chTIo]:
puts(" Enter achatacteAaray
gets (ch);

Created with Scanner Pro

You might also like