I
NSTI
TUTI
ONAL.
.
SUMMER
TRAI
NI
NG.
.
.
2020.
.
NAME:
-VI
KRANT
BRANCH :
-I
NFORMATI
ONTECHNOLOGY
UNI
VERSI
TYROLLNO:
-
DATE:
-5JUNE2020
Pr
ogr
am 1:Wr
i
t
eac++Pr
ogr
am t
of
i
ndt
hemeanv
al
ueoft
wonumber
s
y
si
ngf
r
i
endf
unct
i
on.
Sour
ceci
de:
#i
ncl
ude
usi
ngnamespacest
d;
#i
ncl
ude
cl
assbase
{
i
ntv
al
1,
v
al
2;
publ
i
c:
v
oi
dget
dat
a(
)
{
cout
<>v
al
1;
cout
<>v
al
2;
}
f
r
i
endf
l
oatmean(
baseobj
)
;
}
;
f
l
oatmean(
baseobj
)
{
r
et
ur
nf
l
oat
(
obj
.
v
al
1+obj
.
v
al
2)
/
2;
}
i
ntmai
n(
)
{
baseobj
;
obj
.
get
dat
a(
)
;
cout
<
usi
ngnamespacest
d;
cl
assconst
r
uct
{
publ
i
c:
f
l
oatar
ea;
/
/Const
r
uct
orwi
t
hnopar
amet
er
s
const
r
uct
(
)
{
ar
ea=0;
}
/
/Const
r
uct
orwi
t
ht
wopar
amet
er
s
const
r
uct
(
i
nta,
i
ntb)
{
ar
ea=a*b;
}
v
oi
ddi
sp(
)
{
cout
<
#i
ncl
ude
usi
ngnamespacest
d;
cl
asscl
ass_
b;
cl
asscl
ass_
a
{
i
nta;
publ
i
c:
v
oi
di
ndat
a(
i
ntx)
{
a=x;
}
v
oi
ddi
spl
ay
(
)
{
cout
<>x>>y
;
cl
ass_
aobj
_
a;
/
/
obj
ectofcl
ass_
a
cl
ass_
bobj
_
b;
/
/
obj
ectofcl
ass_
b
obj
_
a.
i
ndat
a(
x)
;
/
/
Cal
l
l
i
ngi
ndat
a(
)ofcl
ass_
a
obj
_
b.
i
ndat
a(
y
)
;
/
swap(
obj
_
a,
obj
_
b)
;
obj
_
a.
di
spl
ay
(
)
;
/
/
Cal
l
l
i
ngdi
spl
ay
(
)ofcl
ass_
a
obj
_
b.
di
spl
ay
(
)
;
r
et
ur
n0;
}
OUTPUT:
PROGRAM 4:Wr
i
t
eaPr
ogr
am t
odesi
gnacl
asscompl
ext
o
r
epr
esentcompl
exnumber
s.Thecompl
excl
assshoul
dusean
out
si
def
unct
i
ont
oaddt
wocompl
exnumber
.Thef
unct
i
onshoul
d
r
et
ur
nanobj
ectt
ot
y
pecoompl
exr
epr
esent
i
ngt
hesum oft
wo
compl
exnumber
s.
Sour
cecode:
#i
ncl
ude
usi
ngnamespacest
d;
cl
asscompl
ex
{
publ
i
c:
i
ntr
eal
,
i
mg;
}
;
i
ntmai
n(
)
{
compl
exa,
b,
c;
cout<>a.
r
eal
;
cout<>a.
i
mg;
cout<>b.
r
eal
;
cout<>b.
i
mg;
c.
r
eal
=a.
r
eal
+b.
r
eal
;
c.
i
mg=a.
i
mg+b.
i
mg;
i
f(
c.
i
mg>=0)
cout<
usi
ngnamespacest
d;
cl
assSampl
ecopy
const
r
uct
or
{
pr
i
v
at
e:
i
ntx,
y
;/
/
dat
amember
s
publ
i
c:
Sampl
ecopy
const
r
uct
or
(
i
ntx1,
i
nty
1)
{
x=x1;
y=y
1;
}
/
*Copyconst
r
uct
or*
/
Sampl
ecopy
const
r
uct
or(
constSampl
ecopy
const
r
uct
or&sam)
{
x=sam.
x;
y=sam.
y
;
}
v
oi
ddi
spl
ay
(
)
{
cout
<
usi
ngnamespacest
d;
cl
assFl
oat
{
f
l
oati
;
publ
i
c:
Fl
oat
(
)
:
i
(
5){
}
Fl
oat
(
f
l
oatx)
:
i
(
x){
}
Fl
oatoper
at
or+(
Fl
oata)
{
Fl
oatt
emp;
t
emp.
i
=i
+a.
i
;
r
et
ur
nt
emp;
}
Fl
oatoper
at
or-(
Fl
oata)
{
Fl
oatt
emp;
t
emp.
i
=i
-a.
i
;
r
et
ur
nt
emp;
}
Fl
oatoper
at
or/(
f
l
oata)
{
Fl
oatt
emp;
t
emp.
i
=i
/a;
r
et
ur
nt
emp;
}
f
r
i
endFl
oatoper
at
or
*(
f
l
oata,
Fl
oatb)
{
Fl
oatt
emp;
t
emp.
i
=a*b.
i
;
r
et
ur
nt
emp;
}
v
oi
dshow(
)
{
cout
<
usi
ngnamespacest
d;
i
ntmai
n(
)
{
i
ntx=10;
/
/i
nt
egerx
chary='
a'
;
/
/char
act
erc
/
/yi
mpl
i
ci
t
l
yconv
er
t
edt
oi
nt
.ASCI
I
/
/v
al
ueof'
a'
i
s97
x=x+y
;
/
/xi
si
mpl
i
ci
t
l
yconv
er
t
edt
of
l
oat
f
l
oatz=x+1.
0;
cout<
#i
ncl
ude
#i
ncl
ude
usi
ngnamespacest
d;
i
ntmai
n(
)
{
i
f
st
r
eam wor
mf
i
l
e(
"
ol
d.
t
xt
"
)
;
of
st
r
eam dt
f
i
l
e(
"
new.
t
x
t
"
)
;
st
r
i
ngwor
ml
i
ne;
{
get
l
i
ne(
wor
mf
i
l
e,
wor
ml
i
ne)
;
}
dt
f
i
l
e<
usi
ngnamespacest
d;
st
r
uctempl
oy
ee{
i
ntempI
D;
charname[
50]
;
charaddr
ess[
50]
;
}
;
i
ntmai
n(
){
st
r
uctempl
oy
eeemp[
3]={{1,
"
Vi
kr
ant
","
v
i
l
l
ageChouhan"},
{2,
"
Sachi
n","
v
i
l
l
ageBal
sua"},
{3,
"
Ni
t
i
sh","
v
i
l
l
ageGhar
ot
a"}}
;
cout
<
#i
ncl
ude
usi
ngnamespacest
d;
i
ntmai
n(
)
{
charst
r
[
50]
;
i
ntl
en;
cout<
usi
ngnamespacest
d;
i
ntmai
n(
)
{
i
ntar
r
[
10]
,
i
,
num,
n,
cnt
=0,
pos;
cout
<>n;
cout
<>ar
r
[
i
]
;
}
cout
<>num;
f
or
(
i
=0;
i
usi
ngnamespacest
d;
#def
i
neMAX100
i
ntmai
n(
)
{
/
/
ar
r
aydecl
ar
at
i
on
i
ntar
r
[
MAX]
;
i
ntn,
i
,
j
;
i
ntt
emp;
/
/
r
eadt
ot
al
numberofel
ement
st
or
ead
cout
<>n;
/
/
checkbound
i
f
(
n<0|
|
n>MAX)
{
cout
<>ar
r
[
i
]
;
}
/
/
pr
i
nti
nputel
ement
s
cout
<ar
r
[
j
]
)
{
t
emp=ar
r
[
i
]
;
ar
r
[
i
]
=ar
r
[
j
]
;
ar
r
[
j
]
=t
emp;
}
}
}
/
/
pr
i
ntsor
t
edar
r
ayel
ement
s
cout
<
usi
ngnamespacest
d;
i
ntmai
n(
)
{
i
ntcount
,
i
,
ar
r
[
30]
,
num,
f
i
r
st
,
l
ast
,
mi
ddl
e;
cout
<>count
;
f
or(
i
=0;
i
>ar
r
[
i
]
;
}
cout
<>num;
f
i
r
st=0;
l
ast=count
1;
mi
ddl
e=(
f
i
r
st
+l
ast
)
/
2;
whi
l
e(
f
i
r
st<=l
ast
)
{
i
f
(
ar
r
[
mi
ddl
e]l
ast
)
{
cout
<
#i
ncl
ude
usi
ngnamespacest
d;
i
ntmai
n(
)
{
f
l
oatl
,
b,
h,
ar
ea,
v
ol
ume;
cout
<>l
;
cout
<>b;
cout
<>h;
ar
ea=(
2*
(
(
l
*
b)
+(
b*
h)
+(
l
*
h)
)
)
;
v
ol
ume=(
l
*
b*
h)
;
cout
<
usi
ngnamespacest
d;
cl
assCPol
y
gon{
pr
ot
ect
ed:
i
ntwi
dt
h,
hei
ght
;
publ
i
c:
v
oi
dset
_
v
al
ues(
i
nta,
i
ntb)
{wi
dt
h=a;
hei
ght
=b;
}
}
;
cl
assCRect
angl
e:
publ
i
cCPol
y
gon{
publ
i
c:
i
ntar
ea(
)
{r
et
ur
n(
wi
dt
h*hei
ght
)
;
}
}
;
cl
assCTr
i
angl
e:
publ
i
cCPol
y
gon{
publ
i
c:
i
ntar
ea(
)
{r
et
ur
n(
wi
dt
h*hei
ght/5)
;
}
}
;
i
ntmai
n(
){
CRect
angl
er
ect
;
CTr
i
angl
et
r
gl
;
CPol
y
gon*ppol
y
1=&r
ect
;
CPol
y
gon*ppol
y
2=&t
r
gl
;
ppol
y
1>set
_
v
al
ues(
40,
5)
;
ppol
y
2>set
_
v
al
ues(
40,
5)
;
cout<
usi
ngnamespacest
d;
cl
assbase /
/
si
ngl
ebasecl
ass
{
publ
i
c:
i
ntx;
v
oi
dget
dat
a(
)
{
cout<>x;
}
}
;
cl
assder
i
v
e:
publ
i
cbase /
/
si
ngl
eder
i
v
edcl
ass
{
pr
i
v
at
e:
i
nty
;
publ
i
c:
v
oi
dr
eaddat
a(
)
{
cout<>y
;
}
v
oi
dpr
oduct
(
)
{
cout<
usi
ngnamespacest
d;
cl
assAbst
r
act
{
i
nti
,
j
;
publ
i
c:
v
i
r
t
ual
v
oi
dset
Dat
a(
i
nti
=0,
i
ntj
=0)=0;
v
i
r
t
ual
v
oi
dpr
i
nt
Dat
a(
)=0;
}
;
cl
assDer
i
v
ed:
publ
i
cAbst
r
act{
i
nti
,
j
;
publ
i
c:
Der
i
v
ed(
i
nti
i
=0,
i
ntj
j
=0):
i
(
i
i
)
,
j
(
j
j
)
{
cout<