You are on page 1of 241

I

F 2005

, F
I , ,
, .

A
M, ,
I , .

A CK
M, , .
FF E , FK , .
M, ,
I ,
.

e
M, , .
FF F Aw, H LI, .

F
FF M, , T R H LI,
.

CK
CL , P, Hv, .

M :

K: I
O M , I

70 T.v.. O C.

ii

QQ M b
HC Q EPJ MJP b
G . EP
M. M A.
- C
EP, C PM, E, G HC
bF A F .
N, E O Q M
. Q, Q ,
F GM .
CF PM.
A E J, QK O
A. , A O M
, G A G , I
E GA. K,
H F. , EP
P A.
, ,
EP O J
. EP
N G A.
, KP N G
N PA.
G N
. C PM , C E
. C,
N . G N, G, b G
O K
.
C-N . ,
N. , b
A . C-N F N.
F C-NJ C++ N P
MA. C++, G (Object Oriented Programming
iii
-OOP) P F . ,
N G N
A. C++ N ,
N (OOP) N AM.
C++ NO (Object) P
A A A.
, GO , ,
.
QA , HC Q
O F A. A
G A HC
b A. C++ NJ,
G C, A
K AP J A.
O, M G
FJ . C++
G A I MM L
F F I.
N
F MA. K M
M (Q
). O N
P P M.
CK, e, O M
O IC E
P
KM .

.I

F e

iv

1 C++ NJN
G 1
(Object Oriented Concepts using C++)
1.1 G N 1
(Object Oriented Programming Language)
1.2 (Polymorphism) 4
1.3 K (Inheritance) 5
1.4 : i c 6
JC M 9

2 C++ NJ 10
(Overview of C++)
2.1 10
2.2 C++ P F (C++ Character Set) 10
2.3 (Data Types) 30
2.4 P (Variables) 41
JC M 51

3 54
(Basic Statements)
3.1 k / Of 54
3.2 C++ G - C++ GL 56
3.3 (Declaration Statements) 57
3.4 FH (Assignment Statements) 58
3.5 (Control Structures) 59
3.6 G 88
JC M 89

4
(Functions) 94
4.1 94
4.2 P (Function Prototype) 96
4.3 P 98
4.4 P H 99
4.5 FH FH 109
v
4.6 inline 112
4.7 PO (scope) MF 114
JC M 118

5 M - E 124
(Structured Data Type - Arrays)
5.1. 124
5.2. K E (Single Dimensional Array) 126
5.3 (Strings) 131
5.4. K E (Two-Dimensional Array) 136
5.5. O E 143
JC M 145

6 151
(Classes and Objects)
6.1 - 151
6.2 151
6.3 (Data Abstraction) 154
6.4 154
6.5 155
6.6 156
6.7 M 157
6.8 G W 159
6.9 static 160
6.10 O E 164
JC M 164

7 169
(Polymorphism)
7.1 169
7.2 EI (Function Overloading) 169
7.3 P EI (Operator Overloading) 174
JC M 182

vi
8 A NH 184
(Constructors and Destructors)
8.1 184
8.2 A (Constructors) 184
8.3 AJ 185
8.4 AJ EI (Constructor Overloading) 185
8.5 A
MF 190
8.6 NH (Destructors) 190
8.7 NH
MF 191
JC M 192

9 K 193
(Inheritance)
9.1 193
9.2 KF 194
9.3 M 194
9.4 G / A H
(Visibility Mode / Accessibility Specifier) 197
9.5 KF 201
JC M 204

10 F e
EPJ 208
(Impact of Computers on Society)
10.1 208
10.2 EP 209
10.3 EP i 209
10.4 iL A E
211
10.5 MJ EP 213
10.6 A EP 215
10.7 EP 216
10.8 J EP 217
10.9 G O 218
JC M 218

vii
11 N
(IT Enabled Services) 219
11.1 219
11.2 I- (e-Governance) 220
11.3 M (Call-Centres) 222
11.4 (Data Management) 222
11.5
(Medical Transcription and Tele-medicine) 224
11.6 EP (Data Digitization) 225
11.7 227
JC M 227

12 EP P
(Computer Ethics) 228
12.1 (Data Security) 229
12.2 EP (Computer Crime) 229
12.3 (Cracking) 232
12.4 , , 232
JC M 232

viii
1

C++ NJN G

(Object Oriented Concepts using C++)

1.1 G N
(Object Oriented Programming Language)
C b M
EP MA. C b EP G
(Programs) (Application
Software) AA. G
G NJ A.
EP G, k O
e A. k
, EP GL Of
A.
G NO k Of
P (Variables) . k
(Data Types) .
O e G EP
P (Control Statements) .
G N J A.
CL bP A.
b C
I CA , G N
O F A A.
F G N .
EP P O N
.
H, C bM, (data),
(operations) HK , Q
J C b FM
.
C++ G N,
J C HC b, Q
1

. , Q HC
b , b Q
A. H
A.
F
P. K O F
O
K A F
J C b F I P
AA. Oe G
, C b N
G A.
O Q, O F,
H , G
C HKA.
- - (object)
A. , O H A.
EP GL
A.
, EH (Calculator) .
G (State), H (Behaviour) A . G ,
c , , CF, P
PA. H , , N,
GF I, G N
A.


FO

F, ,
M
C F

1.1 EH
2
G NJ EH
A:

- EH
:
Number1,result, operator, Number_backup

:
Additon()
Subtraction()
Erase_Memory()
Display_Result()

 ,
A .
 , PH ,
G .


F
(Encapsulation ) N A.


H F
A.

A , , , , L
G H A
O . M
EP GL
P F A.
GO A E
(Objects) OF.

3
- A
A
: :
Account number long int Date_of_birth char[10]
Name char[15] Name char[15];
Opening balance float; Class, sec char[4];
Account type char Marks float

: :
Accept_Details() Accept_Details()
Display_Details() Display_Details()
Update_opening_balance() Total()
Withdrawls() Average()
Deposit() Grading()

1.2 (Polymorphism)
, , ,
E .
J.
:
Draw_Square() Draw_Rectangle() Draw_Circle() Draw_Arc()
Read side Read length, Read radius Read Start_angle,
Drawrequired breadth Draw End_angle,radius
Draw
lines required lines draw

W :
Draw (side) -
Draw (length, breadth) -
Draw (radius) -
Draw(radius, start_angle, end_angle) -
Draw( ) k A.
. J
k Draw()
P . Draw( ) kO
J O
(Polymorphism) A.

F O
F A.

4
1.3 K (Inheritance)
(Class) M A G
AA. H
O (Template) . , JKO
MA A. , M
A. M , ,
G-c , C, HK
P. M
. , , N,
A MO
A. , ,
MO . MO
, .
J K Q E
. , , G-c , C,
A , M M
A A. A:

Class animal :
Features :
eyes, skin, habitat, food

Functions :
Reproduction()
living_style()
prey_Style()

Mammals Birds:
Young_ones Young_ones;
Mammary_glands Feeding_Style;
Skeleton_hollow;
Functions:
Parenting(); Functions:
Reproduction_style() Migration();
1.1 K
M (base class) A.
, M (derived
classes) A. M F I.
K Q
M .
5
M K (Inheritance)
A.
K M M
IMA. G PJ (Code Reusability)
FA.
GF :
 GO,
(Class) M
A.
 H O ( O
)
.
O I O
A. (Data Hiding)
(Data Abstraction)
A.
 (Function) P (Operator)
F
(Polymorphism) C (Complexity)
A.
 K (Inheritance), M
J M
NA. P (Code
Resuability) FA.
O, H
P A F N
A.
1.4 : i c
i c G
. F c OPO
O cK , cK
A GL . G
M: F G c FHO (Taps)
E, FHJ N O cK ,
F cK . FH
. , c
6
1.2 i c
/ G PH M
0 cK A
. E FH ,
FH F, E,
cK P, c A A
P P (Instance Variables)
. FH A:
:
Tap_open, Qty_water,
Water_source

:
Start()
Stop()

1.3 FH
cK A G, FH c
MQA c (Water pipe)
. c FH A
(Building) . c
Q,
F FHO G
P . FE 1.4 -
A.
7
i FK c

t1, t2, t3 A
FH
p1, p2, p3 A
c

:water_pipe

:
Thickness, Length,
Valves

:
Water_flow()
Valve_Status()
1.4 i c Time_Taken()

cK total_amount F,
t1.water_consumed()+t2.water_consumed+t3.water_consumed()
A. QQ FHJL cK
t1.water_consumed(), t2.water_consumed(),.... P.
t1.water_consumed() P1
N cK
P. t1 FH cK
P1 J bQA. G,
F M A
. O
A. G O A , GL
F M A. , k
H K A.
GF , , A
A
A. I J , GO
O M A.
O H M
GF PH C
.
8
JC M

I. G
) EP GL
________ A.
)
H ____________________
A.
) F O
F____________________________ A
) M F
M ___________________
A.

II. W M M O:
1. ?
2. F ?
3. KFL
A?

III. W FE M
G
FK (Data Model) K MA. G
E K I .
EO M: Name, date of birth, language, nativity.
EO E J I
M:
) Stores - date of joining, dept, salary
) Scientist - area of specialisation, current project details, paper presentations
) Technician - height, weight, ailments, risk factor, department, wages

9
2
C++ NJ
(Overview of C++)

2.1
C++ N 1980-O F & F
vv (Bjarne Stroustrup) .
C++ (C Hv Hv K )
K vC . ++ C NJ
I P .
2.2 C++ P F (C++ Character Set)
C- N C++ N P F
. FL M (Tokens- G P
O ) A.
P FJ W P A:
A........Z, a.......Z, 0........9
+, -, /, *, \, (, ),[, ], {, }
=, !=, <, >, ., , , ;, :
%, !, &, ?, -, #, <=, >=, @
O, A ,
F F H P.
P .
M (Tokens) A. M
GL eC Q . M
2.1- A.
M

C P PL P G
P
2.1 MO

2.2.1 C
EP NJ GH (Language Compiler)
KA C A.
10
C .
P . C++ NJ
C O 2.1- .
auto break case const class continue
default delete do else enum for
friend goto if inline new operator
private protected public return signed sizeof
static struct switch this unsigned virtual
while
2.1 C
2.2.2 P (Identifiers)
P, P (Variables) A.
P , F PL A G
PA. PJ F
WP(Underscore) A,
. _test; test; sum12 A
P. P H
P P .
2.2.3 PL (Constants)
PL F M
. PL ,
. PL
F . . F
O (decimal numbers) . (Integers)
I O (floating point) PL .
2.2.4 PL (Integer Constant)
PL
. HF .
+ - A P (prefix) .
0 - M (Octal) PL
. (-) 010 = 8 ([8]10 = [10]8).
0X F (hexadecimal)
. (-) 0XF=15 ([15]10 = [F]16).
11
2.2.5 I O PL (Floating Point Constant)
I O PL PJ P.
, F, F O, H F, F
A F . I O
PL PH F, H F A
MM.
. 58.64 I O
() . J
W PH:

5.864E1 => 5.864*101 => 58.64


5.864E-2 => 5864*10-2 => 58.64
0.5864E2 => 0.5864*102 => 58.64

I O J PH E
e .

2.2.6 P PL (Character Constant)


P PL P
P . C++ NJ P
FJ P (ASCII
FJ E/d/H C
P) . (tab), HQO (backspace)
KF (line feed), FHL (null), H (backslash) A C
P M K (escape sequence) PHA.
M K H
PH. 2.2- M K P
.

12
M K P
\a E L
\b HQO
\n F K/ KF
\t A
\v
\\ H
\ () \ /
\o
\X F
\0 FHL
2.2. M K P
2.2.6 G (String Literal)
G P
PO K . G
PO E (array of characters) A.
G (by default) \0 C P
P . F F PA.
(-) : testing
2.2.7 P (Operator)
P F M G
PA. P H
O (Operands) e A.
:
RESULT = NUM1+ NUM2
F, NUM1, NUM2 A H. +
M P . =
FH(assignment) PJ M M F,
RESULT PJ IA. C++ NJ
PO 2.3- .

13
[] * % == = >=
() + << != *= &=
. - >> ^ /= ^=
-> ~ < | += |=
++ ! > && -= , --
size of <= || %= #
& / >= ?: <<= ##

2.3 C++ NJ P
W P C++ N K:
:: .* ->*
# ## A P L (Preprocessor)
F .
P :
W (Arithmatic)
FH (Assignment)
K (Component Selection)
G (Conditional)
(Logical)
(Manipulator)
H P M (Member dereferencing)
G (Memory Management)
L (Preprocessor)
d (Relational)
(Scope Resolution)
(Shift)
(Type Cast)
HO E J
P (Unary) (Binary), (Ternary)
HK.
:
P H .
P H .
P H .

14
P M
+
- N
*
/
% eF
<<
>>
HG &
|
^ Q
&&
||
M FH = FH
P /= FH
& K += FH
*= A FH
! F %= eF FH
* -= N FH
<<= FH
++ I >>= FH
~ HG G &= HG FH
|= HG

FH
- F d < MCP
> MK
+
<= MCP G
2.4() >= MK G
P G == G
!= GK
. K
K
-> K
:: /
H P
.* P M P
G -> *
P M
?: P
O , FH
2.4() P
15
2.2.7.1 W P (Arithmatic Operators)
W P E G
A. W PO :
P
+
- N
*
/
% eF
+=, - =
*=, /= A
%= FH

W P, PL/P,
W P
A A, W (arithmatic expressions)
A.
:
a = -5;
a = +b;
a/=5; (a=a/5)
a++; (H I P. a = a+1 G)
a- -; (H P. a = a-1 G)
++a; ( I P. a = a+1 G)
- -a; ( P. a = a-1 G)
a *= 2; (a = a*2 )
a %= 5; (a = a%5)
a = b + pow(x,y); (a = b + xy )

P KJ J GA.
H, P PH
FHA.
(association) A. F .
E PO
2.6 - .

16
P F
K
( ), [ ] E I
H ++, E- I
++,
+, - E- I
*. /. % E- I
+, - E- I
2.6 E PO K
W , W FH
K MA.

5 + 6/3 = 7 5 6 3

5 * 6/3 = 10

17
(5 + 6) /3 =3

k int M 3 .
k float Q, M 3.66 A.

1 + pow (3, 2) = 10

18
1 + pow (3, 2) * [ (3 + 2) (8 - 7) + 2 ] = 55

I, P C NJ C++
NJ A. P
, FH 2.7- .

19

a++ a- F a = 5;
FH 1 I c = a++;
:
c = a;
a = a+1;
, c
PJ

F 5 .
++a a- FH 1 I a = 5;
F c = ++a;
:
a = a+1;
c = a;
,
c-
PJ
.
F 6 .
a -- a- F a=5;
FH 1 c = a--;
:
c = a;
a = a-1;
c-
F
?
--a a- FH a = 5;
F c = --a;
:
a = a-1;
c = a;
c-
F
?
2.6 I, P
20
2.7- FO PO
F ?

1. a = 5; 2. x = 10; 3. fun=1;
b = 5; f = 20; sim=2;
a = a+b++; c = x++ + ++f; final= - -fun + ++sim-fun- -
PJ PJ PJ
F
F_____ F fun-_______
c-_______ sim-______
x-_______ final-______
f-_______

2.7 O M

2.2.7.2 d P (Relational Operators)


F H d P A.
d PO :
== G
> MK
< MCP
>= MK G
<= MCP G
!= GK
d P F H A.
H d P
d A. ,
W G d P
.
10 > 20
500.45 <= 1005
99 != 99.5
9 == 9

21
d , K (true) (false) A
M . PL 0 (N) (false) F
PA. N F K (true)
P. O Of :
0 (10>20 )
1 (500.45<1005 K. NI F)
1 (99!=99.5 K. NI F)
1 (9==9 K. NI F)

W J F ?

num1=99, num2=20, num3=10 Q


(num1+num2-num3)/5*2<(num1%10) ?

2.8 - d FH:

P M

== 5==6 0

!= a!=a

> 5>6

a>A

< 5<6

a<A

>= a>=z

5>=5

<= a<=z

5<=6

2.8 d FH
22
d P, W PM
K . , x+y*z< e/f
FH:

