You are on page 1of 10

Name - PurVa Balasaheb Gaikwad

RollNo- 22313.

The.ory Assignment 1

2What is a class and ohjeck


class
I+is user defined daka tupe ulhich holds its
Dun data 4ee membex and membex functions uwhich
Can be a Eze ssed and used by creatiog an înstanie
0F that class.A Class is like blue print fox a n
object
Exam ple
Conside the class OE CarsThere may be
many CaY with diffexent names Brand but all of
them will Shae Some Common Properties like all of
themwi have h WheelsSPeed Limik Mileage Tamge
limits etc. So hereCa is the cloass amd wheels
Seeed limits mileage ae ther Propexties

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

2 ite Shost Notes On


)'this 'Pointe
2 (bey Conshuck

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

buLt "\n prO 9Yam fox this Poin er"


thisPoin ler a (300)j
Yetun oi

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

3 Explain friend fumchiom with example


2 DTt 1S fWnctions which are not Part of he
elasS butjtCum access the Private amc
PTOlected membeSO he class.
2) They hare SPeda erivilage to accesshe
members oP the class but not Pamt OE he class
) The Protoype is Scume as tha Of nom a
fwn CHO) Lwith Priend key word at the SBaa
fumcion

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)

JDe fi nation o Fum chon

Example 0P Static membe

+Tnclude <ioshream> h
Using n amespace std i
class sBaic fun CHon

Static int COunti


intaj
Public
Void fun ()

a = 10

COuk n Prosram £x skaticmembear funcion


Stakic-Funchion ai
fttnchio) a.funt)
Sadic.funchon: funi ()
Funchion caled without object-E
teturn 0

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

Example af Inhne Function


#include iosheam
t+ include <shing
Using namesPace Stdi
inline Void displauy )
Cout \nThis Is inline Hunchon"

inline int add (inta,int b)

retun atbi 3

int maio ()_

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

0.S2 hat ane he Propenhies ofobfect--0fented Pogramming


bject osien teo Progyammin 9 Is based on object
Albng with ConceptS OP obiect they Provicling many
fund a ment als ConceptS Which ame foltouss

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.

You might also like