0% found this document useful (0 votes)
22 views19 pages

OPP Assignment 1

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)
22 views19 pages

OPP Assignment 1

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/ 19

Assignmest- 1 Damei

Omker Kembhur
;- To xplose basic Concepts of oPP though C++

Ohiecthyesi-To stuchy hesicondamental Concepts lixe


asiables. data tupe Costeol Structureg and fntions
C++.

Psoblem stateneati
Waite proqsam tox Adding to Dumbess in Ctt.
2. ++ poognan to checkif a fumber is een
3. Waite C++ proqsam to fiod lagest number am ong three na.
4 site a CHH psagáam to find the sum of all thenaturel na.tom1
to
5. ite a c4 progtam to ompete the pouer a qiYea.
gixen
hambes to a qnveo poJeE.
6iwste a nction to fod the lenatk cf a Stieg in Ctt
Sofiwae and Hacolevace reguicemente ;-Any Teat edite
Lisur Tucbo Ctt Compiler installeaf onn
PC,

3*Theary i
C+f is Onethe mast popds Jaoguage io the
iproatamming twosld Ct+ is q poweshe qeneral pcpose
psonsamoag laaquage tett twas odeveloped in
heeasly 1980 as. an petension o the e
(
fo6
* pogsammiag lacqu age.
oiale
Ttis coiclly us
devloping Yaoge ef applicatons,
incuding Systet Software, game dlerlouprmert embe
ddecd
Mose
ostems, high -pertormance applications &
C+ Co mbinesboth high- level 3>low level
poogao, ming featuces, otfesig a balance be
petormance andabstoaction. t Supfocts psacedutal
cbjecd- orientecl, and generie fprogfamming pesachign;
giriog clevelopers fleri bility n designingad
mplermenting theis golutions.

Hincucle <isa Jastseam is heacles ffle libxasy


thet Iets us cwock coith input aodl output objects
Such Cout "2 " aoacin ' .

Dsing Oamespace stol meaos thet


hat o)e an
Dasnes Yos objects an Variables om the
Siandasd ibsasy
is called e fnctian. Any
tocle insile its cuhy brackets oill be
eaebcitecl.
Evesy C+4 stotement end with senicoloo
6
ende the maio nctiang
Rasic Data ypes
The doda Specifies the size anal type of
oocmtion he Variable coill sBosei

Dato
Type oze Desciption
boolean 1byte Stores true or folee vehues

char 1byte Stoses a single chaactee !


letteslnuSDbes, or AsCIT
\aues
int 2 or4 bytes Stoses chole numbers, withaut
Decimas.
Stoses actiong numbers,
Conteiong ome or mose
decion als. sufficient for Slaring
6-7 cleimal eligts
cocble 8 hyes Stoses fsaciongl numbess,
Containing OxP ormose olecimas.
Sufficient oc storing 5 decmal
digits.

*Statennent- Tf-Else niav


jf Conolition)
Il block of oole to be earecuted i4 the ondticnis
tsue.
?
eke
Iblock of code to be ex ectel f he
ondition is fage.
-

When oukno mcr times you cuat


totheloop Por thsoug blocko!
iNsteca
insieco tehile loopi
Srotaes
fox statementJ; Gtatement 2;Stetement 3)
WCodeblack to be erecute

Stateroent Lis exeeuted(one time) before the


erecution of he code block
Staternent 2 defnes the Condlition for rfautig
the Code bloak.
Stede mert2 deineg s eateouted (evesy tioe) aftes the
Code block haeheen cebetea.
-

Alssays ase used to Stose m)lipk Ve lues


single
CA Yariable insteac eleclasing
8epasade /ariales fos eOLch Value
T0 Declae an sTAy oetine the venahle
Type spepik he nanea the
the
Orlloed Dumbere bsackets
the ofelemends shouel
8tose
myNum]
\nsite progrom tos Aelelition of t a
umber in Ctt

To Aclo teo numhess
tembess in e++ cale ceil
No ntumbers e c n b hom the Be user
then pestccm ccle operation to clel e
and toge thes to print the CL cloiion
numbef

+ include is stceasn>
aSing Danespase stl
main )

int bi
ein ah
seturn

Intpt:-25
mcao1@mcao1-ThinkCentre-no-50t-Gen-3:fDesktop/Omkar.FYMCA/OPP

00:16
Oct1-