2.2.7.3 P (L P)
GO M
P PA. && (AND), || (OR) ! (NOT)
A P .
:
c=5. d=6. choice=y, term=2' (K 1 ,
0 F ).
Result_1 = (c == d) && (choice != term)
Result_2 = (y == Y) || (term != 0')

Result_3 = (c==d) &&(y == Y) || (choice != term)


Result_4 = (c==d) || (y == Y) && (choice != term)

Result_1, Result_2 AP F ?
Result_1- F 0 (); Result_2- F 1 (K)
Result_3- F 1 (K); Result_4- F 0 ()

23
Result_1 = (c == d) && (choice != term) F Fh J

Result_2 = (y == Y)&& (term != 0) F Fh J

24
Result_3 = (c == d) && (y = = Y) || (choice != term)

F Fh J,

1 K

25
Result_4 = (c == d) || (y = = Y) && (choice != term)

F Fh J,

26
P, d P W
PM K . H
J F P ?
5<4 && 8+9

0 -

2.2.7.4 G P (?:) (Conditional Operator)


G P,
(num1>num2) ? K: ;
. ? : P. (num1>num2), K,
- A H. P G P
A. PJ ,
E1? E2: E3;
. E1, E2, E3, A H . E1
G . E2, E3 A F,
. , O K
PJ ,
max=(num1>num2) ? num1: num2;
. num1 F num2-
K Q max- num1 . , max- num2
.
27
W FJ, x PJ
F ?
a = 10;
b = 10;
x = (a<b)? a*a : b%a;
2.2.7.5 FH P (Assignment Operators)
= FH P . J
(PJ ), M PJ (P
J ) A.
FH P M N
FH P . FH P
W 2.9- .
M
A=5 A PJ 5 P 5
F A. F A

A += 2 A += 2 A- J
A = A +2 . F 7.

A *= 4 A=A*4 A- J
F 20.
A /= 2 A=A/2 A- J
F 2.
A-=2 A=A2 A- J
F 3.

A %= 2 A= A%2 A- J
F 1.
a=5, b=6, c=7 Q W O F :
a += b*c

c *= a + a / b

b += a % 2 * c

2.9. FH P
28
C++ NJ PO
K G F
2.10- .

P K F
() I
[] I

H ++, , E I
++, E I
! I
+, - E I

* / % E I

+- E I

< <= > >= d I

= = != d I

&& (AND) I

|| (OR) I

?: I

= *= /= %= += FH I
-= <<= >>=
&= ^= |=

2.10 P K
(P: C++ N K C P O M
)

29
2.2.8 G P (Punctuators)
G P PH E P
. G P P
2.11- .

G P
; C++ A
// P (Comments)
A.
/* */ P A F
P .
{ } C++ F P
A. P
F P .
[ ] EJ PH A
(Index) P
.
P P
.
P .

2.11 G P P
2.3 (Data Types)
G NJ P
PH F . M
(Data Types) A. C++ NJ
HK F, C I
GO E OA.
J HK
:

M GH (Compiler) K G
A F .
30
G G M
P F .
M J HK:
M (User defined type)
O M (Built-in type)
M M (Derived type)
HK 2.2-
:

C++Data
C++ M
Types


User Defined type O
Built - in type M
Derived type
(M)
fundamental)
(Structure) E
Structure Array(Array)
(Union)
Union Function (Function)

Class (Class) (Pointer)
Pointer
(Enumeration)
Enumeration P (Reference)
Reference


Integral type void I
Floating type

float double
int char

2.2 C++ M

2.3.1 M (User defined data type)


G M, A
F .
GL O (readability) A.

31
, W M :

MF
student

2.3 M

student M (class)
. P,
O M K K
. K M , M
FJ .
, class student M
F
M M H GL
O F.
G M F
. (Type definition) F
, M P A FA.
:

typedef <M> < M P>;

:
typedef int marks;
typedef char grade;

32
marks, grade A M P
. int, char P :
marks eng_marks, math_marks;
grade eng_grade, math_grade;
F M P A
typedef A. GL O A.
M M.
PO M
M A. int Pf PL
.
:
enum <M P> (F1, F2...... F n );
:
enum working_days (Monday, Tuesday, Wednesday, Thursday, Friday);
enum holidays (Sunday, Saturday);
working_days, holidays A P
M . (Monday, Tuesday,...) PL
PL F
.
MF W P
PM:
enum <P> P1, P2,.......Pn;
, working_days MF first_workingday,
last_workingday P W PM :
working_days first_workingday, last_workingday;
P working_days F
FO .
first_workingday = Monday;
last_workingday = Friday;
P PL Monday, Tuesday, Wednesday....... A
GJ GH Q 0-M A 1, 2, 3,...........
K int PL A. ,
FH .

33
first_workingday = 0;
last_workingday = 4;
, P PL O
F PH int PL
.
enum working_days (Monday=1, Tuesday, Wednesday, Thursday, Friday);
F Monday 1 F .
PL 2, 3, 4.... int PL F .
2.3.2 I (Storage Class)
PJ PM I F
A (qualifier) . auto, static, extern,
register I . static,
register A PO PM 0
F MA. auto PO
MF J F F
F. auto P, (Garbage)
F A. I
, 2.12-
:

34
I

auto P (local variables) . void main()


PM {
F P auto float ratio;
. Q, auto int count;
P }
auto . ratio, count A P
auto I main()
.
PHF. autoI

static P void fun()
F {
P static int x;
F x++;
N A. PP }
P PM
F
H EP
GF AJ static
F(Modifier)
A. P C
F
A.
extern P, extern int filemode;
GL extern void factorial();
O
MP(global variables)
. P
GL .
register register F, void fun()
PM P {
CdM FO (registers) register int i;
F GH }
A. I
.
2.12 I
35
2.3.4 O M (Built-in Data Types)
O M M
M A. GHJ
. M
(integral), I(float), FHL(void) HK.
, int, char A M A. int
M. 1, 2, 3...... F . H F
. char P M. Q P
F, F A . ,
ch PJ PM, F FH
:
char ch = A;
,
char ch = 65;
PM. (65 A F vA F
). E G
A. ch PJ A A.
I M float, double A M
A. I M H F F
F F . (I O PL
P G ).

FHL M (void type) J A:

F FH
P
(generic pointer) PM

, W void.cpp, fun.cpp A C++ GO


:

36
void.cpp GL void cpp(void) PM
(prototype) M F FH ,
O (parameters) M M F
A. main( ) P,
fun() . fun.cpp GL PM
int fun(int a, int b) fun( ) int
F FH GH A.
main() P sum=fun(a,b)
. sum P return a+b
int FH A.
 void M, F FH
GH A. L
A, void M F
A.
M F (modifiers)
A. F GJ AF
M A. signed. unsigned. long. short
A C F . M,
GF , P
F A 2.13- .

37
Type Byte Range
char 1 -128 to 127
unsigned char 1 0 to 255
signed char 1 -128 to 127
int 2 -32768 to 32767
unsigned int,
unsigned short int 2 0 to 65535
signed int,short int,
signed short int 2 -32768 to 32767
long int,signed long int 4 -2147483648 to
2147483647
unsigned long int 4 0 to 4294967295
float 4 3.4e-38to3.4e+38
double 8 1.7e-308 to
1.7e+308
long double 10 3.4e-4932 to
1.1e+4932

2.13 M P F

2.3.4 M M (Derived Data Types)


M M int, float O
M MOL
. , E (Array)
MF PM/FH :
int num_array [5] = {1,2,3,4,5};
char dayname [7] [4] = { Sun, Mon, Tue, Wed, Thu, Fri, Sat};
num_array 5 F . EJ
H N A. H
0 ML A. num_array[0] H 1
. num_array [4] H 5 .
dayname[0], dayname[5], dayname[3][2] A O
F ?

38
(Pointers)
G K P .
PJ G H
A. EP GF
K . K .
i . K NULL F
A 1, 2, 3 ......... K .
, 640Kb G, NULL A
6,55,356 K . 2.4 .
640KB G

Null K
1
2

655358 Last Address

655359 C K
2.4 640KB G

G F N , GH,
PK G H W A. P
M GF
A.
, W PM :
char c; int i; float f;

P K
char c - 1 PHA.
, c, i, f A PO G
int i - 2
H 1, 2, 4
float f - 4 . P K
F J PA.
39
M , K (&), F
(*) A P P P .
& P:
int num1=10;
, C++ GH (C++ Compiler) W
A:

1. GF int F F W
A
2. G num1 A.
3. GF F 10 F A.

num1 PJ (HF )

10 (HF F)

0X8f90f2 num1 PJ G K

// Program 2.1
// to demonstrate use of & operator
#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
int i = 10;

cout << \n Address of the variable... <<&i;


cout << \nValue stored in the variable .. << i;

getch();
}

40
W F :

P: F P (*)
1. P PM .
2. GF F FJ
(F P).
3. P (Unary Operator) .
2.4 P (Variables)
PH FH A
F P A. , W
:
int num;
num = 5;
int num ; n int P
A.

int num;
num = 5;

FH , 5 F num PJ
A A.

G H
P .

41
PJ , , W (underscore)
A . F WP
. Q, WP G
P (internal system variables)
P. (Case Sensitive)
. . CP , K F
F PA. 2.14 - G .
P K/ H
H?
A_b K
1a_b H PJ
WP
.
_Test

Balance$

#one

Include
2.14 P O
2.4.1 PO PM
F F P G
A. P MF J GH
G A. , P
M PH PM .

int q;
float f1, f2;
char name [10], choice;
PM P :

M P O PJ

42
int side, float hypotenuse, area;
PM . PM.
, GH P K:
side, float, hypotenuse, area A int P
. , float H O
H F .
side int P, hypotenuse, area float
P PM .
PM P :


P PM P PH .
O HK .

M PM char, int, double, float, void, short, signed,


long, unsigned A A.
long, short, signed, unsigned A, O
O P F
(modifiers) FA (qualifiers) A.
void .
GJ 15 int F 00000000 00001111
A. int F J 16 H H
F A. A H
15 H F
A. int PJ
F +32767. C F -32768. (215 = 32768. F 0 +
32767 . F F -1 -32768 ) 16- H,
F H (Most Sifgnificant Bit ) P H (Sign Bit) A.
, (Positive) F (Negative)
PA. 16- H 1 Q F , 0 Q
.
43
int PJ PMH unsigned F
F PJ F .
P H F F. ,
FH 216 . 0
65535 F .

 F (modifier) MF
H P F M A.

FO M:
unsigned F, /F
P P H F F
P FH
PA.
long F PH MF
FK, FH cA.

MF P PM,
F . ,
unsigned int registration_number;
unsigned long int index;
signed char c;

 P PM, F
M .

const FA (qualifier) GL F
PJ F A. const
PJ F GH H
F . const FA, H F
P PM M
A.
:
const float pi = 3.14;

44
FA F H
E FH P
M 2.15- :

Data Types
Type Length Range
unsigned char 8 bits 0 to 255
char 8 bits -128 to 127
enum 16 bits -32,768 to 32,767
unsigned int 16 bits 0 to 65,535
short int 16 bits -32,768 to 32,767
int 16 bits -32,768 to 32,767
unsigned long 32 bits 0 to 4,294,967,295
long 32 bits -2,147,483,648 to 2,147,483,647
float 32 bits 3.4 x 10-38to 3.4 x 1038
double 64 bits 1.7 x 10-308to 1.7 x 10308
long double 80 bits 3.4 x 10-4932 to 1.1 x 104932

2.15 F M

P PM
int * iptr;

PJ

P, GH
A (P K )

int A
PA.

int * iptr PM , iptr int


P (pointer variable) .
int F F K iptr
P .

45
PJ PM :

char * cptr char PM


float * fptr float

void * vptr M A
. G
PMA.

const int *ptr PL int F ptr.


(ptr G KJ
int F P )

char * const cp cp PL . cp-


K P .

2.16 P

2.4.2 P A (Initialization of Variables)


P PM F PH F
FH A. PO
FH A (Initialization) A.
int num = 10;
int fun(5);
P num PJ 10
FH. P A (constructor)
5 F fun PJ .
(Implicit Conversions)
J O GH
A. ,
W F :
float f = 7.6;
int x = f;

46
, x PJ 7 F . float
int M. GH
A.
MF:
P H
P .
F W G:
1. H long double Q
HJ F long double .
2. H double Q F double
.
3. H float Q F float

4. H unsigned long int Q F
unsigned long int .
5. H long int Q F long
int .
6. H unsigned int Q F
unsigned int .

// demonstrating implicit type conversions


// Program 2.2
# include <iostream.h>
# include <conio.h>
# include <iomanip.h>

void main()
{
clrscr();

int i;
float f;
double d;
long double ld;
unsigned int ui;

47
unsigned long int uli;
i = -5;
f = 2;
d = 3;
ld = 3;
ui = 6;
uli = 4;
cout <<\nSizeof long double..<<sizeof(ld*d)<<\t<<ld*d;
cout << \nSizeof double... << sizeof(d*f)<<\t<<d*f;
cout << \nSizeof float... << sizeof(f * i)<<\t << f*i;
cout << \nSizeof unsigned long int ...
<< sizeof(uli* f)<<\t<< uli * f;
cout << \nSizeof unsigned int... << sizeof(ui * i)
<<\t<< ui * i;
getch();
}
P: sizeof P.
MF M (M F GF
) O M .

Output displayed by the above program:


Sizeof long double ...10 9
Sizeof double ...8 6
Sizeof float ...4 -10
Sizeof unsigned long int ...4 8
Sizeof unsigned int ...2 65506

Program 2.2 - J 2.17 - G .


J F
M M .

48
K MJ

1. 10 ld*d ld P long
double
JL
F
long double
.
2. 8 d*f
------
JL
F
double
.
3. 4 f*l
4. 4 uli*f
5. 2 ui*i
2.17 Program 2.2- J JC
P A
P H PO K FA. ,
P M ,
PJ K . ,
int *iptr, num1;
num1 = 10;
iptr = &num1; // PJ
FH

W FH H:
int * iptr;
float num1 = 10.5;
iptr = &num1; // int iptr PJ
float PJ K
H F A.

P PJ M F
.
49
(Type Cast):
PJ F FH M P
PA (float)7
7 F float A.
P FH M
PH A. :
(< >) <P/F>
,
< > (P/F)
, O M
K.
x = 8% 7.7;
GH (compilation)
H F . , % eF P
int M FO . H
,
x = 8% (int) 7.7;
FF . float PL 7.7 F int
PL . 2.18 - G .
int x;
x =7 / 3; x- F F ?
float x;
x = 7 / 3; x- F F ?
float x;
x = 7.0 / 3.0; x- F F ?
float x;
x = (float) 7 / 3; x- F F ?
float x;
int a = 7 , b = 3;
x = a/b; x- F F ?
float x;
int a = 7 , b = 3;
x = a/ (float) b; x- F F ?
2.18 x- F P
50
JC M

1. W O FH K bQ:

i. a + pow(b, c) * 2
ii. a || b && c
iii. a<b && c || d > a
iv. (c>=50) || (!flag) && (b+5 == 70)
v. (a+b) / (a-b)
vi. (b*b) 4 * a * c

2. W GO H :

a. b.
# include <iostream.h> # include <iostream.h>
void main() void main()
{ {
float f = 10.0; float f = 10.0;
x = 50; x = 50;
cout << x << f; cout << x << f;
} }

c.
# include <iostream.h>
void main()
{
int x,y,k,I;
x = y + kI;
cout << x;
}

51
3. GO Of ?

4. W C++ N FH:
a=5, b=3, d=1.5, int c, float f .
a. f = a+b/a;
b. c = d * a+b;
c. x = a++ * d + a;
d. y = a b++ * b;
e. (x >= y) || (!(z==y) && (z < x)) Q,
52
 x = 10, y = 5, z = 11 ( )
 x = 10, y = 10, z = 10
 x = 9, y = 10, z = 2
5. W G, G P F
C++ F :

 x = 30 Q f = 0.5 f = 5
 x> = 60 Q fn = 0.9 .7

6. P ?
7. P M PJ K F name
P PM P F .

53
3

(Basic Statements)
C++ NJ (Basic Statements) M
(tokens) F A. C++ N
HK:
k/ Of (Input / Output)
PM (Declaration)
FH (Assignment)
(Control Structures)
(Function Call)
O F (Object Message)
FH (Return)
3.1 k / Of
F
OJ EP GL P
. PO F N
. , FH
. F .
N, GL F k
. G A , M N
k cin (C- K
) A. cin C++ NJ
(Object). k
(Standard Input Stream) AA. k ,
k M JL
PA. cin k OL
. P H . cin P
PM istream.h H (Header file)
. k/Of
istream.h, ostream.h A O
C PMO GA. istream, ostream A
iostream.h
.

54
, O
PM
.
-L P F,
H GL .
-L P # P .
, E GH
A.
L P #include<iostream.h>
. , iostream.h
H GL GH
A. cin/cout A
F Q, iostream.h
H GL .
C : iomanip.h, stdio.h, ctype.h,
math.h, fstream.h H.

>> P (extraction)
(get from) P . P,
OL (stream object) F ,
PJ F. , W
:
float temperature;
cin >> temperature;

