0% found this document useful (0 votes)
10 views10 pages

Opp Ass2

Uploaded by

Omkar Kumbhar
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)
10 views10 pages

Opp Ass2

Uploaded by

Omkar Kumbhar
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/ 10

Namei- Omkar Kumbhar

Ro'lNo:- M11?5

Title :
Assinnmeat -2 EYMGA

Wocking of objects nd clasç îoin Ctt


pspgfammig
objectives
To illu sbrate the coocking af objecis &
Classin
Poob lemstcitementi
I. Waide a Ct+ psogsan to Caleulade Area
Qnd olune of somusing Class ancl
an
oject..
Wkite a Ct+ Psoqsam to pxind yoce follrumber
4sinq class and object
3. \Wzitec C++' Psosam to soxe andDisþla
Enplbyee Iao[nadicn
Sotwose & Harol96e 6equise mests
Teeteditor and Terminal in inue
Tusbo Ct+ lompileX instcllec) on PC.

TheoatcHtclasscassis
In
is a lemplate
o qsoup of siilar objects
som ohich obiect ace cceatecl
Cen heve fielos, methodg,onstucos ec.
Syotaxi
cass ClassName
access5peciEiey:
DBedy of the class
C++ obecd i
tt, object is worle enitity,
tot example, cheqc, cay, Pea, molbile, lapop eBc.
To othér tworcls object is an entity that
has state ancl behevior. Object is a Tunim
eotidy it is Cseatedl cet îuntime. ehiect is cn
jnstance of a class. AJL he menmbers G the
lass cCan be acceSsedthrough cbject hen
a clacs is elefgeod anly tie specilicdion
fos the obiect is_depoed: nomemory or
Storage ia allacatad. T0 clse the datc aoel
acess function,s defined in the clase yaL
need to cecte ohjects.
Syorlat to Cseode an obËect :
nle Ca_(seate an obiect c the given
Clase in the same tway eue declase te
Verables of any other hbull6 data ype
)ClassName 6bjectNeme;
Code&
)"zie
Waide a ct+ Psagócm o caleulate Arec
Linstrelg laci ancl bject.
tincuce
using nemespace Stods
1lesecte a class
class Room
pblic
double enqt
double breadth
double heighbi
cocahle Celordatearea )
Yetusn Jength * dseadth
double Caledate Vola meC)
Teturn lengt *hseaci* height:

jnt main O
lcecde ohiect of Room clas
Room aom;
lassiqn aues to dato membecs
Tooml. lenh 42. 5:
Kooml height =19.2
Calaaale
&alispley the aea &
volume
he Gon
Cot e<" Asea o? Rootn=
"sooml Ceeclete-6enc).
CatAge Youme Roomlroom).
Ketusn o CalcalateteleuseC)
leocl.Q;

Axea c Room = B09


Volune Room 25132

Actvil
2. WoiBe a Ct+ Progsam to sint yocr roll nunbor
ancd Name csing olags and objecd.
Room.c+

Ja.out
nca@nca-ThinkCentre-nco-50t-Gen-3:-/Desktop/onkar.NCA
NI175$
ma@ma-ThinkCentre-neo-50t-Gen-3:-Desktop/omkar.M..aE
g++
MI175SIE
Nca@nca-ThinkCentre-neo-50t-Gen-3/Desktop/onkar.MCA.M1175$

MCA.

07:26
8Oct
-ThinkCentre-neo-50t-Gen-35-/Desktop/onkar.

Save=
25132.8

1309

