0% found this document useful (0 votes)
15 views

C++ - OOPS Part-1

The document discusses object-oriented programming concepts like encapsulation, abstraction, inheritance and polymorphism. It provides examples of defining classes and objects in code to represent real-world entities like vehicles and using inherited properties and methods to manipulate them.

Uploaded by

onlyforytb123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

C++ - OOPS Part-1

The document discusses object-oriented programming concepts like encapsulation, abstraction, inheritance and polymorphism. It provides examples of defining classes and objects in code to represent real-world entities like vehicles and using inherited properties and methods to manipulate them.

Uploaded by

onlyforytb123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

than galher function ligin toin

gohex)
toyethex packed vahíaber methede,
all have towise Mellad-
9t Login (O
nmahalks data, hulated pack cading
to infdea gaod 29i
for ems oths esentials kothaStaitonay
m clothei, lke togete
Schol
Conmbiaing eatit logi aaingl teaethox
l Encapsulatioy dat
heast Tae
tane Iahesi (O,
oaituted ohject kack buldig The
.C40bjet
Oietd
NGO. PAGE
GOLD
Data
Abst radin / Pete titig9 ne kicing inpem catati onal
to use.
dotils and
Ex ) Jonplementation dtails can enguey Coelig Breaking
lidlen eem the uer
itelace to iat esact with ham,
engáe, cte
qeanbx ayten,
chemial heacio in aú condi t oning

Possod5)
as

234CE.

3) hhesitance s- Code can be wten in a


"CzLd claser can in keit prpetiu om a
EX;-()
Inkeiing p pertiey clays
Bheske , spcak, facia Subelas- chiy
featxst, heatt das
Conditins ete
fesent class Common poties Inhited
Vehl de
to child clases

Seatag ap
Child caLser
Bite Car Tauck
4)
’Bkoas
ntanpulatim AaphlEa
lent a ch Whie ta
chd The
2 Vasiaee Ahat
det obiet ike
yen can
with are cas. cdass lite-ne be
Tzuck
- haeCan
mane, inwil Callacti inhetited
thL the may
centa Tyscetapspeed
No, same al
clae oihex haue
be o
Ags Aame boatSpace hom them
paht t Vantabledncitn
wntheiqun
Dhject a
ge utn bust
s et Veics oill
but DATE PAGE NO
code data Ositated t have
bike
yeoll
behave mean cass
andcoele
fdata, Comaen 20

bekane ont
abyeta Dilenant pupeiti
o
do
Exanplei- Once " . "
ain({int studeat
clas object class a class clases sreetc. "
t 20;namecha
each
On obje Mose
holNojinlt
getDotaik
()}void dt
detlh
Adent
shudent, a0se can rogram othey
; ke Ctf n Can ataeopeotitsiouun ae
deihed
cas i be rn
|| nell variables Run neal
S1 Considsed data
ereution piterat abot
, and
Nosheded2, class
that to tme
a woald
aa gethey 0r time
lete. o objets
9 as witot
codo. etities
ot
wil
shudent tye objeia ep
can we a Compl hresentatiom
ave class.
Becondod 3 bupit talke having
their ase Caeate
-the to in
eron
memeo a
functitnat anstherby wil code
Pepentiu o and
clcosass contain
supaas
popeta ohet Moreeche
exist
The Las be looks
pastitien) codeThe clNameass
Cause e
Code is Were
paateiedi publifeactios
o
hitance in i
declatation
Salable possible
0rganised
mone
prtdatoedtea
hedundant du
faen
to data
ixtehet
Subclasses.
ertended
small to obje DATE:
PAGENO,
code
ca/elauea.
20J
toseqmandalinLodiCodo'
lasge is
elininted, Can Co
Data Encapsulaton i- Encap Sulation Can be wsed to hida
data membehs ad wombes focdion. that tho iatemal
’Under Hhá dafinition , en capsulation Mkars
supresenation an
fom vieus
kidden
outide oy heobjct
. Data b hidden
dafiiion.

Oaly un ctios wappd inide Sanne stope. Can ac cesn it.