P (>>), k cin-L
M , temperature PJ F
A. P ,
F k JL , K
PO F . , temperature, humidity
A P k ,
cin >> temperature >> humidity;
.
cout (C- K ) O
f (Object) .
Of F C A.
55
Of FF (redirect) .
<< P M (insertion) (put to)
P . P PJ
F O F . ,
W :
int marks = 85;
cout << marks;
cout << \n Marks obtained is : << marks;
marks PJ I F cout
H . marks- F FJ .
cout << \n Marks obtained is : <<marks;
, F PJ F
F H. , Of P
, M J
OJ .
C :
cout << \n The sum of the variables a,b .. << a+b;
cout << a+b << \t << a-b << \t << a/b;
cout << \n The difference of numbers . << a-b
<< \n The sum of two numbers . << a+b;
3.2 C++ G - C++ GL
// My first program Program 3.1
# include <iostream.h>//preprocessor directive
# include <conio.h>
float fact = 1; // declaration of variables
int term;
int main() // function header
{
clrscr(); // predefined function
cout << \n This program computes factorial of a
number;
cout << \n << Enter a number ...;
cin >> term;
// looping statement
for(int x = 2; x <= term;fact *= x,x++);
cout << \nThe factorail of the given number ..
<< term << is .. << fact;
return 0;
}

56
G . C++ G A HK
:

P, O PM
main() .
HIP G H, G
main() . P,
GL H , H A
.
3.3 (Declaration Statements)
GL P P
M .
int *iptr; // int PMA.
iptr = new int; // int F G
A- P
M.
*iptr = 5; // 5 F A. G
H GA.

PJ PM, PJ
PA. , int *iptr;
PM . iptr int
P P K .
P, F FK G
A.
M, P,
, P PM
PM A. HK 2.3-
M P G .
P PM, G A Q,
PM (definition) .
,
int num;
PM P . ,
57
A. , M F G
MA. W F :
int num; // int PJ PM .
num = 5; // F 5 A.
G W O K
Qb? char, int, float
MO P PM G
MA.

 PM PJ PA.
PH M A.
 P GF K
A.

 C P PM G
MA.
 P PM
F. G W
A. new P G
W .

3.4 FH (Assignment Statements)


FH , FH P
J F PJ A. =
FH P . , PO
FH :
num = 5;
total = english+maths;
sum += class_marks;
FH , C++ GH,
J M, PJ M P
A. 2.4.2. - HKM M / O
G .

58
3.5 (Control Structures)
GL H
K G A .
GL C F GJ K G
. GJ, GL
FJL F A.
G
A. W :

K

G

K
1 2 G
1


2

3

-1 : -2:

1. k , Q
1 , Q
OJ G 1- .
H K GA.
2. k , A
F, J
F G .
F eF A Q M=ODD
59
, eF M Q M=EVEN M
A HKA.

 , GL FJL
F G
A.

A
J, bQ (Decision Making Statements),
(Looping Statements) . bQ
(Selection Statements) . C++ NJ
W F
A.


Control Structures


Selection
Loop

if .. else switch Exit Control Entry Control


Do
d .. while () loop f
For(;;)
While
w () loops

3.5.1 (Selection Statements)


GL G J bQ (Decision),
GL F A.
C++ NJ bQ O
A. I A, N
A if... else... . bQ
switch, PJ F J, A

60
HK A HKM F G
NA.

if : bQ O I O.
O A:

if (N)
if..else (N)
if (G/ )
if (G/ ) {
{ // F-1
}
// F
else
} {
// F-2
}

W G (Program - 3.2) if MA:

// Program - 3.2
# include <iostream.h>
# include <conio.h>
// Demonstrates the use and syntax of if statement
void main()
{
int a;
clrscr();
cout << \nEnter a number ;
cin >> a;
if ( a%2 == 0)
cout << \nThe given number << a << is even;
getch();
}

61
GL, G K
The given.... F, . GL ,
cout<<\n The given... G
getch() MM.

W G (Program 3.3) if.. else... MA:

// Program 3.3
// Demonstrates the use and syntax of if else statement

# include <iostream.h>
# include <conio.h>
void main()
{
int a;
clrscr();
cout << \nEnter a number ;
cin >> a;
if ( a%2 == 0)
cout << \nThe given number << a << is even;
else
cout << \nThe given number << a << is odd;
getch();
}

GL, K
The given number 10 is even F .
else- .

62
if H G /
EJ :

branch P G .

int branch = 10 > 20;


if (branch)
{
// F-1;
}
else
{
// F-2;
}
N (Zero) K
, if(1) G .

if (1)
{
// F-1;
}
else
{
// F-2;
}

G . J F
>0 - FHJ, F-1 G.
F-2 G.

if ( a % 2 )
{
// F-1;
}
else
{
// F-2;
}

63
W G A F
P ?

// Program - 3.4
# include <iostream.h>
# include <conio.h>
void main()
{
int count = 1;
if (count > 0)
{
cout << \nNegating count ....;
count *= -1;
}
else
{
cout << \nResetting count ...;
count *= 1;
}
getch();
}

G A Negating count... F
. count F -1- H else-
H F M
?
F: if...else H if- W
F GJ, else F G
. if F G else
F G.

 N if..else...
H G J
PH F G.

64
. H ?

1. if a> b G H
cout << True; P
. K :
if (a>b)
cout << True;
2. if ( a > b) G H, Misplaced
a- -; else H
cout<<\nVariable is decremented; F .
else F
a++;
cout << Variable is incremented .. H O
P
.
K :
If ( a> b)
{
a--;
cout<<\nVariable is
decremented;
}
else
{
a++;
cout << Variable is
incremented .. }
3. if (a > b); G H
cout << Greater..; O, if
else P
cout << Lesser ..; M. GH,
Misplaced else H
. K :
if (a > b)
cout << Greater..;
else
cout <<Lesser ..;
3.1. if
65
3.2.2- E G
if F :
. E if

1 F 90-
H A G
2. F 90- H A
G . B .
3. E 30 A.e- Q
Accelerate - traffic to flow
E 31-L 40 A.e. Q
Moderate - accelerate by 10 kmph ,
Good- be careful..
F FJ .
3.2. if

H if : if..else H if
. W if..else
H .

(-1)
(-2)

-1;

-2;

-3;

H if..else H,
else- , else- if

66
,

if (grade = = A)
if (basic > 5500)
incentive = basic * 10/100;
else
incentive = basic * 5/100;
else
cout << Try to attain Grade A;

F :
grade== A, basic ==5501 Q incentive- F 550 .
grade == A, basic ==5000 Q incentive- F 250 .
grade != A Q, if G. O else
G. Try to attain Grade A
F A.

if , W if
G? F J .

if (grade = = A && basic > 5500) :


incentive = basic * 10/100;
else if (grade = = A && basic <5501)
incentive = basic * 5/100;
else
cout << Try to attain Grade A;

switch : AHK . GJ
J, O
. A:

67
switch ()
{ switch (remainder)
case 1 : F-1; {
break; case 1 : cout << remanider 1;
case 2 : F-2; break;
break; case 2 : cout << remanider 2;
case 3 : F-3; break;
break;
default :F-4; default :cout << Divisible by 3;
} }

W G, switch P MA:
// Program - 3.5
// to demonstrate the use of switch statement

# include <iostream.h>
# include <conio.h>

void main()
{
int a, remainder;
cout << \nEnter a number ...;
cin >> a;
remainder = a % 3;
switch (remainder)
{
case 1 : cout << \nRemainder is one;
break;
case 2 : cout << \nRemainder is two;
break;
default: cout << \nThe given number is divisible by 3;
break;
}
getch();
}

68
G,
a = 4 eF 1 Q,
Remainder is one
a = 5 eF 2 Q,
Remainder is two .
a = 3 3- Q,
The given number is divisable by 3 .
Q,
F FJ .
W GL Of A
A?

// Program - 3.6
// to demonstrate the use of switch statement

# include <iostream.h>
# include <conio.h>

void main()
{
int rank = 1;
char name[] = Shiv;
switch (rank)
{
case 1: cout<<\n<<name<<secured 1st rank;
case 2: cout<<\n<<name<<secured 2nd rank;
}
getch();
}

GL Of :
Shiv secured 1st rank
Shiv secured 2nd rank
case 1, case 2 A F
KA? Program-3.5 Program- 3.6 A
GO F H .
Program- 3.6- M KA? .
break M. FL P ?

69
FJ FJ break
. , GJ J
M G case- A
case-O F K G.
(Program - 3.6) case 1-
A. F G
A. F break case 2-
F K GA.

 PH case- F
G switch M
O, FJ FJ break
.

W swich H.
:

1. char name[ ] = Shiv; switch selection expression must


switch (name) be of integral type G
{ H H.
case Shiv : cout << \n ,switch-
<< name << secured J F,
1st rank; (char, enum, int)
case Rama : cout << \n PL
<< name << secured .
2nd rank;
}

2. float value; switch() P


switch (value) float
{ HA.
case 1.5 : cout << \n
<< value 0.5;
case 2.9 : cout << \n
<< value + 0.1;
}

70
3. switch (rank) case 1 to 2
{ . case-
case 1 to 2 : cout << \n F
<< Best rank; .
break; PH
case 3 to 4 : cout << \n F
<< Good rank; F
} Q, G
F
.
switch (rank)
{case 1 :
case 2 : cout << Best rank;
break;
case 3 :
case 4 : cout << Good rank;
break;
}

3.5.2. (Loops)
, F PH F
F GA. , W Program - 3.7-
:

// Program - 3.7
# include <iostream.h>
# include <conio.h>
F
void main() G KF
{ G
int i = 1;
F F G
loop_start:
F
if (i < 6)
{
cout << i <<\t; GL , F
i = i + 1; F G
goto loop_start;
} FJ
} .
71
G A, if P W
F 5 G, 1 5 J
FJ .
Program- 3.7 A:

1. i P PM FHA.
2. i < 6 d KFA.
3. G K Q F (cout<<i;i=1;)
GA. GL e loop_start
A (goto loop_start).
d J G J
F F F A. i P,
P PHA. ,
F F F G i- F
A.
, F, F,
F . G
KA. J, GL , A
F e e FHM, F F G
A. W G :

//Program - 3.7 A //Program - 3.7 B


void main() void main()
{ {
int i = 6; int i = 6;
loop_start: loop_start:
if (i < 6) {
{ cout << i << \t;
cout << i << \t; i = i + 1;
i = i + 1; if (i < 6)
goto loop_start; goto loop_start;
} }
cout << i; cout << i;
} }

72
GO Of G
Al?
Program-3.7A, 6 FJ .Program-3.7B, 7 .
GL, (cout<<i; i=i+1;) A H G
. G
M. H G KA. i- F
7 GL loop_start I
M. FL P ?

 A FJ FJ G
J, F
GM.
 G ,
, -F (Program-
3.7A), O-F
(Program - 3.7B) HK.

A , A:
1. G PJ F A.
2. A F GA.
3. G PJ F IA.
4. G P, d J KF
A. d J F J
, FJ ,
M O.
C++ NJ, :
1) for()
2) while()
3) do..while()

73
do...while() :
:
do
{
F;
} while <(G)>

W G :
// Program - 3.8
# include <iostream.h>
# include <conio.h>

// to print the square of numbers


// between 2 to 5

void main()
{
clrscr();
int num = 2;
do
{
cout << num * num << \t;
num += 1;
}while (num < 6);
getch();
}

Program -3.8 GL J W M M
:
) :
1. P
2. A FJ
3. KF
) G?
) GL Of ?
) ?

74
M:
) 1. P num
2. A F :
cout<<num*num<<\t;
num += 1;
3. (num<6) KF
)
) 4 9 16 25
) O-F

A G :
1. A A.
2. num- F FJ A.
3. PJ F 1 IA.
4. G FA. M
J G-2 A.
5. A.
do..while(G) O - F
. , G , A F
F . G
J . :

int ctr = 1, sum = 0, check = 1; int ctr = 5, sum = 0;


do do
{
{
cout << ctr;
cout << ctr;
sum = sum + ctr;
sum = sum + ctr;
ctr = ctr + 2; ctr = ctr - 2;
check = (ctr < 11);
}while(check); }while(ctr);

75
int ctr = 5,sum = 0,c=1;
do
{

cout << ctr;


sum = sum + ctr;
ctr = ctr - 2;

}while(ctr >= 1);

W GO Of ?

Snippet A-J i- F -32768 G.


Snippet A, Snippet B A GO H
. O G
K . Snippet A-J i- F
10- M . Snippet B-J choice- F
1 G K A MA.
F G K G
I A. A F
PJ F I/H
G .

76
while() :
-F . :

while <(condition)>
{
F;
}

while() P F K M
A FJ G
. F J F
. do..while() A M G while()
F e . (Program-3.9).
// Program - 3.9
# include <iostream.h>
# include <conio.h> A FJ
F F
// to print the square of numbers
// between 2 to 5 G
.
void main()
{
clrscr();
int num = 2;
while (num < 6)
{
cout << num * num << \t;
num += 1;
}
getch();
}

:
1. num PJ 2 F
A.
2. num<2 F FH, M K
G-3 A.
3. num PJ FH ,
FJ A.
4. num PJ F IA.
5. GL G-2 A.
6. A.
77
G Program- 3.10- J W M
M O.

//Program-3.10
# include <iostream.h>
# include <conio.h>

void main()
{
int x = 3, y = 4, ctr = 2,res = x;
while(ctr <= y)
{
res *= x;
ctr += 1;
}
cout << x to the power of y is : << res;
getch();

) 1. GL
P ?
2. A F ?
3. KF ?
) GA?
) GL O ?
) F
?

M:
) 1. P ctr
2. res *= x; ct +=1;
3. ctr <=y
)
) 81
) - F
78
W G Program-3.11- Of ?
G k y, y, y, y, n :

// Program - 3.11
# include <iostream.h>
# include <conio.h>
void main()
{
clrscr();
int counter = 0;
char choice = y;
while (choice == y)
{
cout << Continue <y/n> ...;
cin >> choice;
counter = counter + 1;
}
cout << \The loop is executed ..
<< counter << times;
getch();
}

W G H. P H
P. G K H F:

//Program - 12 A //Program - 12 A
# include <iostream.h> # include <iostream.h>
# include <conio.h> # include <conio.h>
//to print numbers between //to print numbers between 5&10
5&10 void main()
void main() {
{ int start = 5, end = 10;
int start = 5, end = 10; while (start <= end)
while (start >= end) cout << start++;
cout << start++; getch();
getch(); }
}

79
//Program 13 A //Program 13 B
# include <iostream.h> # include <iostream.h>
# include <conio.h> # include <conio.h>
// to print numbers between // to print numbers between 10&5
10&5 void main()
void main() {
{ clrscr();
clrscr(); int start = 5,end = 10;
int start = 5,end = 10; while (start <= end)
while (start <= end) cout << end--;
cout << start--; getch();
getch(); }
}

//Program 14 A //Program 14 B
# include <iostream.h> # include <iostream.h>
# include <conio.h> # include <conio.h>
// to print numbers // to print numbers
between 1 & 5 between 1 & 5
void main() void main()
{ {
clrscr(); clrscr();
int start = 1; int start = 1;
while (Start <=5) while (1)
cout << start++; cout << start++;
getch(); getch();
} }

for() :
. PH
G A. :
for ( F; F G; I)
{
F;
}
for(;;) :
1. GL L AQ ,
PJ F .
2. G KF. G K Q A
F .
A.

80
3. A F e G
PJ F I, e G
KF.
4. G .

W G for(;;) A M:

//Program - 3.15
# include <iostream.h>
# include <conio.h>

