OPP Assignment 1
OPP Assignment 1
Omker Kembhur
;- To xplose basic Concepts of oPP though 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.
Dato
Type oze Desciption
boolean 1byte Stores true or folee vehues
+ 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
#incleleisstream)
USing namespaçe stodi
flaat
Cio >a >>>ci
19Ca>=b &laEc)
Cout << "Lasqes namber i
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
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
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+)
|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