Assignment 0003
Assignment 0003
Rol
lNO=18
Assi
gnment#03
Submit
tedt
oSi
rWaseem
Ull
ah
Task01
#i
ncl
ude<i
ost
ream>
usi
ngnamespacest
d;
st
ructDi
st{
i
ntf
eet
;
f
loati
nch;
};
i
ntmai
n()
{
Di
std1,
d2,
resul
t;
cout
<<"
Ent
erf
ir
stdi
stancei
nfeet
:"
;
ci
n>>d1.
feet
;
cout
<<"
Ent
erf
ir
stdi
stancei
ninch:
";
ci
n>>d1.
inch;
cout
<<"
Ent
erseconddi
stancei
nfeet
:"
;
ci
n>>d2.
feet
;
cout
<<"
Ent
erseconddi
stancei
nch:
";
ci
n>>d2.
inch;
r
esul
t.
feet=d1.
feet+d2.
feet
;
r
esul
t.
inch=d1.
inch+d2.
inch;
whi
le(
resul
t.
inch>=12.
0){
r
esul
t.
inch=r
esul
t.
inch-12.
0;
++r
esul
t.
feet
;
}
cout<<"Sum ofdist
ances="
<<r
esul
t.
feet
<<"f
eet
"
<<result
.inch<<"i
nch"
<<endl
;
r
etur
n0;
}
Task2
#i
ncl
ude<i
ost
ream>
usi
ngnamespacest
d;
st
ructcompl
ex{
doubl
ereal
;
doubl
eimag;
}
;
compl
exaddcomp(
compl
exx,
compl
exy
){
compl
exr
esul
t;
r
esul
t.
real
=x.
real
+y.
real
;
r
esul
t.
imag=x.
imag+y
.imag;
r
etur
nresul
t;
}
compl
exsubt
ract
comp(
compl
exx,
compl
exy
){
compl
exr
esul
t;
r
esul
t.
real
=x.
real
-y.
real
;
r
esul
t.
imag=x.
imag-
y.i
mag;
r
etur
nresul
t;
}
i
ntmai
n()
{
compl
exc1,
c2,
sum,
dif
fer
ence;
cout
<<"
ent
err
ealpar
tof1stcompl
exnumber
:"
;
ci
n>>c1.
real
;
cout
<<"
ent
eri
magi
nar
ypar
tof1stcompl
exnumber
:"
;
ci
n>>c1.
imag;
cout
<<"
ent
err
ealpar
tof2ndcompl
exnumber
:"
;
ci
n>>c2.
real
;
cout
<<"
ent
eri
magi
nar
ypar
tof2ndcompl
exnumber
:"
;
ci
n>>c2.
imag;
sum=addcomp(
c1,
c2)
;
di
ff
erence=subt
ract
comp(
c1,
c2)
;
cout
<<"
sum:
"<<sum.
real
<<"
+"<<sum.
imag<<"
i"
<<endl
;
cout<<"
dif
fer
ence:
"<<di
ff
erence.
real
<<"
+"<<di
ff
erence.
imag<<"
i"
<
<endl;
r
etur
n0;
}
Task03
#i
ncl
ude<i
ost
ream>
#i
ncl
ude<st
ri
ng>
usi
ngnamespacest
d;
st
ructEmpl
oyee{
i
ntempCode;
st
ri
ngname;
st
ri
ngdat
eOf
Joi
ning;
}
;
i
ntcalcul
ateTenur
eInYear
s(st
ri
ngcur
rent
Dat
e,st
ri
ng
j
oini
ngDate){
i
ntcur
rent
Year=st
oi(
cur
rent
Dat
e.subst
r(6,
4))
;
i
ntj
oini
ngYear=st
oi(
joi
ningDat
e.subst
r(6,
4))
;
r
etur
ncur
rent
Year-j
oini
ngYear
;
}
i
ntmai
n(){
consti
ntMAX_
EMPLOYEES=5;
Empl
oyeeempl
oyees[
MAX_
EMPLOYEES]
;
f
or(
inti
=0;
i<MAX_
EMPLOYEES;
++i
){
cout<<"
Ent
erEmpl
oyee"<<i
+1<<"Det
ail
s:"<<
endl
;
cout<<"
Empl
oyeeCode:
";
ci
n>>empl
oyees[
i]
.empCode;
cout<<"
Name:
";
ci
n.i
gnor
e()
;
get
li
ne(
cin,
empl
oyees[
i]
.name)
;
cout<<"
Dat
eofJoi
ning(
YYYY-
MM-
DD)
:";
ci
n>>empl
oyees[
i]
.dat
eOf
Joi
ning;
}
st
ri
ngcur
rent
Dat
e;
cout<<"
Ent
erCur
rentDat
e(YYYY-
MM-
DD)
:";
ci
n>>cur
rent
Dat
e;
cout<<"\nEmploy
eeswi
tht
enur
e3ormor
ethan
3year
s:"<<endl
;
cout<<"
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
-"<<endl
;
f
or(
inti
=0;
i<MAX_
EMPLOYEES;
++i
){
i
nttenure=cal
culateTenur
eInYear
s(cur
rent
Dat
e,
empl
oyees[i
].
dat
eOfJoining)
;
i
f(t
enur
e>=3){
cout<<empl
oyees[
i]
.name<<endl
;
}
}
r
etur
n0;
}
Task04
#i
ncl
ude<i
ost
ream>
usi
ngnamespacest
d;
l
ongf
act
ori
al(
int*
num)
{
i
ntf
act
=1;
f
or(
inti
=1;
i
<=*
num;
i
++)
{
f
act
*=i
;
}
r
etur
nfact
;
}
i
ntmai
n()
{
i
nta;
cout
<<"
ent
eranumber
:"
;
ci
n>>a;
i
nt*
ptr
=&a;
i
ntr
esul
t=f
act
ori
al(
ptr
);
cout
<<"
fact
ori
alof"
<<a<<"i
s:"
<<r
esul
t<<endl
;
r
etur
n0;
}
Task05
#i
ncl
ude<i
ost
ream>
usi
ngnamespacest
d;
i
ntmai
n()
{
i
ntar
r[
5]={
4,7,
8,
5,
4};
i
ntsi
ze=si
zeof
(ar
r)/
sizeof
(ar
r[
5])
;
i
nt*
ptr
=ar
r;
i
ntsum=0;
f
or(
inti
=0;
i
<si
ze;
i
++)
{
sum+=*
ptr
;
pt
r++;
}
cout
<<"
sum ofar
rayel
ement
s:"
<<sum<<endl
;
r
etur
n0;
}
Task06
#i
ncl
ude<i
ost
ream>
usi
ngnamespacest
d;
i
ntmai
n()
{
i
ntwaqar
1[2]
[2]
={{
5,8}
,{
5,2}
};
i
ntwaqar
2[2]
[2]
={{
3,9}
,{
7,1}
};
i
ntsum[
2][
2];
f
or(
inti
=0;
i
<2;
i
++)
{
f
or(
intj
=0;
j
<2;
j
++)
{
sum[
i]
[j
]=waqar
1[i
][
j]
+waqar
2[i
][
j]
;
}
}
cout
<<"
sum ofmat
ri
ces:
"<<endl
;
f
or(
inti
=0;
i
<2;
i
++)
{
f
or(
intj
=0;
j
<2;
j
++)
{
cout
<<sum[
i]
[j
]<<""
;
}
cout
<<endl
;
}
r
etur
n0;
}
Task07
#i
ncl
ude<i
ost
ream>
usi
ngnamespacest
d;
i
ntmai
n()
{
i
ntr
ow1,
col
1,r
ow2,
col
2;
i
ntm1[
10]
[10]
,m2[
10]
[10]
,pr
o[10]
[10]
;
cout<<"
Ent
erthenumberofRowsandCol
umnsof
f
ir
stmatri
x:"
<<endl
;
ci
n>>r
ow1>>col
1;
cout<<"
Ent
erthenumberofRowsandCol
umns
ofsecondmat
rix:"
<<endl
;
ci
n>>r
ow2>>col
2;
i
f(col
1==r
ow2){
cout<<"
\nEnt
ert
he"<<row1*col
1<<"
el
ementsoff
ir
stmatr
ix:
\n"
;
f
or(
inti
=0;
i<r
ow1;
i++){
f
or(
intj
=0;
j<col
1;j
++){
ci
n>>m1[
i]
[j
];
}
}
cout<<"\
nEntert
he"<<row2*col
2<<"
el
ementsofsecondmatr
ix:\
n";
f
or(
inti
=0;
i<r
ow2;
i++){
f
or(
intj
=0;
j<col
2;j
++){
ci
n>>m2[
i]
[j
];
}
}
f
or(
inti
=0;
i<r
ow1;
i++){
f
or(
intj
=0;
j<col
2;j
++){
pr
o[i
][
j]=0;
f
or(
intk=0;
k<col
1;k++)
pr
o[i
][
j]=pr
o[i
][
j]+(
m1[
i2[
k][
j]
);
}
}
cout<<"
thef
ir
stmat
ri
xis:
"<<endl
;
f
or(
inti
=0;
i<r
ow1;
i++){
f
or(
intj
=0;
j<col
1;j
++){
cout<<m1[
i]
[j
]<<""
;
}
cout<<endl
;
}
cout<<"
Thesecondmat
ri
xis:
"<<endl
;
f
or(
inti
=0;
i<r
ow2;
i++){
f
or(
intj
=0;
j<col
2;j
++){
cout<<m2[
i]
[j
]<<""
;
}
cout<<endl
;
}
cout<<"
Ther
esul
tantmat
ri
xis:
\n"
;
f
or(
inti
=0;
i<r
ow1;
i++){
f
or(
intj
=0;
j<col
2;j
++){
cout<<pr
o[i
][
j]<<""
;
}
cout<<endl
;
}
}el
se{
cout<<"\n\
nMatr
ixmul
ti
pli
cat
ioncan'
tbedone
ast
heindicesdonotmat
ch!
";
}
cout<<endl
;
r
etur
n0;
}
Task08
#i
ncl
ude<i
ost
ream>
usi
ngnamespacest
d;
doubl
ecel
siusToFahr
enhei
t(
doubl
ecel
sius){
r
etur
n(cel
sius*9/5)+32;
}
i
ntmai
n(){
consti
ntDAYS_
IN_
WEEK=7;
doubl
ecel
siusTemper
atur
es[
DAYS_
IN_
WEEK]
;
doubl
efahr
enhei
tTemper
atur
es[
DAYS_
IN_
WEEK]
;
cout<<"
Entertemperat
uresi
nCel
siusf
oreach
dayoftheweek:"<<endl;
f
or(
inti
=0;
i<DAYS_
IN_
WEEK;
++i
){
cout<<"
Temper
atur
eforday"<<i
+1<<"
:";
ci
n>>cel
siusTemper
atur
es[
i]
;
}
f
or(
inti
=0;
i<DAYS_
IN_
WEEK;
++i
){
f ahr
enhei
tTemper
atures[
i]=
cel
siusToFahr
enhei
t(
celsi
usTemper
atur
es[
i]
);
}
cout<<"\nTemper
atur
esf
oreachdayoft
he
week:
"<<endl;
cout<<"
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
-"<<endl
;
cout<<"
Day
\tCel
si
us\
tFahr
enhei
t"<<endl
;
f
or(
inti
=0;
i<DAYS_
IN_
WEEK;
++i
){
cout<<i+1<<" \
t"<<celsi
usTemperat
ures[
i]<<
"
\t"<<fahrenhei
tTemperat
ures[
i]<<endl
;
}
r
etur
n0;
}
Task09
#i
ncl
ude<i
ost
ream>
#i
ncl
ude<mat
h.h>
usi
ngnamespacest
d;
st
ructst
udent
{
st
ri
ngname;
i
ntr
oll
no;
i
ntage;
i
ntmar
ks;
}
;
i
ntmai
n()
{
st
udentst
d1;
cout
<<"
Ent
ernameofst
udent
:"
;
ci
n>>st
d1.
name;
cout
<<"
Ent
erst
udentr
oll
no:
";
ci
n>>st
d1.
rol
l
no;
cout
<<"
Ent
erageofst
udent
:"
;
ci
n>>st
d1.
age;
cout
<<"
name:
"<<st
d1.
name<<endl
;
cout
<<"
name:
"<<st
d1.
rol
l
no<<endl
;
cout
<<"
name:
"<<st
d1.
age<<endl
;
r
etur
n0;
}