void main()
{
int i, fact = 1;
for(i = 1; i < 6; i++)
fact *= i;
cout << \nThe factorial of the number is .. <<fact;

for(i = 1; i < 6; i++)

I ( F)

KF G (2- F)

PJ
FH (3- F)

 PJ FH,
A F L
,
.
 A F
G
KF.
 G KF
PJ F I.

81
W G . P Of
? F .
// Program 3.16
# include <iostream.h> Of:
# include <conio.h> 10
9
void main()
{ 8
int ctr = 10;
7
for(; ctr >= 6; ctr)
cout << ctr << \n; 6
}

// Program 3.17
# include <iostream.h>
# include <conio.h>

void main() Of:


{
clrscr(); The factorial.. 120
for(int i=2,fact =1;i<6;fact*=i,i++);
cout <<\nThe factorial .. << fact;
getch();
}

for() P FH I FJ
, Qb?
H J K. for( )
A F P .
O HK . W A
FJ Of ?
Of :
void main() 1 2 3 // j < 3 .
{ 1 2 3 4 5 6 7 // j< 8
. O P
for (int i = 1, j = 0 ; i < 8,j<3;i++,j++) F G
cout << I << \t; . G (
for (int i = 1, j = 0 ;j < 3,i < 8;i++,j++) ) K
cout << i << \t; .
G && ||
} P .
82
// Program 3.18
# include <iostream.h>
# include <conio.h> Of
:
void main()
{ sum : 15
clrscr(); FH
int sum =0, ctr = 1;
for(;ctr <= 5;) I
{ for()
sum += ctr;
ctr = ctr + 1;
} M
cout << \nSum : << sum;
getch(); Qb?
}

// Program 3.19
# include <iostream.h>
# include <conio.h> Continue <y/n> ? y
void main() Continue <y/n> ? y
{ Continue <y/n> ? y
clrscr(); Continue <y/n> ? n
int sum =0, ctr = 1; sum:10
char ch =y; Choice : n
for(;ch == y;)
{ F for()
sum += ctr; G
ctr++;

cout <<\nContinue <y/n> ? ;
cin >> ch; F bQ
} Qb?
cout << \nSum : << sum;
cout << \nChoice : << ch;
getch();
}

W G FJ H ?
int ctr, sum = 0;
for (ctr =1; ctr <5; ctr++);
sum += ctr;
cout << sum;
Of 5 .
KA? for() O .
, sum + = ctr , A F
M.
83
W GFO Of ?

for(it ctr =1; ; ctr++)


cout << ctr;
G
int F
-32768, +32767
A
FJ PJ
F
F e e 1 A
. M
MA. Of
AM.
1 . ,
M AM.

3.5.3. continue
A FJ continue , A
C . A FJ continue
H G.

//Program 3. 20
# include <iostream.h>
# include <conio.h>
for() A I
F .

void main()
{
int i = 1,sum = 0;
for(;i<10;i++)
{
if( i % 2 == 0)
{
sum += i;
continue;
}
cout <<i;
}
cout << \nSum of evennos..<<sum;
getch();
}

84
O continue M W :

3.5.4. break
KF G , A
GA. C GO, KF G
PH F A
. , Program - 3.21- :

//Program - 3.21
# include <iostream.h>
# include <conio.h>

void main()
{
clrscr();
int a[] = {1,2,3,4,5,6,7,8,9};
int search_item = 7;
for(int x=0; x<9;x++)
{
if (a[x] == search_item)
{
cout << \nItem found at position .. << x;
break;
}
}
cout << \n << value of index position is .. << x;
getch();
}

85
Of :

Item found at position .. 6


Value of index position is..6

 break , GL

O A.
x - F 6 -
, break
A PA.

 break AM
O .
 break AM
.

H (Nested Loops)
A FJ H
. W G Program- 3.22- .
// nesting of loops Program- 3.22
# include <iostream.h>
# include <conio.h>
Of:
void main()
{ *
clrscr();
for(int i = 1; i <= 3; i++) * *
{ * * *
int j = 1;
while(j <= i)
{
cout << * ;
j++;
}
cout << \n;
}
getch();

86
O A:

H O A:

for ..loop while loop

i = 1 G 1 ( j<= I)
i = 2 G ( j = 1 .. 2)
i = 3 G ( j = 1.. 3)

W GL Of ?

# include <iostream.h>
# include <conio.h>

void main()
{
clrscr();
int i = 1, j = 1;
while(i <= 3)
Of?
{
cout << \n;
for(i=1;i<=j;i++)
cout << *;
i++;
j++;
}
getch();
}

87
H MF:

1. O-, - P
. H
.
2. - O-A F
F .
3.6 G
EP NJ F, G
NJ G A. G NJ
G P (Source Code) A. P
F K M N . F
N M G (Object file) A.
GH (Compilers) PJL
A. GH , P
JL F N N G
. GH, NJ ( )
KA. HJ PJL
A.
, G (executable file)
A. O K 3.1- .

3.1 G
88
JC M:
1. W PM K, H PH.
H Q, .
PM K/H
int A; a;

char name(10);

float f, int;

double d, float f;

int 1choice, _2choice

2. W GL H FF, K G :

3. W PM
F :
) 8/3 W M F .
) Emp_Name PJ Kalam
FH.
) Y-yes, N-no PH KI k
.
4. W G FO H :
) int a = 10; b = 5;
if a > b
cout << a;
89
) if (a<b) && (a<0)
cout << a is negative and ...
) char option = Y;
do while option == y
{
cout << * ;
.................
}
) for (int i = 1; i < 10; i ++)
cout << i * 2;
) do
{
cout << * ;
}while (cout << \n Continue <y/n> ...; cin >> ch; ch == y);

5. W G/ GFO Of
?

// 5 a. // 5 b.
# include iostream.h> # include <iostream.h>
# include <conio.h> # include <conio.h>

void main() void main()


{ {
int feet; int i = 1, sum = 0;
const int inch_conversion = 12; clrscr();
clrscr(); while(i++ <= 5)
cout << \nEnter feet ; {
cin >> feet; cout << \n << i;
cout << \nConverted s += i;
to inches }
<< feet * inch_conversion; cout << \nValue of the
} variable i after
executing the
input 7 for feet while loop ..
<< i << \nSum:
<< s;
}

90
// 5 c // 5 d
# include <iostream.h> # include <iostream.h>
# include <conio.h>
# include <conio.h>
void main()
{
void main() int i = 1, sum = 0;
{ clrscr();
int i = 1, sum = 0; for(i = 1; i <= 5; i++)
clrscr(); { cout << \n << i;
while(++i <= 5) sum += i;
{ }
cout << \n << i << \t << sum;
cout << \n << i;
for(i = 1; i <= 5; ++i)
sum += i; {
} cout << \n << i;
cout << \n << i << \t << sum; sum += i;
getch(); }
} cout << \n << i << \t << sum;
}

//5e // 5 f
# include <iostream.h> # include <iostream.h>
# include <conio.h> # include <conio.h>
void main()
{ void main()
int i = 1, j = 1; {
clrscr(); int num = 1784, s= 0, d = 0, x;
do x = num;
{ clrscr();
while (j<=i) for(;num > 0;)
{ { d = num % 10;
cout << #;
s += d;
j++;
} num = num / 10;
cout << \n; }
i++; cout << \nThe sum of digits of
j = 1; << x << is :
} while(i<= 5); << s;
getch(); getch();
} }

//5 g
# include <iostream.h> // 5 h
# include <conio.h> # include <iostream.h>
void main() # include <conio.h>
{
clrscr(); void main()
for(int i = 1,s = 0; ; i++)
{
{
if (i%2 == 0) clrscr();
continue; for(int i = 1,x = 0;i <= 5; i++)
s += i; x = x + i%2==0 ? i*1 : i * -1;
if ( i > 9) cout << x;
break; getch();
}
}
cout << \nThe sum is .... <<
s;
getch();

91
//5 j //5 k
# include <iostream.h> # include <iostream.h>
# include <conio.h> # include <conio.h>

void main() void main()


{ {
clrscr(); clrscr();
do int i = 0;
{ for(i = -5; i >= 5; i)
cout << \ndo loop ...; cout << Bjarne Stroustrup;
} while (0); cout << \nReturning to Edit Window..;
getch(); getch();
} }

//5 l // 5 m
# include <iostream.h> # include <iostream.h>
# include <conio.h> # include <conio.h>
void main()
void main() { int day = 3;
{ switch (day)
clrscr(); {
int month = 5; case 0 : cout << \nSunday ..;
if (month++ == 6) case 1 : cout << \nMonday ..;
cout << \nMay ...; case 2 : cout << \nTuesday ..;
else if (month == 6) case 3 : cout << \nWednesday .. ;
cout << \nJune ...; case 4 : cout << \nThursday ..;
else if (month == 5) case 5 : cout << \nFriday ..;break;
cout << \nMay again ..; case 6 : cout << \nSaturday ..;
} }
}

// 5 n
# include <iostream.h>
# include <conio.h>

void main()
{
clrscr();
int bool = 2,b =4;
while(bool)
{
cout << bool << \t << ++b << \n;
bool;
b;
}
getch();
}

92
6. G :
) a , b . ab P. (while()
).
) E (factorial)
P. (for() ).
) n C P.
C : 0, 1, 1, 2, 3, 5, 8, 12, 18, 20, 32, ...
) W E Of . (Q
Q G )
4
1
1 2 3 4
1 2 3 2 3 4
1 2 3 4 1 2 3 4
1 2 3 4 5

B C

D E F

G H I J

7. F F k , W
F OJ. switch() .
) day 1 Q, 1st day in the month OJ.
) day 2/22 Q, 2nd / 22nd day in the month OJ
) day 3/23 Q 3rd / 23rd day in the month OJ.
) day 4,5,......14, 15,16........ Q 4th/5th....... day in the month
OJ.

93
4

(Functions)

4.1
C++ GO F
(Functions) . GL F M
A. G O main()
. ,

 GL c A.

 PJ A.

// To print X!/F! using functions


// To print X!/F! Program - 4.1
// Program - 4.2
# include < iostream.h >
# include <iostream.h >
# include <conio.h >
# include <conio.h >
void main ( )
int fact (int num)
{ int x, f,xfact=1, ffact = 1;
{
clrscr ( );
int factorial = 1;
cout << \nEnter values ...;
for (int a=1; a<= num; a++)
cin >> x >> f; for (int a =1; a < = x; a
factorial *= a;
++)
return factorial;
xfact * = a;
}
for (a = 1; a< = f; a++)
void main ( )
ffact * = a;
{ int x, f;
cout << xfact/ffact;
clrscr ( );
getch();
cout<<\nEnter values;
}
cin >> x >> f;
cout << fact (x)/fact(f);
}

94
Program - 4.1 GL A
F F . Program-4.2 GL
fact (int num)
. , W J A:

 G PJ (fact( )
)
 P Q G (Compiling)
G
A .

P F
:

// To print X!/F! using functions


// Program - 4.3
# include <iostream.h >
# include <conio.h >
int fact (int num)
{
int factorial = 1;
for (int a=1; a<= num; a++)
factorial *= a; ,
return
return factorial; P
} A. GL


void main ( )

{ int x, f;
A.
clrscr ( );
cout<<\nEnter values;
cin >> x >> f;
P
cout << fact (x)/fact(f);
}

95
4.2 P (Function Prototype)
, GL PM
. M PM
A. , Program - 4.4 G .

//Program -4.4
# include <iostream.h>

void fun (char name [ ]) ; (P PM)

void main ( )
{
char n [ ] = { C++ programming.};
fun (n);
}
void fun (char name[] ) P
{ cout << name; }

GH W
A:

1. O (arguments) E P
M-(char name[]) ).