addttlon.C++
additlon.c+t1

mca01Qmca01-Thtnkcentrerneo-50t-Gen-3Desktop/Omkar
MCA/OPPSla.out
FY.
gedit
g++
7mca01@mca01-ThinkCentre-neo-50t-Gen-3:/DesktopLomkar.FY
MCA/oPP$MCA/OPP^
MCA/OPP$

/Omkar.Fö
mca01@mca01-Thinkcentre-neo-50t-Gen-3:/Desktop/Onkar.FY

mca01@nca01-ThinkCentre-neo-50t-Gen-3:-/Desktop

Terminal

5
Activitles 2
Ctt prosam to check ca number is even
5 To check i a ivern numter is even or oclal in
C++cue Simple
simpl oliiode the given number by 2,
the femainder is 0 thenis even othecauise
odl.

tiocueleliosBsea
using AamespaLe Std;
int mainf
Cin )ai
11a1.23o)f
then oVen Dub her
Cout 2<"even ";
Lelse

op
-Cver
mca01omca01-Thinkcentre-neo-50t-Gen-3:-/Desktop/omkar.FY.MCA/OPP

n
.
O0:21

1
Oct

evenoddc++
evenodd.c++

la.out
gedit
9+t evenmca01@mca01-Thtnkcentre-neo-50t-Gen-3:-/Desktop/Omka
MCA/OPPS
ThinkCentre-neo-50t-Gen-3:Desktop/0nkar.FY,
MCALOPPS
mca01@mcao1-
MCAJOPP$
MCAZORPS

FY FY
mca1@mcao1-ThtnkCentre-neo-50t-Gen-3:/Desktop/0mkar
Thinkcentre-neo-50t-Gen-3:Desktop/0nkar

Terminal
mca01amca01-

Activities 8
(19

Q.3 ite a Ctd poq tum to find the lorgest


Dumber among thsee numbess (A
CA Duber cill be
lourgesi nmbess
nmbesg is grealest hen both the
Dumber)

#incleleisstream)
USing namespaçe stodi

flaat
Cio >a >>>ci
19Ca>=b &laEc)
Cout << "Lasqes namber i

Cous Losgest rumbes:"Kb:


< "lacgest rumber i

Cout Largest Dumber:" Lci

Eoput 2 3

Largest Dkunber : 3
(5)
mcao1omca01-Thinkcentre-neo-50t-Gen-3:
/Desktop/omkar.FY.MCAJQPP

100:26,
Oct

l¡rgest.c++
MCAJ0PPS
mca01@mca01-ThlnkCentre-neo-50t-Gen-3:/Desktop/omkar.FY
g++largest.c++
MCA/OPFS

mca01amcao1-ThinkCentre-neo-50t-Gen-3:-/Desktop/Omkar.
MCAJOPPS/a.out
FY -3:-/Deaktop/0mkar.FY
gedit

MCAJOPP$

mca01@mca01-ThtnkCentre-neo-50t-Gen-3:Desktop/omkac:FY.

3mca01@mca01-Thlnkcentre-neo-50t-Gen

9Terminal Nunber:

