Professional Documents
Culture Documents
RollNo- 22313.
The.ory Assignment 1
object
Anobiect is an instamce of ClasS. when
class fs defined no- memosy s allocated but when
itIs fnstantiaked ie on cbjetis reated mem oy is
allocated.
Example
class Emplovee
Chay name [2ol
int id
Public
Void gebdetailsE
0tmain
Employee Eme Emp is a objett
his' Pointes
DThis Pointes is fmpoztan+ conceph în Ctt. It isUsed to
get the address oF Own obfect
T has implicit Pasameka Ho aul member fümchon
wecan use this Pointer inside any membex unchon.
for ino/oking the 0bject
3 f tuvo Vayiable name axe Same that time we
Ctu uSe this Páinte t0 diffementiate betuee
the VaTiab les
Example l
include ioshream?
Using Namespace std
elass this_ Pointea
in+ Cbmt
Public
this-pcin e int (Ount)
this-7 CoLmt 10
Cout 4 \ n The value oE COwnt passed by ob)ec
s ' LCOumt
COut <<In The Nalue of counk in this cloass is
*<4Hhis-2 LOUnt
int maun O
OlP
Progam for this Poin tir
The Vaue Perr OF (ount Passed by obieck 1s 30o.
The vaueoF Coun in the class islo.
COPy Consuctor
+ s SPeclcConshuctor in
Ct+ to Ceat new object as coPy 6 exiting
obiectIt is Standard toey bECCpying obiech
n C++ finst axgumen+ to Such (onshructo 1s
heferente +o 4the obleck bf he Same type
T i s use +o initiauze one obiect from
anothe obiect 0FUme tuPe
3)T+(am be wed to LOPy am obiect to Pass
asangument o FuncHon
4) CoPy am objec to retun it from fundion
Suntax
classDame (onst Classnaneobectname)
IL Conshructor
Suntax
friend fumchiom- PzoBokype
9)They Should be declared inside the class
deeinahon of friend Punchion is outside the
class ScOPe
ExamPle -
4+ include ioseam
Using namespale sBd i
class hiend-class
Privedo
in+i
Public
iendclass C)
0
3
Friend inam fum chon ( friend-class)i
iD+ my fun chom LPhiendclass c)
C Soo
reuanc
3
int main )
COut(\n fmend- funcHon Progrum
fiiendclass Fi
Lout L"In Valuue of vaiable Is
< mytunti
retumO
0.4) Explain sBatic Membes kiline fumciom_with Exe2
Static Members
Dstatic member fumcHoms n beaccess ony
StaticmembeS
They Caled using the className k notby the
ObJect name.
Fumciom hould be dedaned with static
KeywoTd
w e cam cal steutic mem ber um chions eve
IP Dbieck oF the class does no existS
sThey are mostly Wed to check wehe Some
obecHs oF he class haren Created orn.o
Tnline FuncH om -
are used to store the ye cUen ty USe
Fumckiong
InstrucHons.J+ is also to modulaize the
Pogrem
am,
2) FuncHion Save memoTy_JPace of h e Prog
3) whene\ven the funliom is Called.inshucion
the Humcion
Poin te iS Jwmped to definiion oP
funciominsbruhi
Afte complee exe(uion.F
Point (ome back to h e nsuchom rom.
Wheme i t made aump
include <Stdio.h>
Void fwnchomname C) K.
shCe 1
intmaun O
SP 2 fun Lho name ()
9)In inline Pum.ckion unchionCall is replaceed
actuol Program Lode
S I does no jmp to back Code genercuy
hey are ne commend ed o Smal com.putcuton
6) is moxe lilke noama funlhon wita
1hiine keyword at he dime of detlaation
Of fum CHon
Suntax
inline um Chon-Pro to ype L)
+Tnclude <ioshream> h
Using n amespace std i
class sBaic fun CHon
a = 10
olP
PrO9am foz Static Membex unchHon
This is Dmal Funchom 1o
This is Static member unCHon.
Ttcan access bnly Static Membex
Intiall Ualue of Stahic Variable iS:O
retun atbi 3
Cout
L"In This Pogram is fox inline
function"
diselay Oi u
intaa ad d C10.2o)i
COuk<\DAddi'tion ofnumberis <<aj
relum O
Olp
This Po9voms for lolíne fum chon
This is înline fumchon
Addition of number is i30
Namespaces
1.AnamesPace is a declaradive TEIion that Prouides a
StOPe to the iden ti Fiers insi de i+
2 Names pa ces are used to P/ent name collision thbot
Can occur especialuy when youy Code base encudles
multiple librasies
cla sses:
1T is user define data Hpe, Which ho lds its Own
daBamenmberS and member unckon. Atlass is like
blueprink for an obiect
obiects
An Objen is cun instance o class whem class is
d e h n e n o memoy i s aloccched b u t when it is
tDstaan+iatede am object is Ceaked memoTy IS
auocatco
40aka membes
5. Meth6d s
Messages
Oaka encaPsulahon.
8. Daa absacion informahien hiding
9 tn hehance
Lo. PolyMOsphism.