2. FH FH M.(
fun() P M void
, FH F
. Program-4.2 - e . fact()
FH M int .

96
M :
<M> <P > <>;
:
void fun(char);
int max(int, int);
int max(int a, int b);
M , P
K GH .
P PM ,
(Template) A.
, K
, FH F K
F GH F
A. FH M
M Q, GH, H
GH .
int max (int, int) K?
PMH, O FK P.
PH I. M
PH P F (place holders)
PHA.
P J O (P)
A. , P
A.
void fun(char name[ ])
{
cout<<name;
}
int fact(int num)
{ name, num
int f =1; A P
for(int a = 1;a <= num; a++) .
f *= a;
return f;
}
97
4.3 P
P PH, P
L . , . P
O HK H
P . :
// Program - 4.5
# include <conio.h>
# include <iostream.h>

(Formal Parameters)
int add (int a, int b)

{ return a + b;}
void main ( )
{ int x1, x2, sum = 0
cin >> x1 >> x2;

(Actual Parameters)
sum = add (x1, x2);
cout << sum;
}

P :

int add(int, int)


{
...............

return a+b;
}
A.

void main()
{
......................
sum =add(x1,x2);
cout<<sum;
}

98
4.4 P H
P , (Arguments)
(Parameters) K
A.
PL P PL
P O
N A.
C++ NJ , J
.
 F (Call by value)

 P (Call by reference)

4.4.1 F (Call by Value)


H ,
H O F F , F
P A. O ( P
PH ) F, O
(P H PH ) .
, O A
F A. G Program -4.5- G .

main() add()
// Program - 4.5
# include <iostream.h> x1 = 5 a=5
# include <conio.h> x2 = 7 b=7
int add (int a, int b) sum =
Assume address of the variables :
{ return a + b;}
void main ( ) x1 = Oxf1 address data
{ int x1, x2, sum; x2 = Oxf3 Oxf1 5
cin >> x1 >> x2; a = Oxf7 Oxf2
b = Oxf9 Oxf3 7
sum = add (x, x2); sum = Oxf6 Oxf4
cout << sum; Oxf5
} Oxf6 12
Oxf7 5
Assume x 1 = 5, x2 = 7
Oxf8
Oxf9 7

99
x1, x2 A,
a, b A G HO
Qb? , F
J, , PL,
P .

// Program - 4.6
// To exchange values
#include <iostream.h>
#include <conio.h>
# include <iomanip.h>
void swap (int n1, int n2)
{ int temp;
temp = n1;
n1 = n2;
n2 = temp;
cout << \n<<n1<<\t<<n2<<\n;
}

void main ( )
{
int m1 = 10, m2 = 20;
clrscr ( );
cout <<\n Values before invoking swap
<< m1 << \t << m2;
cout << \n Calling swap..;
swap (m1, m2);
cout << \n Back to main.. Values are
<< m1 << \t << m2;
getch ( );
}

Of:

Values before invoking swap 10 20


Calling swap ..
20 10
Back to main... values are 10 20

100
m1, m2 A PO F P, main()
P HFLM. E b?
F H,
, M
MO F P A. O
F F PO A.
, PO
, O HFLF.
F J, O
O HF
LF.

4.4.2 P (Call by Reference)


J, P -
- P O
(alias) A.
O e J, O
e A . Program - 4.6 - G
. P F, swap () P
FF .

//Program - 4.7
// To exchange values

# include <iostream.h>
#include <conio.h>
void swap (int &n1, int &n2)
{
int temp;
temp = n1;
n1 = n2;
n2 = temp;
cout<<\n<< n1
<<\t<<n2<<\n;
}

101
void main ( )
{
int m1 = 10, m2 = 20;
clrscr();
cout<<\nValues before swap call
<< \t << m1 << \t << m2;
swap(m1,m2);
cout<<\n Calling swap..;
cout<<\n Back to main.Values are
<< \t << m1 << \t<< m2;
getch ( );
}

Of:
Values before invoking swap 10 20
Calling swap ..
20 10
Back to main... values are 20 10

O
O HFL. , P
O G
A.
W M :
main() swap()
m1=10 n1=10
m2=20 n2=20
temp
m1, m2 A PO G K Oxf1,
Oxf4 .
m1 = Oxf1 = 10
m2 = Oxf4 = 20

102
O P (reference)
M:
m1 = 10;
n1 , m1- P ,
int &n1 = m1;
PH. , m1- n1 .
, m1, n1 G H PA.
, O ,
n1 = m1 = Oxf1 = 10
n2 = m2 = Oxf4 = 20
.
K H
Oxf1 (n1, m1) 10 20
Oxf4 (n2, m2) 20 10
, O
O FL.
P J, O
O HF
L.

W G A :

// Reference variables
// Program -4.8
# include <iostream.h>
# include <conio.h>
void main ( )
{
int num1 = 10, & num2 = num1;
num2 ++;
cout << num1;
}

103
GL Of 11 A.
PH M num1, num2 A P
G H A.
, num1- num2- HFLA.

MF
1. F J PL, P
J M
H .
,
int add (int n1, int n2)

P :
x = add (5, 10);
x = add (a1, a2) [a1, a2 A int P]
2. P J ,
PO M H .
,

int add( int &n1, int &n2)
P ,
x= add (a1, b1) (a1,b1 A int P)
.
x = add (a1+b1, a1);
x = add (5,10) ;
H.

104
// Program - 4.9
//To print 5 stars per row and 5 such rows
# include <iostream.h>
# include <conio.h>

void fun_starts(int &i)


{
int j = 5;
for (i= 1; i <= j; i++)
cout << <<*;
}

void main()
{
int mi = 1;
clrscr( );
for (; mi<= 5; mi++)
{
cout << \n;
fun_starts (mi);
}
getch();
}

G, PJ PH Of
KA? G,
*****

K M . K M .
: i P mi PJ P (reference)
. G i- F 6
AMA. mi- F 6 AM. , main() -
for( ) A.
4.3.4 Q (Default Parameters)
C++ NJ P M
O Q F .

105
:

// Program - 4.10
// formal parameters with default values
# include <iostream.h>
# include <conio.h>
float power (float n, int p = 1)
{
float prd = 1;
for (int i = 1; i<= p; i++)
prd *= n;
return prd;
}

void main ( )
{
clrscr ( );
int x = 4, b = 2;
cout << \n Call statement is power(b, x)...
<< power (b, x);
cout << \n Call statement is power(b)..
<< power (b);
getch ( );
}

Of:
Call statement is power (b,x) ... 16
Call statement is power(b) ... 2
power(b, x) P FH
:
n = b, p=x
power (b) P, n PJ
2 F .
p PJ Q F 1 .

106
P:
 PJ FH M Q F
.

 P P C M
M
Q N A.

 Q F M
L F . L
F, M .
W G A :

//Program - 4.11
# include <iostream h>
# include <conio.h> Of:
int area (int side1 = 10, int side2=20) 24
{ 80
return (side1 * side2); 120
} PJ FH:
H:
void main( ) side1 = s1, side2 = s2
{ 2 H:
int s1 = 4, s2 = 6; side1 = s1, side2 = 20
clrscr( ); 3- H:
cout << area (s1, s2) << \n; side1 = s2, side2 = 20
cout << area (s1) << \n;
cout << area (s2) << \n;
getch( );
}

107
W GL Of ?

// Program - 4.12
// arguments with default values

# include <iostream.h>
# include <conio.h>

void print (int times, char ch = * )


{
cout << \n;
for (int i = 1, i < = timers; i ++)
cout << ch;
}
void main ( )
{
clrscr ( );
print (50);
print (A, 97);
print ( );
}

M:
print (50) - times 50 F
. , 50 * OJ.
print (A, 97) - times PJ A F
. (char F int F
). times- 65
F .

108
97 F ch- . ,
int F char F .
ch- a .

,

J .
a 65 .

print() -
Q (default)
F . ,
* P, 50 .

4.5 FH FH
F FH void PM
A. P PM M O
PHMQ, P int
. ,
int add (int, int);
add (int, int);
O FH F int .
C++ NJ Q FH M
int .

W :

K FH
1 float power (float, int) float

2 char choice ( ) char

3 char * success ( ) pointer to character

4 double fact (int) double

109
4.5.1 P FH
P P:

// Program - 4.13
# include <iostream.h>
# include <conio.h>
void main ( )
{ int i = 5;
int &count = i ;
cout << \nCount: << count;
count ++;
cout << \ni: << i;
getch ( );
}

Of:
Count : 5
i:6

count P, 5 F ?

count PJ F I i- F F
K? count i A P GF M
. , PJ
P PJ FL.
J, W GL Of
P:

110
// Program - 4.14
# include <iostream h>
# include <conio.h>
int &maxref (int &a, int &b)
{
if (a>b)
return a;
else
return b;
}
void main ( )
{ int x = 20, y = 30, max = 0;
max = maxref (x,y);
cout << /n Maximum is:<< max;
}
Of:
Maximum is : 30
GL, maxref () int PK
PH (reference) FHA. maxref(x,y)
, a, b AP K P FH
. , max P y- F A.
W GL Of ?
// Program 4.15
# include <iostream h>
# include <conio.h>
int & maxref (int &a, int &b)
{
if (a > b),
return a;
else
return b;
}
void main ( )
{
int x = 20, y = 30, max = 0;
maxref (x,y) = -1;
cout << \n Value of x is : << x;
cout << \n Value of y is: <<y;
getch ( );
}
111
Of:
Value of x is : 20
Value of y is : -1
P:
1. PH FH P
FH P .
2. , y- -1 . ,
maxref() , b P
P FH main() P b-
P y . , FH P
b . -1 .
3. P P
P
. ,
int & maxref (int a, int b);
H, GH H A.
a, b A PO maxref ()
P .
4.6 inline
O
L:
 G PJ , G
C ; GL c
.
I, P
, GH
, H F
A. G (stacks)
A GH .
, FH, A
QC C I
A. GL
A. C GO, P CP
( EJ ) ,

112
GH IF,
P GH Fh M. F,
P FL A. inline
A.
inline GL
O. GH (compiling time)
P
F GL M. inline
, F G
.
W :
// Program - 4.16
// inline functions

# include <iostream.h> // working of Program - 4.16


# include <conio.h> // inline functions

inline float convert_feet(int x) # include <iostream.h>


# include <conio.h>
{
return x * 12;
void main()
}
{
clrscr();
void main()
int inches = 45;
{ cout << inches * 12;
clrscr(); getch();
int inches = 45; }
cout << convert_feet(inches);
getch();
}

, convert_feet (inches)
, return P (inches * 12)
Fh .
P inline PM Q,
Program-4.16- P H inline
C .
P: inline C, GH
K . C O GH, K
EM F.

113
4.7 PO (scope) MF
PJ A (accessibility)
PA. C++ NJ .
:
1. (Local scope)
2. (Function scope)
3. (File scope)
4. (Class scope)
4.7.1 (Local Scope)

// Program - 4.17
// to demonstrate local variable
# include < iostream.h
# include <conio.h>
void main( )
{
int a, b;
a = 10;
b = 20;
if (a > b)
{
int temp; // local to this if block
temp = a;
a = b;
b = temp;
}
cout << \n Descending order;
cout << \n <<a << \n <<b;
getch( );
}

P, F (Block) A.
PJ
F .
P PM F
OJL .

114
Program -4.18 PJ MA.

//Program - 4.18
# include <iostream.h>
# include <conio.h>
void main ( )
{ G G
int a, b; , GH H
a = 10 F .
Error in line no. 13
b = 20;
The variable temp is not accessible
if (a > b) PO
{
int temp; F
temp = a; . P F
a= b;
b = temp; P NA.
}
cout << a << b << temp;
getch ( );
}

P PM
F O PF.
F O P
F.

P PM F
G.

GL F ,
P A.
O NA.
Program- 4.19 GL P .
P PH.

115
// Program - 4.19 P
# include <iostream.h> x: while( ) F
void main ( ) 1. x
{
int flag = 1; a = 100;
while (flag)
{ 2. j j : if ( a > x ) { }
int x = 200;
F
if (a > x)
{ int j; 3. k k :else { } F
-------
}
else
{ int h;
------
}
}
}

4.7.2 (Function Scope)


P PM PO ,
P F F
-F MKA.
Program-4.19- flag P main()
. while(), if() A -F
.
PJ ,
FJ . P
O
.
4.7.3 (File Scope)
F
(P main() P ) PM P,
. PJ
GL MKA.
G c.
116
// Program - 4.20
// To demonstrate the scope of a variable
// declared at file level
# include <iostream.h>
# include <conio.h>
int i = 10;
void fun()
{
cout << i;
}

void main()
{
cout << i;
while (i)
{
......
......
}
}

4.7.4 P (Scope Operator)


P PJ A

O . W G .
num P main()-
// Program - 4.21 , O
# include <iostream.h>
# include <conio.h> PM
Qb? :: num
int num = 15; PH A
m ? ::
void main() bQ
{ P A.
clrscr(); F PM
int num = 5; P PH
num = num + ::num; P A.
cout << num << \t <<++::num;
getch(); P K
} G GO
P .
117
4.7.5
6- P M.

JC M
1. MO J W
.

() Procedural -fuction()
- , F FH
.
M:
void Procedural-function (void);
, void Procedural-function( );

() Manupulative-function()
- double , int F
FH .
M
(i) int Manipulative-function(double) ;
(ii) int Manipulative-function(double d);
(iii) Manipulative-function (double)

() fun-default()
- . Q
int F . float F.
F FH.
M:
void fun-default (float, int num = 10);

118
() return-reference-fun()
- int , int P
FH.
M:
int & char-reference-fun(int&, int&);
() multi-arguments()
- float .
pi-J F.
P . F FH.
M:
void multi-arguments (float const pi, float & a);

2. W O H :
. float average (a, b);
. float prd (int a, b);
. int default -arg (int a=2, int b);
. int fun (int, int, double = 3.14);
. void strings(char[ ]);
3. W P
main() P .
void line (int times, char ch)
{
cout << \n;
for (int i =1; i <=times; i++)
cout << ch;
cout << \n;
}

119
4. GL PO
PH:

# include <iostream.h> M:
float a, b ; void f1 (char); a,b -
int main ( ) ch -
{ -main()
char ch;
............
{ i - F
int i = 0;
...........
}
}
void f1(char g) x, y, g -
{ - f1()
short x, y ;
...............
}
5. W GO H :

) include <iostream.h> M:
P F
xyz (int m, int n) m P
{ PM .
int m = 10;
n = m * n;
return n;
}
void main( )
{
cout << xyz(9, 27);
}

120
. # include <iostream.h> M:
void xyz ( ); void PM
void main ( ) P return
{ int x = xyz ( ) ; } . ,
void xyz ( ) ,
{ return \0 ; } J F
.

. # include <iostream.h> M:
void counter (int & a) , P
{ ++ a;}
void main ( ) F
{counter (50); } M H
.

6. W GO Of ?

. # include <iostream.h> M : 101


int val = 10;
divide (int);
void main( )
{
int val = 5;
val = divide (::val/val);
cout << :: val<<val;
}
divide (int v)
{
return v/2;
}

121
. # include <iostream.h> M : 1
divide (int v) (i) divide(400) 40-
{ return v / 10;} M
void main( ) (ii) divide(400)==40 40==40
{ int val = -1; , G
val = divide (400) = = 40; K val- F
cout << \In Val. << val; 1 .
}

. # include <iostream.h> M : 10
int incre (int a)
{ return a++; }
void main( )
{ int x = 10;
x = incre (x);
cout << x;
}

. # include <iostream.h> M :
# include <iostream.h> *****
void line( ) ****
{ ***
static int v = 5; **
int x = v - -;
while (x)
{cout << * ; x --;
}
cout << \n;
}
void main( )
{ clrscr( );
for (int i = 1; i < = 5; i ++)
line( );
getch( );
}

122
. # include <iostream.h> M : Val : 50
first (int i)
{ return i++; }
second (int x)
{ return x ; }
void main ( )
{
int val = 50;
val = val * val/val
val = second (val);
val = first (val);
cout << \n Val: << val;
}

7. G :

() float cube (int, int, int) P .


cube() - F main() P
.

() unsigned long int factorial(int) P


. E F P :
5- =1x2x3x4x5. factorial (n)- F P
main( ) P .

() char odd-even-check(int) P .
, Q E ,
O M . P
A, K F OJ main() P
F .

() int prime(int) P .
, Q 1,
-1 M . P
A, K F OJ main() P
F .
123
5
M - E
(Structured Data Type - Arrays)

5.1.
C++ NJ E M M .
M F .
F , FJ
A E .
, W G :

1. O FJ K
P:

) FJ H, d
:
if (a > b)
max = a;
else
max = b;
) FJ H, d
:
if (a > b) && (a > c)
max = a;
else if (b > c)
max = b;
else
max = c;

124
) FJ H, d
:
if (a > b && a > c && a > d)
max = a;
else if (b > c && b > d)
max = b;
else if (c > d)
max = c;
else
max = d;
E F d F
Qb? N
HP, F O
F I.

, W F :

int a [4] = { 10, 40, 30, 20}; max = 0 ; i = 0;


for (; i < 4; i ++)
if a [i] > max
max = a [i] ;
cout << \n The largest number is << max;

F, O L
K bQA. , 10, 40, 30, 20 A O
40 OJA. if Am? F
O , M O
F E PM.
, E M PO F
. EJ PH .

125
EJ :

1) K: PH EJ
.
2) K: PH EJ, K
E .
5.2. K E (Single Dimensional Array)
O K E
. K E PMA:
int num _array [5];

EJ [ ] ;
O

5.1 K E

EJ E (positive)
.
int num_array[5];
PMH , num_array F
K E . EJ
EJ , EJ H (position)-
P . ,
num_array[3] = 99;
, EJ H 99- A.
num_array EJ , [3] W (Subscript)
(position) .
num_array- G 10 .
F int . ( int F 2
. 5 x 2 = 10 ).

126
G W :
num_array - EJ

0 1 2 3 W
99 F
( )

EJ W 0- M . num_array
E PJ W 0 ML 4 .
num_array[5] H, W
0 4 . E PMH K H :
i) int array [100];
ii) float exponents [10];
iii) char name [30];
iv) const i = 10;
double val [i];
v) int days [ ] = { 1, 2, 3, 4, 5, 7};
iv)- , val EJ E
i PL PH. (v)- ,
days EJ E 7
. A A? , {1, 2, 3, 4, 5,
6, 7} FH P bQA. 7
EJ bQA. , Program - 5.1
. EJ G
MA.
E :
cin >> number[4] - EJ
F A.
cout<< number[subscript] - subscript- PH
H FJ .
number[3] = number[2] - H
EJ H .
number[3] ++ - H
F I.
number [++a] = 10 - ++a - PH E H
10 F .

127
W G A Of :

// Program - 5.1
// arrays and basic manipulations on
// arrays
# include <iostream.h>
# include <conio.h>

int a[5],ctr = 0, sum;

void main()
{
for(;ctr<5;ctr++)
{
cout << \nEnter value ..;
cin >> a[ctr];
}
// generating sum of all the elements
// stored in array
for(ctr = 0, sum = 0; ctr<5;ctr++)
sum+= a[ctr];
clrscr();
// display values stored in array
for(ctr = 0; ctr < 5; ctr++)
cout <<\t << a[ctr];
cout << \nSum of the elements ... << sum;
getch();
}

128
// try out
// Program 5.2 Of:
abcdeffedcba
# include <iostream.h>

# include <conio.h>

char ch [ ] = {a, b, c, d, e, f};


void main ( )
{
for (int i = 0; i < 5; i++)
cout << ch[ i];

for (j=4; j>=0; j)


cout << ch [j];

getch();
}

// try out
// Program - 5.3
# include <iostream.h>
# include <conio.h>

void main ( )
{
int even [3] = {0, 2, 4}; int reverse [3];
for (int i=0, int j = 2; i<3; i++, j )
reverse [j] = even [i];
clrscr ( );
for (i=0; i<3, i++)
cout \t << even [i] << \t << reverse [i] << \n;
getch ( );
}

Of:
0 4

1 2

4 0

129
// try out
//Program - 5.4
# include <iostream.h>
# include <conio.h>
void main ( )
{
int x[5] = {1,2,3,4,5}, y [5] = {5,4,3,2,1},
result [5] = { 0,0,0,0,0 };
int i= 0;
while (i++ < 5)
result [i] = x [i] - y [i];
clrscr ( );
cout << \n The contents of the array are: \n;
i = 0;
do
{
cout << \t << x [i]
<< \t << y [i]
<< \t << result [i]<<\n;
i++;
} while (i<5);
getch ( );
}

Of:
The contents of the array are:

1 -1 0
2 4 -2
3 3 0
4 2 2

5 1 4

130
//Try out
//Program - 5.5
# include <iostream.h>
# include <conio.h>
void main()
{
int vector[] = {2, 4, 8, 10, 0};
for(int i=4; i>2; i)
vector [i]= vector[i-1];
clrscr();
cout << \n Elements of array before insertion \n;
for (i= 0; i<5; i++)
cout << vector[i];
vector [2] = 6;
cout << \n Elements after insertion \n;
for (i= 0; i<5; i++)
cout << vector[i];
getch();
}

Of:
Elements of array before insertion
248810
Elements after insertion
246810
EJ
K . K (sorting) A.
5.3 (Strings)
, F (literals) A.
K char E A. E
PM PM . ,
(i) char name [10];
(ii) char vowels [ ] = { a, e, i, o, u};
(iii) char rainbow[ ] = VIBGYOR;

131
char E (ii), (iii) AP
FHF PM. (ii)- char E
Q F \0(NULL)
P PH .

// Program - 5.6
// Reading values into an array of characters

# include <iostream.h>
# include <stdio.h>
# include <conio.h>
# include <string.h>
void main()
{
clrscr();
char name [30], address [30], pincode[7];
cout << \n Enter name ...;
cin >> name;
cout << \n Enter address...;
gets (address);
cout << \n Enter pincode ...;
cin.getlin e (pincode, 7,#);
clrscr();
cout << \n Hello << name;
cout << \n Your address is ... << address;
cout << \n Pincode ....;
cout.write(pincode, sizeof(pincode));
getch();
}

(Program - 5.6), name, address, pincode A


P F cin, gets(), getline() AP
A. cin, O F F (Carriage
Return - Enter Key) F .
,
cin >> name;

132
) k K V N Perumal , name- K
. K- O
M F .
) name- F K.V.N.Perumal k , name-
K.V.N.Perumal .
FH O
Q, stdio.h H gets()
P . k
istream- getline()- .
:
gets() : gets(char EJ ) gets (char *)
getline() : cin.getline(char *, O E, P);
F FJ N
:
1. cout <<name; - H PO F OJ
2. cout.write (pincode, 7); cout.write (pincode, sizeof(pincode));
write() Of ostream-
. M
, M O
(object/instance) . write() P
F ,
O E. :
//Program - 5.7
# include <iostream.h>
# include <conio.h>
void main()
{
clrscr();
char name[ ] = Tendulkar;
int i=1;
while (i<10)
{
cout.write (name, i);
cout << \n;
i++;
}
getch();
}

133
Of:
T
Te
Ten
Tend
Tendu
Tendul
Tendulk
Tendulka
Tendulkar
string.h H ,
O M 5.1- :

K FH
F
1 strlen() strlen(char*) F O
E . (.):
char name[ ] = Lasya;
strlen(name),5 M .
2 strcpy() strcpy(char *, F
char*) (.)
strcpy(name, petname)