= Roon
Room
of
Mcaenca
of Volune <<roon1.calculate_volume()<«
Area room
<<roon1.calculate_area()
<<endl;
-JDesktop/omkar.MCAM1175 the
height;
of
Room.H
volune
th: *
breadth
bread and
double
calculate_volune(){
double
calculate_area(O{ members area
* length*
class
length
the
roomdata display
double
breadth;
height;return return
double
length;
double
Roon
of to Roon
length=42.5;
room1.
valves
object breadth=30
height=19.
roon1.
and of
of
using
nanespace
std; Volune
calculate
class Room
rooni; Area
1#includei0strea assign
create
public:
room1. cout<<
cout<< return
9Terminal a 6 class
Roon{ ){
Create 1/ ||
main( 1/

Open || int
18}: 35
)
2 4 20
3 8 9 2 13 14 15 6 7 9 21 22 29 31 32 33 34
Activities
Q.2 Mhide to poinf your roll amher
aocl AleÇ using élass cod objct.
#lnchdo <iosream

class student f
Puslic
iot fel doda member Celsa iostance liodable).
3ting dlme; ldkta medeclalsa ingacee1leciable

Stuclent SL; locecting o0 object ofstdoat


l d = 201:
34-name= Sonoo e Toistua"
cocut <<sl. id <Kebdl
Cott lSl. Dousneleod
6etusn 0;

Olp
JaiSewal
Sonoo
c++
student.

veriable) Cada-Titnktentr
neo-S0t-Gen-3D
MCA.M1175Sla.o
g++
tnstance
veriable)
M1755 carcaTinkC
5at-Ces-3
CIT5^
instance
member(also
Student mca@mca-Thinkcentreneo-
ThnKCentreheo-S

the

(also of
object
menber
String
data
nane;// Sonoo
Jaisnal
:
an
datà create
cout<<s1.nme<<endi;
cout<<s1.id<<end:
ld;|
s1;I
s1.id
=
201:
std;
int :return
s1.nane
=
Lnclude<L0sreT
public: Student
namespace
3class
Studentí
19
int
main(){ Sonoo
Jatswàl

Terminal
Eaca
using
8}; 19
} 201
18
11 12
1 2
Activities
Qe corite c Ctt ProsACn toSBose cod Display
Imploee Tafoxmodion.
inckude iostrecn
uSIng namepce stol
ca mployée
Public
ic: / dato membeclalso jastance Mesiable
int id
Szingnameilleata member Calso insteunce Vesicble)
yig
float saloxg
Void inserb Cint i, stringn, fload s)
id

2
Salary= S
vaicl display

int mainCvoid )s
Employee elil&ectiosg object ef nployee
Enployee e2lnting Chjeet ofnpleee
el. ingeart2o1,enoo !, '99 000:
P2einggaT202, "Naku!" 2goo
el: clisplay);
e2displayC);
and prcgtamtninq
ok
ted! onobiects cnd cleasses
n lndlersordinq
the objecis
depondenty
r of coith
interadeol beCcn
aocl methodewnDsaperkies
and heir
hjects erecte toUsed a
Clacses
*ocusren
1
9gO00 Nan
Sonoo 20)
Terminal

open

1#include <lostrean>
2 using namespace std;
3 class Enployee
4{
5 public:
6int td;//data member (also Lnstance varlable)
7 string name;//data nenber (also Lnstance vartable)
8 float salary;
9void insert(int t, string n, float s)
10{
11 id = l;
12 name = n;
13 salary = s;
14}
EN 15 void display()
16 {
17 cout<<idee" <<name<< "<<salary<<endl;
18 }
19 );
20 int main(void)
Enployee
21 Employee e1; l/creating an object of Employe¿
22 Enployee e2; //creating an object of
23 e1.insert(201, "Sonoo,990000);
24 e2.insert(202, "Nakul, 29000);
25 e1.display();
26 e2.display();
27 return D;
28

mca@mca-Thlnkcentre-neo-50t-Gen-3:/Desktop/omkar.MC.
Gen3:pesktop/dkar MCAZMI175$ gedtt employee.c++
Ncacnca ThinkCentre neo-50t Desktop/oka MCA MI175Sctt enployee.c++
RCagnca- ThtnkCentrneo:50t-Gen:3:
ecadricaThinkCentreneo-s0t Gen-3/Desktoplonkar MCÁ MII75SJa.out+
201/Sonoo 990000
202 Nakul 2900o0.
cagnca ThtnkCentre-nea 50t Gen DesktOp /ookar MCA NIIZ5$

You might also like