0 ratings0% found this document useful (0 votes) 23 views14 pagesC++ Practice File Solutions
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
. \
TUTORIAL/ PRACTI ‘AL
a 1. Write a Cr+ Program to Find the Sum ond produtt
>
3 g aM clement St on array . *
> a
oH incddude g
i Using Nomespace Std; °
: es
& int moml)§ *
o . 2
i mt arr[s]* § 10,20, 30,40,504) *
> int Sun= 0; %
° ink product =4; %
$ ink ns; 2
i dor link io sicnss Ha)g £
M4 Sue = Sumt arr lid; >
+ Product = product * ary [i]; =
es Fo. 3
* (out <<" Sum array ip 2 S
+ Uni ‘
: "y Nomepace Std 5
: Struck Student
> int radd-no;
» Chor name [so];
a int ed)
”
> Float morkg}
> 4
> a
* ME rmain()§ «
* &
: Student 8; ye
° Goud << “ Enter Anporrasion” eee 3
: (oud << “Enter valld_no ="; S
o Cin >7 §- volo; %
a Cour << “Enter name :"Ke ond; S
* Cin >> Sname; v
& Cow > Sage ; “ge er °
e . 2
S Cou oul << Pome" *
° Pointer - *
z F# indude 4
> Uting Nomespute Std5 os
< * &
° int main() ¢ *
> mk abies %
2 int * p47 72,* Ps; re
> w . &
* Couk << “Enter three numbers ccondhs oS
+ Cin >2 a >> b>>c5 2
° P1- ga; P= Bos 03-Bc; Coa
ss if ("ei >=" 02 Bp *Pir=*Pa)§ =
oo Cou << * Qreadert ip Pir"
o ols %
+ iE" 0ap=*0L BP *P2>="P3)4 S
e “ 4
* Cout <<“ gveatet tp 02! << =*p1 83 *Pa>=*pall °
= Cout °
° Lring namerpate Std 5 ©
oY i
Fink Fyb Cink x) 4 i
> -
3 WE(w ==4) Nhxe=o))f *
> Yelurn x 5 :
> %
° ebae { 4
: Yeturn ( Fil 4) + Sib lx-2))5 o
* *
eo 5 °
& ink maint )4 s
a int xis 0; =
Cout <<" Erker the number of tev: Ta
ry Seria t's 2
Cin 2x 5 8 8 ea
o Couk <¢" Fibanaci Seria.” « cy
% hile (i ex) :
2 Cou ce * "ce PibLi); +
3 4h; *
Oo
* o
” Yeturn 0; y-
: 2
° °
+ ©
* *
+
Ce Ne
+
oeDa
SF
ae
TUTORIAL/PRACTICALNO
Sete
wee epee
° 5. Usrite a Crt Prograre ko demonstrate member
4 derttivn decoration inside and Qudside she .
o Claws %
P &
H# include < loptream> 3
Uning Namerpace Std)
HE maind
Cham fest §
Pulilic:
Void Funnpide ()$
Couk X<" Declared artide Cons”
es j >
* int maint )4
& fok 4;
o
” 4. Fumimice (5
+ 4. Fun Oudsiaee );
* Yeurn 0;
° 3
3 2
° i
Xs *
s *
oe he oe ale ease ae aap ee aap be op eee eke oe ade ele oe ake ade oe alo ode ae alp ole ote ale of
BAR AL TIATIINNCITV ALTOCUIANI ACW Avna
JTORIA PRACTICAL NO.
i
Senos
qurction ont Cried cham -
tinchade ¢ lo skream >
Ofing Nramerface stay
T
°
o
>
>
>
-
-
F Chow chant;
> Wom chaung
° Public:
s Cham AL): ru Atiadey § 5
° DV ivadse:
: Mt rum;
a Friend int dd L ctorst), Com 8);
> §;
ae
se Lom Clanbt
* Pubic +
* Com BC) “nm B41) $4
* Private:
2 ink mum;
+ Friend im add Cetom A, cdam 8);
a
=
> Wb add (chawP.oblet A, Wom B obletB)$
° Yeturn
ey ( ebict Brum + coheed Brat)
IMk matin (94
y
LLL EEEPE OEE STEED ESET
+
M.M.M, UNIVERSITY OF TECHNOLOGY, GKP.
Ae Ae ae ae oe oe ae ae eae ae a ae eae ete te
6 Udrie oo cM Program to demowkrate Criednd
pe Yom object A;
= UomB obiec g;
ub ce" wot” coady Les vee).
2 dwn 9, “odd (otic A obit 8);
:
°
o
>
PPPS S SSS Ss
Sess ss
SPSS Sees
eet
ooSooeee
oa
Pate ate
Poe S eee eeenees
PHOS Oooo oo eas
Leepdee s Shae deo dete ce ate tes
Write a C44 Program to Add — Combructor and
destructor Jor IniWlatizing and destroying obleds
Hindude cioxtvean>
Using Nomeyace gtd}
dom Merk §
Private:
int n}
Pubic :
rege “eat Link Va): n{vasue) {
Cour +
+ Using Naser pace pas ee
ZF Bom Comper °
oS Private > 8
> doubide veal ; °
° double imaginary} +
: Pubtic: °
> Complex (doubte ¥< 0, double iz o)t S
= Yeal=y; *
imaginary?) 3 2
> 5 ue o
¢ Compfex operator +4 (If +
w At veal) %
> ++ imogi 2 ©
leginor ys
Yellin *thip; 2
Complex Operator --()£
-- Veal)
~- imaginary}
Yerum * tig;
ed
“
Void diagay (Ot
(out Complex numbers. Oring binary Operator Overloading
SF tinckide clostream> ys
2 Oring Momeypace Std) 2
SF Gow Commters ye
. double reads *
+ double imaginary) ra
> Public be
: Complex (double veo, doube iro) %
> Veal: 05 °
: imaginary 215 *
+ 3 am
> Complex operator + (complex Cont fobi )f
: Complex vers *
* YO-Teal = veal 4 Obd-veal 5 *
‘ Yo Wreaginacy Fimaginay y + Obs imaginary 5 z
> veruyn ces} 2
* 4
+ Compsex operator - (tomples (omt ZObi )f °
: Lomplex vers >
’ Ves-Yeall= veat— oblveal *
* Yo-imaginory + irmaginoy ~Obsimaginary
* Yeturn vay Ps
+ 3 ie
* Void display Oy Ps
+ Co 4p . t
rs ‘ is << Read: be
F — Uring namerpace 282) *
° % 9 jamenpi x
Show ovent & e
> Public: 3
ee Void Print Vg e
a
° Cour
oe » *
* ink main) § :
bs Child Child derived } :
iM Chidd. derived . Pyint 4()5 =
* Tdum ©; te
a ;
© ’
j ©
‘ s
° ~
& **TUTORIAL/ PRACTICALN N
SSoSs SPSS
COCO e eee eeeneens
oe
St
%
+
+
jo: Lorike O CAF Programs ko Mow hevikance Uring
Gievent Sevda
YH indude < ostream
Uping nramergace Sta}
om Arimat {
Ouhtte:
; Gout 8
¢
dttincddude cexceptions
Uring Nomespace peas
Void Food) ¢
Crow” An exception Occurred "5
5
Cok (.-.)4
Couk ce" An exception wor Caught "<< onal
4
y
+
?
+
>
¢
?
:
?
+
2
+
+
¢
¢
¢
?
+
+
<
?
+
+
<
+
¢
+
+
< - \
ie Mk mein()¢
2 Fool ();
ca
o
?
o
¢
o
o
°
+
°
oa
o
¢
°
+
ou
¢
oy
¢
¢
+
*
°
7
Yeburn 0;)
TUTORIAL / PRACTICAL NO.
LPP SSO SESE SEES OE SESE EEEEE SES ESE SESE SESES
e 12 .
gf Write ag C44 Program to write Croracker Anto
@ Fle ond bo read Characters dren 0 She
+
oa
te
3
2
$
a
+
°°
Frindude $
Hlndtude < Patream> :
Uying Momerpace kd} 3
ink wan) ¢
Oak ream Ourpurlide | “example. bet"), ¢
Bupa tde< iS
HE (oudpust ite. in opent a}f 3
Ouspudlle eo” Lette world 1"
+
>
-
e
>
+
+
+
-
+
¢
-
-
:
°
:
>
°
¢
>
>
¢
+
+
:
>:
=
:
?
:
-
¢
¢
¢
oS
°
¢
?
<
°
2
7
?
?
¢
¢
+
2
¢
°
2
¢
S?
Se
°
?
?
¢
°