3 strcmp() strcmp(char*, H,
char*) G Q,
0 M .
K
H1
M . H H -
1 M A. (-)
strcmp (Abc, Abc) 0
M . strcmp (Abc, abc)
-1 M.
strcmp ( abc, Abc) 1
M .
5.1.
134
K char E
. :
// Program - 5.8
# include <iostream.h>
# include <conio.h>
void main()
{
clrscr();
char name[] = Pascal, reverse[7];
int i= 0;
while (name[i] != \0)
i++;
reverse[i] = \0;
i;
int j = 0;
while (i>= 0)
reverse [i] = name [j++];
cout << \n The contents of the string are: << name;
cout << \n The contents of the reversed string ...
<< reverse;
getch();
}

W GL Of ?

//Program - 5.9
# include <iostream.h>
# include <conio.h>
# include <string.h>
main()
{
char word[] = test;
int i=0, k = 4, j = 0;
clrscr();
while (i < 4)
{
j = 0;
while (j<=i)
cout << word [j++];
cout << \n;
i++;
}
return 0;
}

135
5.4. K E (Two-Dimensional Array)
K E , K E
E. , marks[3] [4] E, 3
A, 4 P.

0,0 0,1 0,2 0,3


1,0 1,1 1,2 1,3
2,0 2,1 2,2 2,3

int marks[3] [4] = {90, 70, 80, 0, 75, 95, 65, 0, 80, 90, 90, 0};
K E,
0 1 2 3
0 90 70 80 0
1 75 95 65 0
2 80 90 90 0

.
P:

K EJ E, A/
EO .
marks E 12 (3x4)
.
E P W (subscripts)
0-M A. A P W 0
2 , 0 3 .
K EJ marks[ A] [ ]
PH. ,
marks [0] [3] = marks[0] [0] + marks[0] [1] + marks[0] [2];
, AJ F,
90, 70, 80 AP A.

136
K E PMA:
< M > < E> [< A>] [< >];
:
1. int a[3] [2] - a E 3 A, 2
.
2. cons int i = 5;
float num [i] [3]; - num K 5
A, 3 .
3. short fine [A] [E] - fine K 65
A, 69 .
P:
EJ K (A/)
:
1. int PL
2. K PL P
3. char PL
4. enum P
5.4.1. K EO G H
K EJ GF C
HO FA. O F
W P A.

1. A K: A - (row - major)
2. K: - (column - major)

137
:
int sales[2][4] EJ A:

A- K

0,0
0,1 1- A
0,2
0,3
1,0

1,1
2- A
1,2
1,3

- K

0,0 1-
1,0

0,1 2-
1,1
0,2 3-
1,2
0,3 4-
1,3

sales[1][0] H A-
KJ, - KJ Qb?

138
K EJ G
AA:
E x G .
, int sales[2][4] EJ
AA:
E = A x = 2 x 4 = 8

8 x 2 ( int F 2 )
= 16
float num [4][6] EJ ?
M :

4 x 6 x 4 = 96
W E :
int num[4][3] = {78, 7, 6, 4, 5, 8, 9, 7, 6, 1, 2, 3};

num 0 1 2

0 8 7 6

1 4 5 8

2 9 7 6

3 1 2 3

num J I FO F
:

139
M:
num[0][1] - (7)
num[1][1] - (5)
num[2][0] - (9)
num[3][1] - (2)

W PM EO, O E
bQ:
) int array[10] [12]; M : 120
) int x[ ] [2] = {0, 1, 1, 2, 2, 3} M : 6
(A-3, -2)
F E PM,
K PH I.

, E H
. EJ PH
. K PH J.
E P
A. , EJ , GF E
FJ K PA. H P
O P. EJ
PH, K H
A (P ).

140
// Program - 5.10
#include <iostream.h>
# include <conio.h>

void accept (int s[3][4], int &total)


{
int r = 0, c = 0;
for (; r < 3; r++)
{
cout << \n Month: << r+1;
for (c = 0; c < 4; c++)
{
cout << \n << c+1 << Quarter..;
cin >> s[r][c];
total += s[r][c];
}
}
}

void display (int d[3][4], int total)


{
int r, c;
clrscr ( );
cout << \nSales figures for 3 months & their
respective quarters..;
for (r = 0; r < 3; r++)
{
cout << \n Month ... << r+1;
for (c = 0; c < 4; c ++)
cout << \t << d[r][c];
}
cout << \n Total sales .. << total;
}
void main()
{
clrscr();
int sales[3][4], t = 0;
accept(sales,t);
display(sales,t);
getch();
}

141
W G :
// Program - 5.11
# include <iostream.h>
# include <conio.h>
void accept(int a)
{
cout << \n Enter a number ..;
cin >> a;
}

void display(int a)
{
cout << \n << a;
}

void main()
{
int num [2][2] ={{0,0},{0,0}}, r = 0, c = 0;
clrscr ( );
for (; r < 2; r++)
for (; c < 2; c++)
accept(num[r][c]);
clrscr();
for (r = 0; r < 2; r++ )
for (c = 0; c < 2; c++)
display (num[r][c]);
getch();
}

accept() P k 1, 2, 3, 4 A F
. M:
0
0
0
0
A. num EJ O 1, 2, 3, 4 A F
M E b?
, void accept() P
QQ H A. , F
. P
F .
142
P:
EJ EJ K PA.
, GL accept() P P
. 1, 2, 3, 4 k , Of,
1
2
3
4
.
5.4.2. E (Matrix)
E m x n m AO n
O E M . E
K E .
Program-5.12 G E F
k E O G (equality)
KF M A.
5.5. O E
O E K char E . E
H (A E) O
E P. (
E) O c P. :
char day-names [7] [10] = {Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday};
EJ O F 5.1-
.

143
//Program - 5.12
# include <iostream.h>
# include <conio.h>

void accept(int mat[3][3])


{
clrscr();
int r = 0, c = 0;
for (; r < 3; r++)
{
cout << \n Enter elements for row.. << r;
for (c=0; c < 3; c++)
cin >> mat[r][c];
}
}

void main()
{
int m1[3][3], m2[3][3];
accept (m1);
accept (m2);
int i=0, j = 0, flag = 1;
for (; i < 3; i++)
{
for (; j < 3; j ++)
if (m1[i][j] != m2[i][j])
{
flag = 0;
break;
}

if (flag == 0)
break;
}
if (flag)
cout << \n The matrices are equal ...;
else
cout << \n The matrices are not equal..;
getch();
}

144
0 1 2 3 4 5 6 7 8 9
0 S u n d a y \0 day-names [0]
1 M o n d a y \0 day-names [1]
2 T u e s d a y \0 day-names [2]
3 W e d n e s d a y \0 day-names [3]
4 T h u r s d a y \0 day-names [4]
5 F r i d a y \0 day-names [5]
6 S a t u r d a y \0 day-names [6]

5.1 GF EJ

EJ QQ day-names[0]
(A ) PH . F
PH EJ Q
day-names[0][5] (A/
) PH .
F FJ P (null
character - \0) I (optional). M
C++ GH .

JC M
1. W H ?
) int a[5.5];
- EJ K .

) float f[3] = {1.0, 2.0};


- H . EJ PH
EM F
. Q, eF
O 0 F M.
) float num[A];

145
- EJ K O PM
. F, A P F
A. ,
float num[A] ,
const A=10; float num[A];
P .
) char a[3] [ ] = { one, two, three};
- F PM K
EJ K MM.
K .
,
char a[ ] [6] = {one, two, three};
P .
) char ch[1] = s;
-char E PM Q,
char ch[2] = s;
PM. char E PM
Q,
char ch[1] = {s};
PM .
) char test [4];
test = {abc};
- EJ FH .
PM FHF,
char test[4] = abc;
PH. ,
char test [4];
strcpy(test, abc);
F, PJ .

146
) int num[ ] = {1,2,3}, num2[3];
num2 = num;
-E PM FH NJ.
int num1[5], num2[10], num3[15];
PM.
FH JH QQ
.
) int num[3];
cout << num;
cin >> num;
- E k/ Of
FJ.
.
cout << num [1];
cin >> num[2];
.
) int roaster = { 1,2,3,4};
- roaster P F .
,
int roaster = 10; ,
int roaster [ ] = {1,2,3,4} ;
.
2. W FHH EJ
?
) int rate[ ] = {30, 40, 50};
) char ch[b] = {bbbbb\0}; -b O PA.
ch[0] = C; ch[4] = T; ch[3] = A;
) char product-list [ ] [5] = { Nuts, Bolts, Screw};

M:

) rate [0] = 30, rate[1] =40, rate[2] = 50

147
) ch[0] = C, ch[1] = , ch[2]= , ch[3] = A,
ch[4] = T, ch[5] = \0
) product-list[0] = Nuts\0, product-list[1] = Bolts\0,
product-list[2] = Screw\0.
3. W GO Of ?
) # include <iostream.h> M: END
void main ( )
{
char ch [ ] = END;
cout << ch;
}

) # include <iostream.h>
void main ( )
{
int a [ ] = {1,2,3,4,5};
for (int i = 0, i < 4, i++)
a[i+1] = a[i];
for (i= 0; i<5; i++)
cout << \n << a[i];
}

M:
EJ :
a[0] = 1, a[1] = 2, a[2] = 3, a[3] = 4, a[4] = 5
for() ,
i = 0 : a[1] = a[0]
i = 1 : a[2] = a[1]
i = 2 : a[3] = a[2]
i = 3 : a[4] = a[3]

148
, Of,
1
1
1
1
1
.

) # include <iostream.h>
# include <conio.h>
void main( )
{
char name[ ] = Jerry; int k=5;
for (int i = 0; i < 3; i ++, k )
name [k] = name[i];
cout << name;
getch( );
}

M:
for() ,
i = 0 : k = 5, name[5] = name[0];
i = 1 : k = 4, name[4] = name[1];
i = 2 : k = 3, name[3] = name[2];
, Of, JerreJ A.
4. G :
1) int - array int E 10, 20, 30, 40, 50 A
F . E
O F M .

149
2) 10 F F int E
PM. EJ KI
F . F H KJ
FJ.
3) word PJ (char E) KI
. while() switch()
A F K J
(vowels) A M OJ. ,
char word[ ] = The Vowel count AEIOU aeiou;
Vowel count is 14
4) MATRIX[3][3] E .
M O F P
OJ.
5) matrixA [4][4], matrixB [4][4] A E
F k . E
sum-matrix[4][4] EJ
F, OJ.
:

matrixA matrixB sum-matrix

1234 9876 10 10 10 10
5678 5432 10 10 10 10
9123 1987 10 10 10 10
4567 6543 10 10 10 10

150
6

(Classes and Objects)

6.1 -
C++ NJ I A .
C++ N A vv N L
C (C with Classes)
A , M A FA.
M , F
M F N
FA.
F N A.
class student
{
char name[30];
int rollno, marks1, marks2, total_marks;
}
M PM rollno, marks1, marks2,
total_marks A P student F
OA.
, student MK .
N (methods) . ,
O e G ( F
k , W )
A.
P,

A.
6.2
M F :
1) PM
2) M
151
// Program - 6.1
# include <iostream.h>
# include <conio.h>
class student
{
private :
char name[30];
int rollno, marks1, marks2 ,total_marks;
protected:
void accept()
{
cout<<\n Enter data name, roll no, marks 1 and
marks 2.. ;
cin>>name>>rollno>>marks1>>marks2;
}
void compute()
{
total_marks = marks1+ marks2;
}
void display()
{
cout<<\n Name <<name;
cout<<\n Roll no <<rollno;
cout<<\n Marks 1.. <<marks1;
cout<<\n Marks 2.. <<marks2;
cout<<\n Total Marks.. << total_marks;
}
public:
student()
{
name[0]=\0';
rollno=marks1=marks2=total_marks=0;
cout<<\n Constructor executed ... ;
}
void execute()
{
accept();
compute();
display();
}
};
void main()
{
clrscr();
student stud;
stud.execute();
}

152
PMH :


class class-name class student
{ { private;
private: char name [10];
variable declaration int rollno, marks1, marks2, total_marks;
function declaration
protected:
protected: void accept( );
variable decl. void compute( );
function decl. void display( );

public: public:
variable decl. student( );
function decl. void execute( );
}; };

 class C ,
class A.
 M F O P
O A.
 M F P O
PM .
 M F A H
(O C) : private, public,
protected.
 private A PH I.
M A PHM Q
M private
F.
 private PM
.
 protected PM
, M J
M .
 public PM
O .
153
6.3 (Data Abstraction)

F (Encapsulation)
A.
private
OJL .
(Data Hiding) A. H O (objects),
(members) J
MF (Data Abstraction) A.
FA
.
GF (Object Oriented
Programming-OOP) .

private M
(friend functions) C C
.
protected M
O .
public M
IP O O
.
6.4
.
(Data Members). (member functions).
M
P PA.
M P E GA
PA. N (methods) ,
(attributes) .
, Program-6.1- student
-
6.1- . A (constructors), NH
(destructors) Q C
. A/NH P 8- MK
.
154
student M P student
(tag) .
name, rollno,
marks1,marks2, total_marks
accept()
compute() N
display()
execute()
student()
stud student M (instance)/
(object) / P (variable)
6.1 Program- 6.1 student

6.5
student stud;
PM . P stud
student M (instance) (object)
.
H, MF P
PM . stud student P. student
class M. C++ NJ P
(objects) PA. MO
P PM M PM
A. A O P
, PO PH .

6.1
155
6.6
M O P
. , student M execute() P
:


O P
O

M private M
, C C
.
student M name, marks1,
marks2, total_marks A , accept(), display(), compute()
A .
O PM , private protected
,
.
public PM
M .
stud.execute();
. , execute()
public PM . ,
O PM stud
. , stud.accept(), stud.compute(), stud.display(),
stud.marks1- , G H
not accessible H F .
E M Program- 6.2
. F , P,
A P .
sum P public A , s
A.
156
//Program - 6.2
# include <iostream.h>
# include <conio.h>

class add
{
private:
int a,b;
public:
int sum;

void getdata()
{
a=5;
b=10;
sum = a+b;
}
};

void main()
{
add s;
s.getdata();
cout<<s.sum;
}

6.7 M

class add
{
int a,b;
public:
add()
{
a = 0; N-1
b = 0;
}
void display();
};
void add::display()
{
int sum;
sum = a+b; N-2
cout<<sum;
}
157
N 1-, add() , add
PM, .
N 2-, display() , add
PM, O
.
M
. inline
A.
O ,
type class_name: : function_name();
.
:

function_name()- class_name:: (add::)


P , ,
class_name- K A. P H
PH A
PA.
QC H
. G F F
A.

F . P
P.

158
 M private
. H .
 P
. O P J.
( O H
A).
 , C++
. H .
 FH F, M
.
 static .
6.8 G W
H F
GF
A.
P F ,

QQ G F. P
G QQ
A.
. , O P
F .
W PM :
class product
{
int code, quantity;
float price;
public:
void assign_data();
void display();
};
void main()
{
product p1, p2;
}
159
F assign_data(), display() A
GF M FJ A. p1, p2
A M FJ
.
p1, p2 A O G W :

G W
p1 code, quantity, price 8

p2 code, quantity, price 8

6.2 G W

M , Program- 6.3- M
, H
.
6.9 static
M static F O
. static -
 M ,
0 F . H
FHF.

 GF, P
( F F). M
H GF
AA.

 A
. , G
.
static P G
(Program-6.4):

160
// Program - 6.3
#include<iostream.h>
#include<conio.h>
class product
{
int code, quantity;
float price;

public:
void assign_data( int c, int q, float p)
{
code = c;
quantity = q;
price = p;
}

void display()
{
cout<<\n Code : <<code;
cout<<\n Quantity :<<quantity;
cout<<\n Price : << price;
}
};

void main()
{
product p;
p.assign_data( 101, 200, 12.5);
p.display();
}

161
// Program - 6.4
// To demonstrate the use of static member variables

#include<iostream.h>
#include<conio.h>
class simple_static
{
int a,b,sum;
static int count;
public:
void accept()
{
cout<<\n Enter values.. ;
cin>>a>>b;
sum = a+b;
count++;
}
void display()
{
cout<<\n The sum of two numbers <<sum;
cout<<\n This is addition <<count;
}
};
static_simple.count = 0;
void main()
{
simple_static p1,p2,p3;
p1.accept();
p1.display();
p2.accept();
p2.display();
p3.accept();
p3.display();
}

162
Of:
Enter values 10 20
The sum of two numbers 30
This is addition 1

Enter values 5 7
The sum of two numbers12
This is addition 2

Enter values.. 9 8
The sum of two numbers 17
This is addition 3
static P count 0
FHA. O
A count- F IA.
accept() count- F
I 3 F A.
count- A,
count- F 3 A. , 6.2- M.

6.2 static P - count