Largest
123
Activities
lot Wite a
the natusal mbess fom 1 to o.
fio he suA tBe natusal umbess
Tocn to n C++, we have wo nethoda.
ohe is Ay
them
hy itereding sam l1to n ond adlalicq
Lp ohile thee oher way ` usn the
Summaoe ornete:
ioclucle ia stsear)
tesing nenespele stolg
int man()

int n,8umE0

for (ist isof;i<en itt)}"


Sum t=i

Topecta
dput: 15
mca01omca01-Thlnkcentre-neo-50t-Gen-3i-/Desktop/m7ar.FY.MCA/OPP

0
00:34

1
Oct

sumoflc++.
g++.
sumof.C++

/a.out
gedit
FY.MCA/OPPS
15mca01Gmca01-Thinkcentre-neo-sot-Gen-38-/Desktop/Omkar
mca01@nca01-Thtnkcentre-neo-5ot-Gen-3:*/Desktop/Onkar.FY:MCA/OPPS
MCAOPP$
FYMCA/OPP$

FY.
mca01@mca01-ThtnkCentre-neo-50t-Gen-3:/Desktop/Omkar:
mca010mca01-Thtnkcentre-neo-50t-Gen-3:/Desktop/omkar

Terminal

Activities 5
2r

05 Aite a Ct+ proqCam to ompate the powes


qiven DeAmbes to a qivenpower.
Compute the powes f a given Duber in.
Ct+,we iniialize Yesiahle sesut to J. Then,
ehile Jaap to utiply the
Testut by base Fos
for powgs numbes of timer.
ex. g^g = 3*3 *3 =22
hiocluale ioteam)
using std;
int main ()
iot powes;
floatbase, resalt = ;
Cin } beuse > powex ;
Whle Cpower !=o)f

Cout seslk

Tnput
mca01omça01-ThlnkCentre-neo-50t-Gen--Desktop/amkar.FYMCAJOPP.

100:50
oct

power.c++
st

poWer
/a.out
gedtt
gt+
27mca01@mca01-Thinkcentre-neo-50t-Gn-3:-/besktop
MCATOPPS
/omkar,FY,
MCAJOPPS
MCAJOPPS
MCA/OPP$

FY.FY FY
50t-Gon-3:/Desktop/omkar.
mca01@mcaot-Thtnkcentre-neo-50t-Gen-3:/Desktop/0nkar
/Onkar

3Desktop

Thinkcentre-neo-50t-Gen

mca01@mca01-Thlnkcentre-neo-

Terminal
mca01@mca01-

3
Activities 3
Q6 hhite a Ct+ paOEAO)
psonam to calaate the average of al
hen eleonents present io ao asraf.
We iterate oves euch eleoent of the akasf &
calcclote theSelm of al the elements. Thed cwe
Denide the Sum af the assay to qet the avesaqe
he avesage is slosec in a ariableof type flnat
and setushkd.
alesage
ttiheluclek iosteam)
usIngnamespoce sto

Ploat Sum= 0. 0;
for Cint is0:in;i+)

for Cint j=0iloiitt)


Sum t

Cout Kfloat) CBamlleat Jo)

|45
Octputq33333
/Désktop/omkar.FY.MCÁ/OPP
mca01mca01-Thinkcentre-neo-50t-Gen-3:

Octt
O1:03

avg.c++
ct+

avg
array
array
/a.out3.33333mca01amcao1-ThtnkCentre-neo-50t-Gen-3
JDesktop/OmkarFY
MCA/OPPS
gedit
g++
MCAJOPP$
OPP^
NCAJOPPS

MCA
mca01@mca01-ThinkCentre-neo-50t-Gen-3:/Desktop/Onkar,EY.
FY FY
mca01@mca01-ThtnkCentre-neo-50t-Gen-3:/Desktop/0nkar
mca01mcao1-Thlnkcentre-neo-50t-Gen-3-Desktop/onkar

Terminal

D
145
Activities 3
fuochon do find the legh oo Sting ?o.
To ind the Jengta tke tino
Coill tterote thotah tie sting ad
acdincrease
Count by 11 We reach the end of the stig
incluce <iostreamy
(isinq hemespace sto:

Stsing str;
ein Sstr;
int Count =0
for (int izO;gts[i];it+) the striog choecter
Cout ll Conti

Input; cbcode
5

ConcluSion
Wbile bui ldiog hagic Ct+ psoqcams
to teacn AR basicr of the Tengige
languge anc qain.
oofidaare n pcaqsamani ng. After peYfosming this
Hsign ment e Can pxacice fundamentcl oncepts
ike vonahles, data tipes, contsol tructuer anid
function as ceell aithmatic apesadions, inpetlodput
, londitisnale, Joops, and arrays. toosking thsaugh
these poogdaung lews
alows beqinnecs
beginnecg tQ apel ther knaa)lacge
mca01@mca01-ThlnkCentre-neo-50t-Gen-3:-/Desktop/OmkatFY.MCAJOPP

1.01:08
Oct

fun.C++
fun.c++

string
string
/a0ut
gedlt
g++
Smca01@mca01-ThtnkCentre-neo-50t-Gen-3:-/Desktop/omkar.EY.MCA
/0nkar.FYMCAJDPP$,
MCA/OPPS
FY.MCA/OPP$
3:Desktop/Orkar
mca01@mca01-Thtnkcentre-neo-50t-Gen-

FY
mca01@mcao1-Thtnkcentre-neo-50t-Gen-3:-/Desktop!omkar

mca01@mca01-Tblnkcentre-neo-50t-Gen-3:/Desktop

OTerminal:

abcde
Activitles

You might also like