Date Hiding th prusProcats of Ano ving dind aces by objet ,
y Can unction to acced Auch data
Consder ao
Pasioond progham
n AA which u to atheticate
i'ne
to gam B. Bus and etuons
ony Trua / Fale 'to progam Aby compaing adual
Mee prootam B hide the inplemantation & UI acesibe
Prahan A never gt to tns he octa passwond but,onhy
now's i) ib pasDgrd is coyed on not.
do
Pple
0ata Ab sta titnm?
wth Hha fhelp o en tap sulation ma wao oe alo cachiee
data abstnion hich 'in ohy people ink that
ohile
uit doing enapulitin
access
Yu good andhtethoe
at the ame timo.
bundling
aO
otthin
J20
bas
PAGE
NO.
claues
unction ca0;
DATE:
Ah
Calcalate
achiered oitAmenbes
CE
nrapsuletin)
bossam sobje
State thi
a hdude
totlamz ncadth
achies
EncapAlatonDMembes int
btcadth obj-
AaeadH
26
b
encapsulati
data_code
we int
len ken As
ctdi Ret
elass hetsa man()
nt
dat ee"
How Cout
En
In all
()
) Avantages O These
(0) Exanplu ’We
eve Nowo, Encowuge we . We Tues
oyme
Readabili
that Aeadabiiy ode ty
acces Data ooihlnsg
can
settes what 2palswobd
wstmane
dat a
vast hy ned wou
what tncudes Set late
sote - i 1s
.
lik e st Used st ra
abto with
ct J gptesl Shows cble
Jntead chanad Hhe code objed ac on Looe
wi th
ane wok toset clincAeate
we Atne. cess 3 fo the
Countes
countes haue- inwh how were
didy above
want Gettersd
settese dat a Usi ng th a Settes? he a
Coder ights
wnitngo manipatin valus prote
to Inagne acues classer
Codiny abstraotonwots w Prvsam
vale. ito fA or
actels
k change. ctie
dicouayed. nghot mo a { res Usey
satting dilos
paadigm.. lo tnt the
ditig
Countes spe
eace, Class How
and vasiables
ssttig the þas
nny and ase Data
maltiple code vaiables
etchng cheted, th
eed value encapsultion amous
the ne
data , 3175 i lonth Abs
to
Lines by thus hraction
whehe
do 6ut data wayi wtoe 4
10 elot ) breath.
o )
when Let t Gettess
twAOint clas
Shaee getidth)int
wídth,
hetn
veod yod eiostasamz
ncede ok
setwidth sethight nbieti
ot
the
(int (tt exanple
w)! h)t data
object pute to
Megdpk oim wndes setidte
yad(int vod Sotters
Wsettes S tand
Getes
t rivate settaigkt
obiewct DATE PAGENO.

it
olon't o JO20
oidth wones (ind
denot
is A)
public in
acesi
the ble.
1.
EXampl2 Dutputi Thaidth
Cout " sdhaigkt(5);
Uust
das shepe. shepej
Shape
we
'Vsen
Cot Hincbdee
VserID;int
LAerID id Shows The
Ws
a he
i6stream width
Helght
how causeeo
be is
o2. i5.
absba Cant be /ttsvasiabe
names
eti idt
on oont
bt
acccssed
tount ac wook
data
ted" them because
manb
ers hy
ce
dl; ay
priuak. poñvate
tonret data
Patood
Lsexl.authenticate
Dooo);
("pass autketiak(Stisgveistad)
ele pasioond menbe sin
cosieot hd
Paswsallount
acated
soa:
fat
Cot e ,
paswose"lpgv! wethe
fet
InmetLassd
Sucesah"
Lagin lot
the

wll
knooutenteredwey
not
DATE
oak

be
passLoond

he
Acces Modrfess /Aces Spuafos.
c44 ackieed toith the els o Acces Modtkes
fe
are kaon as Aess speciiens, Clas mtnbers ( both daa mebes
md member unctiy can have vaying acceyi bil ty
alcels

Acces Spe ufa

(2)Psivate
() lrotted enbss will take privote behavio
Gi)
Same caly
Bpe
No No cid deivçd -dsub
Yes
boeted Yes Yes Can, be accegzed in he
Jas, inhetcd in a chd elats
bd cad be acceMed outide .
Yes Yes >(ite Can onl be acesed inwide th
Cae, it can not be nheited oY
accewed htsides
Accem specker inhei Acd cutiyah
’ any class menbers (date munbosenbtr tuntio) is
udes
() Ase acLesibls to evnone
(2) Can be accessed.
exs tindudo <iosthcan Bot mainl )
wing names pole atd; Ractagle ne di;
publie:

fnt anea)
braadth; hetun 0;
al()
O (z)
aating Dteuti tbheadthhuct20
e alaed to
Dal, class
can Redaagle
hedl, Rectangle
privatei clae
sele publiei the speifir
Acasa ath
eesviagottr setusn L
aneabacadth;
nt0Lungtisht,
meab ass
clbe
/sett the
length accesLed
es aboe Membes
ambeh.
seti' boead Ae
unotin
(2) pauate hy i
th
settiny o1 decdared
funct
e"Asea
Cout
publics Redanglclasse usiny data he
Vales 'nt pzivake ntes
asnd DATE PAGENO,
lughe;aea(int int names nembe daclased
via length, JD20
poce fantion ttaeni GOLD
fhunctpublo breadth std;
int , bside
a
Ci20)e,; b) ; clan. 'the 13)
inclde
iotream 6 (3)
hetm; 3 publi aCceibleThese 94
henited
psotected : Bat,
he'in lchild / s
note
danied Membx
the das aestd
blae paoected
fn ame A
the (s Acress
s
able den ubcasses as
photetad
wed
membeu accessibily
psiate
to
access casr ara chi) clareddo
/Can data (paut/supn)
/Bau
lprot clas.
nenbe inaccessible.
as ases
manbeis atol ndes
cceu a po
data teted can -
the cton proe
poteted
manbers
data
(huigli) memb outidoBut alo cted
data access
donsed
cas or. then
claebae membes, -
ae the
GOLD
PAGE NO
DATE : J20