static PJ F O
A.

163
6.10 O E
W , G
W :

class product
{
code
int code,quantity;
quantity p[0]
float price;
price
public :
void assign_Data();
code
void display();
quantity p[1]
} p[3];
price
void main()
{
code
p[0].assign_Data();
quantity p[2]
p[0].display();
price
}

JC M
I. H P F:
class x
{
public:
int a,b;
void init()
{
a =b = 0;
}
int sum();
int square();
};
int sum()
{
return a+b;
}
164
int square()
{
return sum() * sum()
}

M:
int x : : sum() int x : : square()

II.
#include<iostream.h>
class simple
{
int num1, num2 , sum = 0;
protected:
accept()
{
cin>>num1>>num2;
}
public:
display()
{
sum = num1 + num2;
}
};
void main()
{ simple s;
s.num1=s.num2=0;
s.accept();
display();
}

165
M:
1) sum PJ PMH F
.
2) num1, num2 A P private
main()- L .
3) s.accept() . protected
.
4) display() P O
.
III.
#include<iostream.h>
#include<conio.h>
class item
{
private:
int code,quantity;
float price;
void getdata()
{
cout<<\n Enter code, quantity, price ;
cin>>code>>quantity>>price;
}
public:
float tax = 0;
void putdata()
{
cout<<\n Code : <<code;
cout<<\n Quantity : <<quantity;
cout<<\n Price : <<price;
if( quantity >100 )
tax = 2500;
else
tax =1000;

166
cout<< \n Tax :<<tax;
}
};

void main()
{ item i; }
GL J W G
:
i- private public i
G A
W

IV.
1) W employee
:
employee M private :
empno -
ename - 20
basic - float
netpay, hra, da - float
calculate()- basic+hra+da A float
F FH .
employee M public :
havedata() - empno, ename, basic, hra, da - A F
k , calculate() P
netpay- A .
dispdata() - FJ
.
2) W math
:
private :
num1, num2, result - float
init() - num1, num2, result AP 0
FH.

167
protected :
add() - num1, num2 ,
result- .
prod() - num1, num2 A,
result- .
public :
getdata() - num1, num2 A F
menu() - 1. Add...
2. Prod...
(menu) .
1 add() P, 2-
prod() P F, result- FJ
.

168
7

(Polymorphism)

7.1
polymorphism , (poly-many, morph-shapes)
A. IN A. C++
NJ, , EI (function overloading),
P EI (operator overloading) AP G
A. J EI (overloading) ,
PA.
, EI Q
P PA. G
K EI C++ NJ O
.
7.2 EI (Function Overloading)

F M O
P F E
I A.

G W MA
:
area_circle() // F E
area_triangle() // F E
area_rectangle() // F E
O P
, K ( )
.
float area(float radius);
float area(float half, float base, float height);
float area(float length, float breadth);

169
Program-7.1- . O
F A area() P
F :
// Program - 7.1
// to demonstrate the polymorphism - function overloading
#include<iostream.h>
#include<conio.h>
float area ( float radius )
{ cout << \nCircle ;
return ( 22/7 * radius * radius );
}
float area (float half, float base, float height)
{ cout << \nTriangle ..;
return (half* base*height);
}

float area ( float length, float breadth )


{ cout << \nRectangle ;
return ( length *breadth );
}
void main()
{
clrscr();
float r,b,h;
int choice = 0;
do
{
clrscr();
cout << \n Area Menu ;
cout << \n 1. Circle ... ;
cout << \n 2. Traingle ...;
cout << \n 3. Rectangle ... ;
cout <<\n 4. Exit ... ;
cin>> choice;
switch(choice)
{
case 1 :
cout << \n Enter radius ... ;
cin>>r;
cout<<\n The area of circle is ...
<< area(r);
getch();
break;
case 2:
cout<< \n Enter base, height ... ;
cin>>b>>h;
cout<<\n The area of a triangle is...
<< area (0.5, b, h);
getch();
break;
case 3:
cout<< \n Enter length, breadth.. ;
cin>>h>>b;
cout<<\n The area of a rectangle is ...
<< area(h,b);
getch();
break;
}
}while (choice <=3);
}

170
O Qb? :
float area(float radius);
float area(float half, float base, flaot height);
float area(float length, float breadth);
area() O
GAl? , P
O EJ A.
M , F ,
F .
float
. F.
M .
O E . O
E H P M P
.
W O EI
O H P ?
?

: H :
void fun(int x); void fun(int x);
void fun(char ch); void fun(int y);
void fun(int y); E
void fun(double d); J
.
H.

EIH A?

GH, IC (Best Match)


HA. F G
H-

 I K
.

171
 I K Q,
P .
,
,
.
, GL (Program-7.1) float area (float
radius) . ,
area(r) F r float
. r int Q,
F, int PL/P char float double
F . F
area(r) area(float radius)
.
GH
. GH J
. :
 char M int/float/double .

 int M char/float/double .

 float M int/double/char .

 double M int float .


Program-7.1 GL area() P
W Q M ?

Of
area (5.0)

area (0.5, 4.0, 6.0)


area(3.0, 4.5)

172
EIH MF
1) EI O E
J, P O .
2) EI FH M
, .
3) EI O Q ,
O L F C++ GH
F .
4) H
.
PM, W HQ
.

void fun ( char a, int times)


{
for (int i=1; i<=times;i++)
cout<<a;
}
void fun( char a= *, int times )
{
for(int i=1;i<=times;i++)
cout<<a;
}
void fun( int times)
{
for(int i=1; i<=times ;i++)
cout<<@;
}
void main()
{
fun ( +, 60);
fun(60);
}

173
G G H
:
 conflict between fun(char a, int times) and fun(char a = *, int times)

 conflict between fun(char a = *, int times) and fun (int times)


fun (+, 60) fun(char a, int times)
fun(char a = *, int times) A .
O
P EI . ,
, O E M
J .
7.3 P EI (Operator Overloading)
P EI , +, ++, -, --, +=, -=, *, <, >
C++ P
PA.
sum = num1 + num 2;
, (int/float/double) , M sum
PJ E F .
, W :
name = first_name + last_name;
F name, first_name, last_name A (char
E) . C++ NJ + P
P ?
+ P GH H .
, strcat() P
.
+ P I O
? P EI + PJ
c .

174
W :
// Program -7.2 OPERATOR OVERLOADING
# include <iostream.h>
# include <conio.h>
# include <string.h>

class strings
{
void main()
char s[10];
{
public :
clrscr();
strings()
strings s1(test),s2( run\0);
{
char *concatstr ;
s[0] = \0;
concatstr = s1 + s2;
}
cout <<\nConcatenated string ...
<< concatstr;
strings(char *c)
getch();
{ }
strcpy(s,c);
}

char * operator+(strings x1)


{
char *temp;
strcpy(temp,s);
strcat(temp,x1.s);
return temp;
}
};

concatstr = s1 + s2;
P.
char * operator + (strings x1)
, + P E
. x1
M A. M:
char * operator+(strings x1) x1
{ strings
char *temp;
strcpy(temp,s);
M .
strcat(temp,x1.s);
return temp; s1, s2 A
} strings
. M
concatstr = s1 + s2; +
P .

175
7.1, P P F
H MA.

7.1 P F
P EI A:
 +, *, -, ++, --, >, <, += C++ NJ
P F
A.
 M EI
P .
 P
. (friend
functions) . (
L ).
 P F
PJ . ,
GL + P
P . GL +
P
E . GH,
PJ
A. ,
cout << 5+10;
15 FJ . (+-
).
176
concatstr = s1 + s2;

, char * operator+(strings x1)


P . , F +
PJ H
s1, s2 A strings M
.
P EIH :
 F M
A M EI
PJ F .
 operator <symbol>() P M public
FJ PM .
 GP
J P P
.
M PO O
W MA.
M O F F (negative value)
P - P Program - 7.3
MA.

// Program - 7.3
# include <iostream.h>
void operator-()
# include <conio.h>
{
i = -i;
class negative
}
{
};
int i;
public :
void main()
void accept()
{
{
clrscr();
cout << \nEnter a number ...;
negative n1,n2;
cin >> i;
n2.accept();
}
-n2;
void display()
n2.display();
{
getch();
cout << \nNumber ...<<i;
}
}

177
sum = - num1;
F, P - P ,
M void operator-() F
(Negative) A.
W G . M M :
// Program 7.4
# include <iostream.h>
# include <conio.h>

class distance
{
int feet,inches;
public :
void distance_assign(int f, int i)
{
feet = f;
inches = i;
}

void display()
{
cout << \nFeet : << feet
<< \tInches : << inches;
}

distance operator+(distance d2)


{
distance d3;
d3.feet = feet + d2.feet;
d3.inches = (inches + d2.inches) % 12;
d3.feet += (inches + d2.inches)/12;
return d3;
}
};

void main()
{
clrscr();
distance dist_1,dist_2;
dist_1.distance_assign(12,11)
dist_2.distance_assign(24,1);
distance dist_3 = dist_1 + dist_2;
dist_1.display();
dist_2.display();
dist_3.display();
getch();
}

178
1. EI P .
2. EI P F
.
3. EI PJ
HO ?
4. EI P P
F .
EI +=, -= A Program-7.5
MA.
//Program-7.5
// operator overloading

# include <iostream.h>
# include <conio.h>
# include <string.h>

class library_book
{
char name[25];
int code,stock;

public :

void book_assign(char n[15],int c,int s)


{
strcpy(name,n);
code = c;
stock = s;
}

void display()
{
cout << \n Book details ....;
cout << \n 1. Name ..... << name;
cout << \n 2. Code ..... << code;
cout << \n 3. Stock ..... << stock;
}

void operator +=(int x)


{
stock += x;
}

void operator -=(int x)


{
stock -= x;
}
};

179
class library_cdrom
{
char name[25];
int code,stock;

public :

void cdrom_assign(char n[15],int c,int s)


{
strcpy(name,n);
code = c;
stock = s;
}

void display()
{
cout << \n CD ROM details ....;
cout << \n 1. Name ..... << name;
cout << \n 2. Code ..... << code;
cout << \n 3. Stock ..... << stock;
}

void operator +=(int x)


{
stock += x;
}

void operator -=(int x)


{
stock -= x;
}
};

void main()
{
library_book book;
library_cdrom cdrom;

book.book_assign(Half Blood Prince,101,55);


cdrom.cdrom_assign(Know your Basics,201,50);

char choice,borrow;

do
{
cout << \nBook,cdrom,exit<b/c/e> ...;
cin >> choice;
if (choice != e)
{
cout << \nBorrow/Return <b/r> ...;
cin >> borrow;
}

180
switch (choice)
{
case b:
switch (borrow)
{
case b : book += 1;break;
case r : book -= 1;break;
}
book.display();
break;
case c :
switch (borrow)
{
case b : cdrom += 1;break;
case r : cdrom -= 1;break;
}
cdrom.display();
break;

case e : cout << \nTerminating ..;


break;
}
} while (choice != e);
getch();
}

F , +=, -= A P
F EJ I O I,
Qb?
book += 1;
book -= 1;
cdrom += 1;
cdrom -= 1;

P F
P EI A.

181
P E I MF:
PO EI C
. :
 P EI
. F P .
 EI P A H
M
.
 PJ P
. , PJ
. P
E .
 EI P P H
P
A.
 PO (Binary Operators) EI,
PJ ,
M
.
 P
EI, O
.

JC M
I. W E G EI
G :
) O K P

) O K P

M: max(int, int), max(int, int, int)

182
II. W E EI F
:
) float PJ F I

) char PJ F I

M: - float incr(float), char incr(char)


III. EI W E G
C++ NJ G :
) x, y A int Q, xy F P.

) x, y A float Q, xy F P.

M: -
int power(int, int), float power (float, float)
IV. P EIH ?

V. EI P F H
G L.

VI. EI P L.

VII. complex_numbers M
G . F,
F
. W G , complex_numbers
F c1, c2
main() P F .
class complex_numbers
{
float x;
float y;
public :
void assign_data(float real, float imaginary);
void display_Data();
complex_numbers operator +(complex_numbers n1);
}

183
8
A NH
(Constructors and Destructors)

8.1
M (instance) ,
A (constructor) C A. A
(class object) AA -
, O F A.
O NH (destructor)
C A. A, NH A
M .
F FH F.
M .
8.2 A (Constructors)

// Program - 8.1
// to determine constructors and destructors
#include<iostream.h>
#include<conio.h>
class simple
{
private:
int a,b;
public:
simple()
{
a= 0 ;
b= 0;
cout<< \n Constructor of class-simple ;
}
~simple()
{
cout<<\n Destructor of class simple .. ;
}
void getdata()
{
cout<<\n Enter values for a and b... ;
cin>>a>>b;
}
void putdata()
{
cout<<\nThe two integers .. <<a<<\t<< b;
cout<<\n The sum of the variables .. << a+b;
}
};
void main()
{
simple s;
s.getdata();
s.putdata();
}

184
G J s
simple() A, A.
s- , GL
~simple() NH A.

GL Of :
Constructor of class - simple ..
Enter values for a & b 5 6
The two integers.. 5 6
The sum of the variables.. 11
Destructor of class - simple

8.3 AJ

1) O O F
A.

2) GF A.

8.4 AJ EI (Constructor Overloading)


A M C ,
EI (Function Overloading) A .
Program- 8.2 G A EI MA.

add() A A (non-parameter-
ized constructor) . A (default constructor)
A. , A GH
A (compiler generated constructors) PH.
, A E
P A A A.
PM,
A A.

185
// Program - 8.2
// To demonstrate constructor overloading
# include<iostream.h>
#include<conio.h>
class add
{
int num1, num2, sum;
public:
add()
{
cout<<\n Constructor without parameters.. ;
num1= 0;
num2= 0;
sum = 0;
}
add ( int s1, int s2 )
{
cout<<\n Parameterized constructor... ;
num1= s1;
num2=s2;
sum=NULL;
}
add (add &a)
{
cout<<\n Copy Constructor ... ;
num1 = a.num1;
num2 = a.num2;
sum = NULL;
}
void getdata()
{
cout<<Enter data ... ;
cin>>num1>>num2;
}
void addition()
{
sum=num1+num2;
}
void putdata()
{
cout<<\n The numbers are..;
cout<<num1<<\t<<num2;
cout<<\n The sum of the numbers are.. << sum;
}
};
void main()
{
add a, b (10, 20) , c(b);
a.getdata();
a.addition();
b.addition();
c.addition();
cout<<\n Object a : ;
a.putdata();
cout<<\n Object b : ;
b.putdata();
cout<<\n Object c : ;
c.putdata();
}
186
Of:
Constructor without parameters.
Parameterized Constructor...
Copy Constructors

Enter data .. 5 6
Object a:
The numbers are 5 6
The sum of the numbers are .. 11
Object b:
The numbers are 10 20
The sum of the numbers are 30
Object c:
The numbers are 10 20
The sum of the numbers are .. 30
A A
add(int s1, int s2)
A. A , int PL
P PM .
P: char, float, double .
F int M
.
: add a(10, 60) / add a(ivar, ivar)
add (add &a) A, A (copy constructor) A.
A W O :
1) P
H.
: void add : : outdata (add x);
2) FH
.
: add getdata();
3) P A H
.
: add a; b(a);
W G (Program - 8.3) A
A MA:

187
// Program 8.3
// To demonstrate constructor overloading

# include<iostream.h>
#include<conio.h>
class add
{
int num1, num2, sum;
public:
add()
{
cout<<\n Constructor without parameters.. ;
num 1 = 0;
num 2 = 0;
sum = 0;
}

add ( int s1, int s2 )


{
cout<<\n Parameterized constructor... ;
num1= s1;
num2=s2;
sum=NULL;
}

add (add &a)


{
cout<<\n Copy Constructor ... ;
num1= a.num1;
num2=a.num2;
sum = NULL;
}

void getdata()
{
cout<<Enter data ... ;
cin>>num1>>num2;
}
void addition(add b)
{
sum=num1+ num2 +b.num1 + b.num2;
}

add addition()
{
add a(5,6);
sum = num1 + num2 +a.num1 +a.num2;
}

void putdata()
{
cout<<\n The numbers are..;
cout<<num1<<\t<<num2;
cout<<\n The sum of the numbers are.. << sum;
}
};

188
void main()
{
clrscr();
add a, b (10, 20) , c(b);
a.getdata();
a.addition(b);
b = c.addition();
c.addition();
cout<<\n Object a : ;
a.putdata();
cout<<\n Object b : ;
b.putdata();
cout<<\n Object c.. ;
c.putdata();
}

ouput of the above program


Constructor without parameters..
Parameterized constructor...
Copy Constructor ... Enter data ... 2 3

Copy Constructor ...


Parameterized constructor...
Parameterized constructor...
Object a :
The numbers are..2 3
The sum of the numbers are.. 35
Object b :
The numbers are..0 1494
The sum of the numbers are.. 0
Object c..
The numbers are..10 20
The sum of the numbers are.. 41

A A
Qb?
Program - 8.3 GL W A
A:

189
add c(b); // b H
A.
addition()
a.addition(b); // b
P HA.
b = c.addition(); // addition()
FHA.

addition() P E
I (overloaded). GL F PM
EI P.

8.5 A MF:

1) AJ M .

2) A, O

3) A , EI .

4) A , GH
A A .

5) , A
. F.

8.6 NH (Destructors)
NH , , A
G F MM
. M .
, ~ P K .

190
:
class simple
{
...............
...............
public :
~simple()
{
................
}
}

8.7 NH MF:

1) NHJ , ~
P M
.

2) NH, .

3) NH, F FH .

4) NHJ EI . ,
M NH .

5) , NH ,
GH NH A
.

6) GL O
, NH
. F.

191
JC M:

I W G :
M A NH
1.
(scope) PM ?
2. EI F?
3. A?
....
4. ?

II W GF H ?

class simple class simple class simple


{ { {
private: private: private:
int x; int x; int x;
simple() public: public:
{ simple(int y) simple(int y)
x = 5; { {
} x = y; x = y;
}; } }
};
void main() simple(int z=5)
{ {
simple s; x = z;
} }
};
void main()
{
simple s(6);
}

192
9
K
(Inheritance)

9.1
G NJ F
K (Interitance) . K
O J F
. , (base classes)
, M (derived classes)
A. M , M
K MA. IP, M
M N
FK . K
J I P .
K H K N
A. , (Parent)
MI K A.

9.1 K
193
9.2 KF
K W OA:
1) G PJ (Reusability of Code);
GF
A. P
F, A
F . G
A.
2) G P A (Code Sharing);
M N(methods) M
A .
3) F (Consistency of Interface);
K N
N FK
A. 1- , M
, N, M, , A A
M
. M
.
9.3 M
ML H MJ
A. M
M K A.
M , W
MF H :
) class C .
) class , M
M .
) O (:) .
) private, public protected A
A MA PH
.
) M PH .
) M K
, N .
194
// Program - 9.1

#include< iostream.h>
#include<conio.h>
class add
{
int sum;
protected:
int num1, num2;
public:
add()
{
num1 = num2 = sum = 0;
cout<<\n Add constructor .. ;
}

accept()
{
cout<<\n Enter two numbers .. ;
cin>>num1>>num2;
}

plus()
{
sum = num1 + num2;
cout<<\n The sum of two numbers is .. << sum;
}
};

class subtract :public add


{
int sub;
public:
subtract()
{
sub = 0;
cout<<\n Subtract constructor .. ;
}
minus()
{
add::accept();
sub= num1-num2;
cout<<\n The difference of two numbers are ...
<< sub;
}
};

195
void main()
{
subtract s;
int choice = 0;
cout<<\n Enter your choice ;
cout<<\n1. Add..\n2. Subtract ..;
cin>>choice;
switch(choice)
{
case 1:
s.accept();
s.plus();
break;
case 2:
s.minus();
break;
}
}
Program -9.1- add . subtract
M . M
:
class < > : < A> < M >
{
M M ;
M M ;
}
Program- 9.1- substract M
:


G/ A
M
M
M
M
P

196
9.4 G / A H
(Visibility Mode / Accessibility Specifier)
KF PH Q, M
M M
, F .
, A (accessibility) A. private, public, protected
A H . A
H G (visibility mode) .
Q G private . M
M, O
A 9.1 MA.

M
M
private protected public

private K
F.

G.

protected private A protected protected


A A

N
A. N A.
A.

public private protected public


A A A


N N
A. A.
A.
9.1 M M O
A

197
private A M
, M public protected ,
M M private GA.
protected A M
, M protected public ,
M M protected GA.
public A M
, M protected , M
M protected , public public
GA.
public, protected, private
M M private
M M K
F. M M
G. .

Program -9.1- add, subtract A PM


:

class add
{
private:
int sum;
protected :
int num1, num2;
public:
add();
accept();
plus();
};
class subtract : private add
{
int sub;
public:
subtract();
minus();
};

198
subtract N ,
:
int num1 & num2 - subtract- private
accept(), plus() - subtract- private

O A 9.2-
.
M A (constructors), M
M N F. , M
M (instance) L
A.

199
class subtract II III

private: private: private:

sub sub sub


num1 protected: protected:
num2 num1. num2 num1. num2
accept() accept(); public:
plus() plus(); accept();
public: public: plus();
subtract() subtract() subtract()
minus(); minus() minus();
private mode protected mode public mode
of inheritance of inheritance of inheritance

9.2 O A

Program - 91- PM .
GL J W G :

M N/

add

subtract

9.3 O /

A:--------------------, ----------------------.

200
9.5 KF
M F
M . KF : N
K, N K, G K, K,
K.
1) N K (Single Inheritance)
M
N K .

Base
class - Employee
- E

M
Derived Class -
Manager
-

2) N K (Multiple Inheritance)
OL
M N K
.


Base Class:
-
Base class:
Office
K
Address

M
Derived Class - :
Manager

201
3) G K (Multilevel Inheritance)
M
M G
K .

M :

M :

Program - 9.2 GL Of ?

202
// Program - 9.2
#include<iostream.h>
#include<conio.h>
class base
{
public:
base()
{
cout<<\nConstructor of base class... ;
}
~base()
{
cout<<\nDestructor of base class.... ;
}
};
class derived:public base
{
public :
derived()
{
cout << \nConstructor of derived ...;
}
~derived()
{
cout << \nDestructor of derived ...;
}
};

class derived2:public base


{
public :
derived()
{
cout << \nConstructor of derived2 ...;
}
~derived()
{
cout << \nDestructor of derived2 ...;
}
};

void main()
{
derived2 x;
}

203
Of:
Constructor of base class
Constructor of derived .
Constructor of derived2
Destructor of derived2
Destructor of derived
Destructor of base class ..

 A, K O KJ
A. , M
A F M J.
NH H KJ .

H M
F
(Abstract Classes) A. , F O
.
JC M
1) W ,
-4,5,6 A G :
class node
{
int x;
void init();
public:
void read();
protected:
void get();
};
class type : public node
{
int a;
public:
void func1();
protected:
int b;
void getb();
}
204
class statement :private type
{
int p;
public:
void func2();
protected:
void func3();
};

type M O A
private protected public

type M
N

type M


4 type

statement O A
M
private protected public

statement
M N

statement
M

5 statement

type

statement

-6
205
2) W GL H , :

#include<iostream.h>
class A
{
private :
int a1;
public:
int a2;
protected:
int a3;
};
class B : public A
{
public:
void func()
{
int b1, b2 , b3;
b1 = a1;
b2 = a2;
b3 = a3;
}
};
void main()
{
B der;
der.a3 = 0;
der.func();
}

3) W PM . W M
M :

class vehicle
{
int wheels;
public:
void inputdata( int, int);
void outputdata();
protected :
int passenger;
};

206
class heavy_vehicle : protected vehicle
{
int diesel_petrol;
protected:
int load;
public:
void readdata( int, int);
void writedata();
};
class bus: private _heavy_vehicle
{
char marks[20];
public:
void fetchdata( char );
void displaydata();
};

. heavy.vehicle M
M PH.
. displaydata() A
PH.
. bus M , A
PH.
. outputdata() P, heavy_vehicle M
?
4. W GL Of ?

#include<iostream.h>
#include<conio.h>
class student
{
int m1, m2, total;
public:
student ( int a, int b)
{
m1 = a;
m2 = b;
cout<<\n Non parameterized constructors..;
};
}
207
10
F e EPJ
(Impact of Computers on Society)

10.1

F AO A
-v F
NF Q
Q N
:
 (EP H
F)
 M L EP

Q, EP
O 85% (Wrod Processing) . ,
EP Q M F
. I N M, Q
EP C J .
EP N
F .

208
10.2 EP
EP (Personal Computers)
, , C P
PM. (Word Processing),
(Databases), MK (Spread Sheets),
(Multimedia Presentation Packages) - A EO
F FK.
. EP F (Desktop
Publishing)
EJ F . M (Paint), M (Games)
CP
F F EP
F A. (Browsing),
I (e-mail), (chat) A
PM.
EP O, O
AA. EP K iO I
J .
10.3 EP i

i K M
 C F, OM (), L
A: K . O
C . J I.
 : I
.
 C : CP -
F LA .
i.
b .
 : O
H
I
. H Q
.
 C :
C A F.

209
 i L, C
JL F
.
 HE
A F
 I- M

 F M
... M M
F EP A F
P M .
i 

 G : F, , C
N H O .
 K: I ,

 M: , L, ,
G
E. G
.
 /

 CF, QC C,
C
 A M: C
O KA .
 MN
O  , , QC
LA
 LA, K C,
P E, , v,
M, EH,

 F
E.
 dQ L A
LA
 P
F

EO A F.

210
10.4 iL A E
N A EJ K
A .
K IH
IHL
. A
A. P GF,
, C, I ,
H A F .
A O QQ H .
, C F A A
PM.
E O AO I c K G .
AO N P,

. I c K I
A.

10.1 CC A

211
10.2 v A

PH AJ AL F
F (ATM- Automatic Teller Machine)
N F A.
M, M O
GO A. , A
K .
AO A G
M .
I-A (e-Banking), iL
F N A O. ,
AO i F
.
EP E A.
J . I-
(e-shopping) J , GF
, , FL A
. c K F. J
F (website) c M O
H M . P
, H K .
M N .

212
(Credit cards), K F
N .
i MQA.
10.5 MJ EP
MJ HKO EP A.
C:
 /O CKO M
, O F F F
N P .
 EP N JC.
(Computer Based Tutorials - CBT).
 O, K, ,
, P MF, MF
F, M M , M ,
N- P
.
 I- (e-Learning) J F N M
P .

10.3

213
10.4 EPN JC

10.5 M M P

214
10.6 A EP
A EPO O . EP
M, , , , M
, PM, , F G P
P H . N
P, P G P
.

10.6 A EP

10.7 J EP (I)

215
10.8 J EP (F)
10.7 EP
J M AA.
K GF Q
. FK.
GA EP
A H .

10.9 J EP (F)
J HKO EP
A. C:

 O
 GA
KP

216
 P M P E
 G EE bQ M


J i N HA. O
PP. (Tele-medicine) ,
PH O e
. JL
N A. A
O A F A.
10.8 J EP
, N
. M
EP I .
N, M J
, M P E C L P
A GG
K . G, ,
M AP J M
F E
E , K A.
J HK:
 GF A
 M
 C
 c

10.10 J EP

217
 H J MQ

 G Fd

 F , ,
J M, H
- P

 F
 G
 F
 F MJ P

10.9 G O
GF
F A. J, M Y i
G F .

10.11 G
JC
F M P
K , M Q
O .
c . CK
. F PH
J.

218
11
N
(IT Enabled Services)
11.1
O O F
N A.
N (IT Enabled Services -
ITES) A. F Q
A . H
N E HK
A. N
FK.
EP F
v J ? F. Q,
(Dictaphone) C F C,
C M E
v- .
L (Wordprocessors), MK (Spreadsheets),
(Databases) A, N
N N . Q, ,
N M F
J P
. v,
A. P F A. ,
N F P N
F F v
.
v J ,
A. O, FF, C
, A O C
. CP N A.
K CP
H
F N
C:

219
 I- (e-Governance)
 M (Call Centres)
 (Data Management)
 (Telemedicine)
 (Medical Traanscription)
 EP (Data Digitization)
 (Website Services)
E Fm (Business Process Outsourcing -
BPO), (Digital Content Development),
(Animation), Q (Human Resources Services),
K (Remote Maintenance) A v M H
.
v E, NF P
O, F PF .
M, AF C F (Communication
skill) . v
F , N , N
(Professionalism), (etiquette) AP
K FQ (Softskill) JC
O.
11.2 I- (e-Governance)
c J
EP A.

. P M, PH E,
C F, , , , v
, , , F , FK
P, - A .
A, I A NO .

220
11.1 F G P

11.2 (&) , I

221
11.3 M (Call-Centres)
NF A.
N O
F G. 365 , O
24 E G
FA.
M , C O, PH
C J A
A. ,
(Marketing), M (Selling), K, -
E F A.
M F,
JC . I
, H G M
, F .
, M M
A. O, O
O ( 24x365 ) A.
11.4 (Data Management)
, v J .
OL F E
PJ I, H - A E A
. N, , F G
O EPJ F,
, C Of EPJ P
A - A E
A. , N
F , O C IP
, L G I .
, Of O
. A (Server) EPO I
A A. C F
O O OJA.
N MO J Of
A.
GO F J
N F F A
222
AA. v
:
 vA (ASCII) M F
F
 C EP
P
 J P K
 k
 FF

 O F
 , , , P-
F
EP P I
 I
 k
 EPJ I ;

 Of
 OM
J v
K G:
 , GFJ HE

 A


 d

 F G
 C


 F



223
PH G v O
J A HKO A
. A (Banking), GFJ (Financial Services),
d (Insurance) A Hv (BFSI)
A. Hv F
vR M C HK.
HKO, , Q (Privacy)
A A . v
F O. v
G . G
F Q v F
. EP P vR P P
.
11.5
(Medical Transcription and Tele-medicine)
, M
MA G, .
N H .
d .
G . :
G-1: vR F
M K
A. C C
N A.
J A EPJ (server) F A.
G-2: L EP
v A.
G . K O
, O
I H . ,
E , vR HK
A. EP e L
A. JC L
F , EPJ P .
P
.

224
G-3:
. K ,
K. Q F .
H P
F H.
. d F
.
11.6 EP (Data Digitization)
EP H O
EPJ P.
, , G, L A O
EP .
EPJ I
. O .
O P .
FF H . Q, EPJ I
, c F
. EP N
M P A. (Preservation)
c . N I
A F N A. NF
G , EP O H
MM. I
M. EP N
C HK :
 P M



 I M Of
 PJ
 GM
 F, , IO I
 / JC P
 M
225
EP F G :
 K P
 EP F
A.
 A.
 J,
A EP
E .
 EP
A.
EP F

AA.
 EP K,
O J,
KA. EP I
e N I
F A.
EP F AA.
A C :
 c .
 A F I
.
 I O A, O .
 , P
F M, I C
P .
 I O
KP .
 , H I
I O K .

226
11.7
W A
EP A:
 H


 N
 GF
 O
A JL F
v F I MM
A.

JC
F M P
K , M Q
O .
c . CK
. F PH
J.

227
12
EP P
(Computer Ethics)
K (Norbert Weiener)
F L EP P
P PH. K L PH:
(1) Q M P M
(2) cFPJ
(3) P F
N
(4) EP P M
P .
(5) A EP P K

1960-O FJ LQM
A v (Donn
Parker), EP E EP b
F A.1980-O
KM M NF
, P b HC P.
EP , EP O
K, EP N K QJ
(Privacy) W, K
C.
1990-O , EP P
P PF.
H M . ,
C F J. M
O I.
Q P , F
bQA MF
P .
EP N
P , P

228
A M A. P C
N F
I. NF
.
EP P P N
A:

EP

12.1 (Data Security)
W N C F K
:
(Physical Security)
, EP P
I I
N H
PA. EP
MF
A .
(Personal Security)
, F EP

PA. (User ID) (Password) A
M. EPJ P
P
.
E (Personal Security)
E , EP ,
EOI
PA.
12.2 EP (Computer Crime)
EP , EP , ,
- F ,
M
PA.
229
EP C:
F N K
.
EP F O
C
C eP

/M
O KJ

G (Virus)
(Cracking)
EP
EP O 80%
G G P. 60%-
PM MA.
L ,
KJ (Piracy) A.
KJ :
MA.
A,
M A .


MA, gF A
A Q
. O
AJA.
G A.
EPJ I
F . F , H
N A ,
FI G F G A
G . P G 57000- F.
6 F G PA.
230
GO EPO
F. E
A. O EP
J N
A. Q, GF
A EP NO
A. G K
EPO H A A.
EP A.
EP P
P, EP P EP
P . W :
 H b MM EP
b.
 HK EP EJ Jb.
 HK EP Mb.
 EP F b.
 C EP b.
 c M FK
b
b.
 H EP FJP, K
IP b.
 HK P K
b.
 c c
J M
E .
 QO A
K K J
EP .

231
EP C
G .
GP, EP K
A A. F EP
IO (Cyber Laws) P.
12.3 (Cracking)
J EP J
HF A. EP
J C
L .
, , , -
. N, E , A
H .
12.4 , ,
EP EE (Tele
Computing), Q E F
G A.
M, E F
, M, MA MA.
, N i
A. Q,
N A. EP PJ I
A HC A.

JC M:
1. EP H (Password)
?
2. EP (Operating System) H
A?

232

You might also like