DataAbstoa cton
inpleaeatatis ataih ox a pnceduse and just

Hhe outide konsld kackyzauad


dtailk fand iayplaanuataion the

Now theae ahe 2tpeaaabstastiouA


cases

Bt, theinpla neentatien detailu hidden


jut get tka duind output aithot shat
happcad ia the backagud
doses
n Cti, we Can
anctin inplemiadation
0e Loant to Rda

This done.
bhw Posta Absthaco Data En capultion16
’ Data Encapsulati on isths pocess iing the data L
(oghams from he ousde w0ild and euudiay
etiy
Dato abstoact'on is the prvess ol ding he inplemtation
'fside a'
the outide
data abstaoion i achiered with the hely o
data enlapsulation we Can S absta ction is he
ncapculation.

a) een ca betioen chay n me and chan nme?


c
CoutBLte ma0 Bat clasts Jagotant
yod Vaid fostacamz
#iucdse
housnlaagth CaLate
13 Void vofd
set bscadthhae Ractangle
Retangle. phiatei
Bacad setBheadth
setlength
t i we
do
2y( i
setsdlength (it
hcadth Bradth int
lea) cadi
(hut brc
(ínt len)
bhe)
DATE PAGENO.

JO20
maiO4.find Exole
A class cas cas <iostneam
aj inheited class+inclade
{A >
lçnot ly (otected:
ade: publicnamespacestd;iny
laa 8: pzivinty; int x
x0 xà ci
phivate inhesifedis
prelect å pubke
ot nhes
in inherited iakeited
inherted
heoited A
ited ed
nhost A inhenited At
{
fed bt but k
polected.
stasondadbut stay stay
& be be
comes
comes be
not pote puie
comas acceuible.not
aCcessible.Palvatepzivae ded
paole in in las
child.
cted chi.
4
Iahoitanle b2-1 bx1; Qe2 1
EasierLues doz1 dex1

totime
maintain kalows in
JnheitnceCttin
to Ctt |Ldoeay't
cade daean'wookt a ldoesn't
appicaia i

wok
wok
and au
asypuli
edit accessiblerot DATE20 PAGE NO
i
not
codes peedad
GoLD
uhuhited.
D.
(19
Modei
lsivate(3 (2) fbieMo(0
da
’hoteed
members
nembe livae
membe ’ ’ ’
ede)Th Paivate luble site Photeded
membelPublic
e Ex Saves
De
heases c
ac ded
cess class t
ble
membess Modai.
Membeu members me
3. A n
4
o! esibleacc-in el
base |Pivade
base in base
-accessible
clais cass
as fered
becone be aote das.
desied
Subclas1/cla)
Ci:ld Sucas.poy clas/base
Cone be |Pcted. class/
in Come
dohived
vate
Poiphivale (protected
peected
publie
clal.
fn in
deaived in
deoired cleired
clas. class
clas.
PAGE NO
DATE: 20

Slass Nanels Denised Cla i(Visbilkty hoda) Nanecof Bak clau


JPata Membas and

Inhois
OSingle
4) Hienaschical In henitan ce
Mulhipath Iaheidance.

laset "Tshesitan ce a a itelligne whase


dass
Can hae mose

Deied fn the ngle inkenitnck a clasi acqisin the


clas

The clas4 that acquisinç he behavias


child clas ox denivedclos os aubehak. called
emhich behaui ausk ta ken i
callad pas
pastit clasa
clask o7 kupta clau os base cla
22

clas
mithods
Vatiables ;

cas i Acces)_spe cife ldetved class


Pazt Methods lexiended om panat
child othad

" n int tanu, child a supuios t lart be cause the chid


has tb oon data and data rom the paeat hentas
laret has oly paent data.
" Hebgs he cha has both mcthods t
and deied methed parant -popnt () okoas lesat clas
wthod.
. Mane t advísable to cheate an object o the ehild natey
than the parunt.
Multi- levd Tn hatance in Ct4
class Procss hese an iherited elas
|Giadpaut parnt clas to
anohes clas.
dass last
lass A
lclais cl2 llaatains ory cau Aprpeot ej
das : pubia A eld AI/iternediale base clas,
"Hese
Los hehe Hhan
Keo
ce las class pasnt
ilass2.
an elas Bsumaíning. cas
fo
can aotie child
Mutiple at
his hae " he
a The
easen, the inkheitance. hem Iahoritance
nuttiyeaquihing panant owet
acces pro
sam aatile
O0- 1 alhiple Ces clases dovel
pasent
the
where i
desisneas methad belkauíauts ctt haha
s
claek
1 DATE:O20
moge PAGENO.
sane a
acces2
deoidad single
(-"ila Celld "and
a cepaliltia
patent capabi cas
to (23)
child lthes
2.
ltpatnhesitance.
sh Hybid vtal aw
clE
called it
nhetan
ca, hieranchtal L B
leuelnedt- Conbination
.e
hare,
a can we
whese
larent clas
clal Parat
Capabilti~s and properte Lovel
o< some the hae
hehitel inthe all ace.tnhesitana
be ad hi Hioah Galled i13A
..
laad Acces 1:
child clas
persnt
faret AcceChild1: cays
clas Patent
base casschild
k alled clas Singla, chelds
pasudlclas
ody
cas
(
Conte
A, Ee; chitd2-1
cass Syntax
) -Hedent --3l lass cas
m5 lltontins
child chidii
Mave son lboth pepeatiad
Hentaint
4childi
paaut
lbeh i
Contaiu 2i both
chauc AtCE
oass paset chidL
ACCes! acces pasent accce
poafatief popestod
)|do
4(0; m4 E. ppeh t
child
Childe pasent tparcat
24 chii
m)i
domgU s
main()
contains Cot
dataellVodmsl) Cas 1
Pubtt
fublies Ep
publci clas
Vod S1lcontai
C)
CoutceVod m2
ee'l
lllodai m30 pubtic clau H
\n ci iNcudo
ub mt
\a Voima)d
m5 lic public pubic DATE:J PAGE
ns n NO.
C m2 <iost
data A
Adata J20 GOLD

cosAt4E
( cloasossmB; MB eam
om pasenta b inhei caataom
A1 AtB.
(2S
A

You might also like