You are on page 1of 32

( jiyg;gpw;F fPNo cs;s ypq;if fpspf; nra;J FOtpy; ,izaTk;!

 Padasalai's NEWS - Group


https://t.me/joinchat/NIfCqVRBNj9hhV4wu6_NqA

 Padasalai's Channel - Group


https://t.me/padasalaichannel

 Lesson Plan - Group


https://t.me/joinchat/NIfCqVWwo5iL-21gpzrXLw

 12th Standard - Group


https://t.me/Padasalai_12th

 11th Standard - Group


https://t.me/Padasalai_11th

 10th Standard - Group


https://t.me/Padasalai_10th

 9th Standard - Group


https://t.me/Padasalai_9th

 6th to 8th Standard - Group


https://t.me/Padasalai_6to8

 1st to 5th Standard - Group


https://t.me/Padasalai_1to5

 TET - Group
https://t.me/Padasalai_TET

 PGTRB - Group
https://t.me/Padasalai_PGTRB

 TNPSC - Group
https://t.me/Padasalai_TNPSC
sa lai. sala
i
www.Padasalai.Net
. i.
lawww.TrbTnpsc.com
sa salai
.
sal
ada ada ada a d a a da
w w.P w w.P w w.P w w.P w w.P
w w w w w
XI COMPUTER SCIENCE VOLUME II
la i .Org la i .Org l a i .Org l a i .Org
d a sa da sa d a sa d asa d a sal
a a a a a
w w.P w w.P w w.P w w.P ww.P
w w w w w
i . O rg i . O rg i . O rg i . O rg
a d asa
l a
a d asa
l a
Classad: aXI
sal a
a d asa
l a
a d asa
l
w.P w.P w.P w.P w.P
ww ww ww ww ww
i.O rg .Org i.O rg rg
sala sa la i
sala s alai.O al
a da a a as
w. Pad w .Pa w. Pad w. Pad w. Pad
ww ww ww ww ww
i.O rg i.O rg i.Org i .Org
s a l a s a l a s a l a sa l a al
a a a ada as
w. Pad w. Pad w. Pad w .P w. Pad
ww ww ww ww ww
i.O rg rg .Or g .Org
sala a lai.O l ai l a i al
a da s asa a sa as
w . Pad w .Pa w. Pad w. Pad w. Pad
ww ww ww ww ww
i.O rg i.O rg i.O rg i.Or
g
sala sala sala l a sal

Padasalai
s a
da da da da da
w .Pa w .Pa w.Pa w.Pa w.Pa
ww ww ww ww ww
i.O rg i.O rg i .Org i.O rg
a sala a sala a sa l a
a sala as al
w . Pad w. Pad w. Pad w. Pad w. Pad
ww ww ww ww ww

la i.O rg
l a i .OrLesson
g
-14la i .Org l ai .Org
d a s a
d asa d a sa d a sa d a sal
a a a a a
w w .P w w.P w w.P w w.P w w.P
w w w w w

l a i .Org la i .Org l a i .Org l a i .Org


sa sa sa sa sal
a Class and
w.P Objectsww.P
a d a d a a d a a d a a d a
w w.P w w.P w w w.P
w w w w w
i . O rg i . O rg i . O rg i . O rg
l a l a l a l a l
a d asa a d asa a d asa a d asa a d asa
w.P w.P w.P w.P w.P
ww ww ww ww ww
i.O rg i.O rg i.O rg i.O rg
a sala a sala da sala a sala asal
w. Pad w. Pad w .Pa w. Pad w. Pad
ww ww ww ww ww
i.O rg i.O rg i .Or g
i.O rg
s a l a s a l a sa l a sal
s a la
P ada 1 a d a a da a d a a da
ww
.
w w.P
Prepared By : M.Dhanapal.,
w w.P
MCA.,B.Ed 9790573672,
w.P
Literacy Mission MHSS,Tirupur
w ww.P
w w w w w

l a i .Org l ai .Org la i .Org l a i .Org


a Send Your Questions a sa id - padasalai.net@gmail.com
a al
das das & Answer Keys to our daemail das das
sa lai. sala
i
www.Padasalai.Net
. i.
lawww.TrbTnpsc.com
sa salai
.
sal
ada ada ada a d a a d a
w w.P w w.P w w.P w w.P w w.P
w w w w w
XI COMPUTER SCIENCE VOLUME II
la i .Org la i .Org l a i .Org l a i .Org
a sa a sa a sa asa a sal
a d a d Book Back aQuestions
d a d a d
w w.P w w.P w w.P w w.P w w.P
w w w Part -II w w
i . O rg i . O rg i . O rg i . O rg
1.saWhata
l are called members? l a l a l a l
a d a a d asa a d asa a d asa a d asa
✓ Class comprises of members. .Members are classified
w.P w.P wP w.P as Data Members wand
.P
ww w
Member functions.
w w w w w w w
✓ rData
g members are the rdata
g variables that represent rg the features or properties
rg of
i . O i . O i . O i . O
d a sala a class. Member d a sfunctions
ala are the functions
d a sala that perform specificd a salatasks in a class. dasal
a ✓ Member .functions
Pa are called as.Pmethods,
a and data members
.Pa are also called.P asa
w w.P w w
attributes. w w w w w w
w w w w w
2. Differentiate structure and class though both are user defined data type.
l a i .Org l a i .Org l a i .Org l a i .Org
d a sa SNO a sa
STRUCTURE
d d a sa CLASS d a sa d a sal
a a a a a
w w.P 1 w w.P of a class are ww.PMembers of a structure
Members w w.Pare public w w.P
w w private by default
w by default
w w
g .Org class Testi.Org .Org
ala i.Or2 struct Test
a la i l a l a i al
as { { asa a
Pad int x;
P a daxsis public
// P a dint x; // x is public Padas Pad
as
w. w. w. w. w.
ww ww
}; ww }; ww ww
O rg rg rg rg
sala i . 3 lai.O only
A structure contains A class ai.Oalso contain functions
lcan lai.O sal

Padasalai
s a s a s a
da member a
advariables da methods] and member
a[called ada da
w.Pa w.P . P
w variables w . P w.Pa
ww ww ww ww ww
g rg class and object initerms
.Org of oop? rg
i.Oisr the difference between
3. What i.Othe i.O
a sala a sala a sala a sala asal
w . Pad Sno w. Pad
Class w. Pad Object w. Pad w. Pad
ww 1 w w
The formation of a class w w w
Creation of objectwconsumes ww
doesn't allocate memory. memory
la i.Or2g A template or lblueprint
a i .Org with An instance la i .Oofrga class is known aslai.Org
asa asa are created is aObjectasa asa s al
a d which d
objects
a d a d ada
w .P w.P as Class. w.P w.P w .P
ww wwknown ww ww ww
3 Class is declared by using Object is invoked by new
O r g O r g rg rg
lai. a
class keyword.
salai. keyword lai.O
sa lai.O
sa sal
as a a a a
w. Pad w.P
4. Why it is considered
a d
as a good practice
a d
w.P to define a constructor
a d
w.P though compiler .Pa
wcan
d
w w w
w generate a constructor? w w w w w w
automatically
. g
✓ OrWhen an object of the
. O rgclass is created a compiler
. O rg can automatically . O g
rgenerates a
a l a i constructor if it isa l
nota i defined. al a i l a i l
a d as ✓ It is considered a d as that writing constructor a d as for a class is aadgood a
as practice becauseadasa
w.P w.P takes over very important w.P duty of initialization w.P ww
.P
ww ww
constructor ww ww of an object beingwcreated
and relieves us from this task
5. Write i . O rg the importance of
down i rg
.Odestructor. i .Org i .Org
l a
sa ✓ Destructor is dused l a
sato de-allocate the memory la
sa of an object that was sa la sal
a d a a a ad a a d aallocated by a d a
w w.P w.P
constructor.
w ww.P w w.P w w.P
w w w w w
6. What is class?
i.Org i.Org i .Org
i.O rg
s a l a s a l a sa l a s a la sal
P ada 2 a d a a da a d a a da
ww
.
w w.P
Prepared By : M.Dhanapal.,
w w.P
MCA.,B.Ed 9790573672,
w.P
Literacy Mission MHSS,Tirupur
w ww.P
w w w w w

l a i .Org l ai .Org la i .Org l a i .Org


a Send Your Questions a sa id - padasalai.net@gmail.com
a al
das das & Answer Keys to our daemail das das
sa lai. sala
i
www.Padasalai.Net
. i.
lawww.TrbTnpsc.com
sa salai
.
sal
ada ada ada a d a a da
w w.P w w.P w w.P w w.P w w.P
w w w w w
XI COMPUTER SCIENCE VOLUME II
la i .Org la i .Org l a i .Org l ai .Org
d a sa ✓ Class is a waydatosbinda
the data and its
d a sa
associated functions asa Classes are
together.
d d a sal
a a a .Pa .Pa
w w.P needed
w wto.Prepresent real worldwentities
w.P that not only have w w
data type properties but
w w
also
w w w w w
have associated operations.
. O r g . O rg . O rg . O rg
7. aWrite
l a i the general form of l a i
class with example. l a i l a i l
a d as a d asa a d asa a d asa a d asa
w.P w.P w.P w.P w.P
ww ww class classname ww ww ww
rg {
l a i . O private:
la i .Org l a i .Org l a i .Org
d a sa d a sa d a sa d a sa d a sal
a a member variable a declarations; a a
w w.P w w.P w w.P ww.P w w.P
w w memberwfunction declarations; w w
rg public:
l a i . O l a i .Org variable declarations;
l a i .Org l a i .Org
d a sa d a sa member
d a sa d a sa d a sal
a a member function a a a
w w.P w w.P w w.P declarations; ww.P w w.P
w w protected: w w w
rg member variable declarations;
i.O i .Org i .Org i.Org
d a sala d a
la
a
l a
sa member function ddeclarations;
sa d a sa l a
d a sal
a a a a a
w w.P w w};.P ww.P w w.P w w.P
w w w w w
8. Write
i . O rg need for class. i.Org
the
i . O rg i . O rg
la a a
al the data and itsasassociated
al sal a Classes are asal

Padasalai
a d asa✓ Class is a way a dto
asbind a d functions atogether.
a d d
w .P .P
needed towrepresent .P that not only have wdata
real world entities
w .P type properties butwalso .Pa
ww ww ww ww
have associated operations. It is used to create user defined data type ww
9. What
l a i .Oisrgdata hiding? l a i .Org l a i .Org l a i .Org l
d a sa✓ Data hiding isdone a sa of the important featuresd a sa of Object Oriented d a a
sProgramming which dasa
a a a a a
w w .P w.P
allows wpreventing the functions w w.Pof a program to waccess w.P directly the internal w w.P
w w w w w
representation of a class type.
✓ i.O rg access restriction to
The i rg class members is specified
.Othe i .Org by public, private, i rg protected
.Oand
l a
sa sections withindthe l a
a body.
sclass sa l a sa l a sal
a d a a d a d a d a
w.P 10. Write syntaxwofwdefining .Pa non inline member a
w.Pfunction. w.P
a
w.P
a
w w w w w w w w w
return_type class_name :: function_name (parameter list)
l a i .Or{g la i .Org la i .Org l a i .Org
d a sa function
d a a
sdefinition d a sa d a sa d a sal
a a a a a
w w.P }
w w.P w w.P w w.P w w.P
w 11. What is thewpurpose of the class access w specifier? w w
✓ .OThe
i rg access restriction ito . O rg class members is specified
the
i . O rg by public, private, i . O rg protected
and
l a a
salclass body. The keywords l a al a are called asal
a d asa sections within athe
a d a d asa public, private,aand d asprotected d
w .P access w .P
specifiers. The default access
w .P
specifier for members is
w P
.private. w .Pa
ww ww
12. List the types of creating objects.
ww ww ww
✓ g Object
.OrLocal .Org .Org .Org
l a i l a i l a i l a i
d a sa ✓ Global Objectdasa d a sa d a sa d a sal
.Pa 13. What is global w .Pa .Pa .Pa .Pa
w ww w w object? w ww www w ww

i.Org i.Org i .Or g


i.O rg
s a l a s a l a sa l a s a la sal
P ada 3 a d a a da a d a a da
ww
.
w w.P
Prepared By : M.Dhanapal.,
w w.P
MCA.,B.Ed 9790573672,
w.P
Literacy Mission MHSS,Tirupur
w ww.P
w w w w w

l a i .Org l ai .Org la i .Org l a i .Org


a Send Your Questions a sa id - padasalai.net@gmail.com
a al
das das & Answer Keys to our daemail das das
sa lai. sala
i
www.Padasalai.Net
. i.
lawww.TrbTnpsc.com
sa salai
.
sal
ada ada ada a d a a da
w w.P w w.P w w.P w w.P w w.P
w w w w w
XI COMPUTER SCIENCE VOLUME II
la i .Org la i .Org l a i .Org l ai .Org
d a sa ✓ An object is ddeclared
a sa outside all the
d a a
sfunction bodies or by
d a a
splacing their names d a sal
a a a a a
w w.P w.P after the closing w
immediately
w w.P of the class declaration
brace w w.Pthen it is called aswGlobal
w.P
w w w w w
objects.
. O r g . O rg . O rg . O rg
l a i
✓ These objects can be
l a i
used by any function in lthe
a i program l a i l
a d asaWhat is Local object?
14. a d asa a d asa a d asa a d asa
w.P w.P w.P then it is called local w.P ww
.P
ww ww is declared with in w
✓ An object aw
function ww object.It cannot bew accessed

i . O rfrom
g outside the function. g
i.Or member function. i .Org i .Org
15.aWrite
l a the general syntax a oflacalling l a l a
d a s d a s d a sa d a sa d a sal
a The general syntax a for calling the member a function is: a a
w w.P w w.P w w.P w w.P w w.P
w Object_name
w . function_name(actual
w parameter); w w
16. Write arg short note on scope resolution rg operator.
l a i . O l a i . O l a i Org
.name l a i rg
.Oblocks
d a sa ✓ If there are multiple
d a sa variables with the
d a
same
sa defined in
d
separate
a sa then ::
d a sal
a a
(scope resolution) operator will reveal a a a
w w.P w w.P w w.P the hidden file scope(global)
w w.P variable.
w w.P
w Example w: w w w
i . O rint
g a=100;
i .Org i .Org i.Org
sa la sa la sal a sa l a sal
d a class A d a d a da d a
a a a a a
w w.P {
w w.P ww.P w w.P w w.P
w w
int a; w w w
i . O rpublic:
g
i .O rg i . O rg i . O rg
l a void fun() l a l a l a l

Padasalai
a d asa { a d asa a d asa a d asa a d asa
w.P a=20;ww.
P w.P w.P w.P
ww w ww ww ww
a+=::a; //using global variable value
g
rcout<<a; rg .Org rg
a lai.O sala
i.O
sa l a i
sala
i.O
sal
as } }; a a a a
w. Pad 17. What is container? w.P
a d
w.P
a d
w.P
a d
w.P
a d
w w w w w w
w is declared as a memberwof another class it is known w
w as a
✓ Whenever an object of a class
g
.Orcontainer Org
class. In thei.container-ship the objecti.of g class is declared in.O
Orone rg class.
another
la i l a l a l a i
d18.
a saWhat is the need of constructor?
d a sa d a sa d a sa d a sal
a a a a a
w w .P w w.P
✓ The initialization of class type w w.P at the time of declaration
object w w.P similar to a structure w w.P
or
w an w array is not possible because w the class members w have their associated w access

l a i .Orspecifiers
g (private or protected
l a i
or public).
.Org special l a i Org
.functions l a i .Org
d a sa ✓ Therefore Classes
d a sa include member
d a sa called
d aas
sa constructors. The
d a sal
a constructorPafunction initializes the a object.
class a a
w w.P 19. List the orderwof w.constructor invocation.w w.P w w.P w w.P
w w w w w
✓ The g constructors are executed
g in the order of the
g object declared. (If it g in same
is
. O r . O r . O r . O r
a s alai statement left to a s alai
right)
a s alai a s alai asa
l
a d ✓ For example a d a d a d a d
w.P w.P w.P w.P w.P
ww wwTest t1; ww ww ww
Test t2;
20. What g
.Oisr constructor? .Org .Org .Org
l a i l a i la i a i
d a sa ✓ When an instance d a saof a class comes into d a sa a special function
scope, d a
l
sa the constructor dasal
called
a a a .Pa as the class name.w.Pa
w w.P w.P The constructorwfunction
gets executed.
w w.P name has the same w wname
w w w w ww
✓ The initialization of class type object at the time of declaration similar to a structure or
rg rg Org rg access
sal ai.O an array is not possible
sal ai.O because the classai.members
sal sal ai.O
have their associated
sal
a d a a d a a da a d a a da
w.P 4 w.P
Prepared By : M.Dhanapal.,
w.P
MCA.,B.Ed 9790573672,
w.P
Literacy Mission MHSS,Tirupur
w.P
ww w w w w w w w w

l a i .Org l ai .Org la i .Org l a i .Org


a Send Your Questions a sa id - padasalai.net@gmail.com
a al
das das & Answer Keys to our daemail das das
sa lai. sala
i .
www.Padasalai.Net i.
lawww.TrbTnpsc.com
sa salai
.
sal
ada ada ada a d a a da
w w.P w w.P w w.P w w.P w w.P
w w w w w
XI COMPUTER SCIENCE VOLUME II
la i .Org la i .Org l a i .Org ai .Org
d a sa specifiers a sa or protected or public).
(private
d d a sa Therefore Classes include
d a
l
sa special member dasal
a Pa a a a
w w.P w w.called
functions as constructors.
w w.P w w.P ww.P
w w w w w
21. What is destructor?
i . O rg i . O rg i . O rg i . O rg
al a ✓ When a class object
al a goes out of scope, a special
al a function called the
al a destructor gets l
a d a s executed. The
a d a s
destructor has the d
same
a a sname as the class a d
taga s
but prefixed with aa d asa
w.P w.P .P
wwreturn nothing and itwdoes
.P
ww not associated withwanydata ww
.P
ww ww
~(tilde).Destructor function w also
type.
g g g g
lai .Or la i.Or lai.Or lai.O
r
sa as a s a s a as al
da d Pad
a
Pad
a
Pad
w .P a w .Pa w. w. w.
ww ww wwPart –III ww ww

l a i . Org l a i . Org l a i . Org a i .Org


d
1.saRewrite the following sprogram
a d a a after removingsa
d a the syntax errors if any
d a
l
saand underline the dasal
a errors: a a a a
w w.P w w.P w w.P w w.P w w.P
w w
#include<iostream> w void display ( )w w

la i .Org #include<stdio.h> l a i .Org {


l ai .Org cout<<studid<<”: l a i.Org
d a sa classmystud
d a sa “<<name<<endl;}
d a sa da sa d a sal
a a a a a
w w.P w.P =1001;
{ intstudid
w w w.P } w w.P w w.P
w w w int main( )
w w
char name[20];
i . O rg public i .O rg
{ mystud i . rg
MS;
O i . O rg
la l a l a l a l

Padasalai
a d asa mystud( a)d asa a d asa
register.MS( ); a d asa a d asa
w.P { }ww
.P w.P MS.display( ); ww.P w.P
ww w ww w ww
}
.O rg Void register() i.Org .Org .Org
l a i {cin>>stdid;gets(name);
l a } l a i l a i
d a sa d a sa d a sa da sa d a sal
a Corrected Program.:Pa a a a
w w .P w w w w.P w w.P w w.P
w w w w w
i . O rg #include<iostream> i .Org i .Org i .Org
la #include<stdio.h>
l a l a l a
d a sa using a sa std;
namespace
d d a sa d a sa d a sal
a .Pa a a a
w w .P wmystud
class
w w w.P w w.P w w.P
w w w w w
{
l a i .Org int studid; la i .Org la i .Org l a i .Org
d a sa char name[20];
d a sa d a sa d a sa d a sal
a public: a a a a
w w.P w w.P w w.P w w.P w w.P
w w
mystud() w w w
i . O rg { i . O rg i . O rg i . O rg
l a studid=0; l a l a l a l
a d asa } a d asa a d asa a d asa a d asa
w.P int w.P
wregister1() w.P w.P w.P
ww w ww ww ww
{
g .Org rg rg
i.Or cin>>studid;i i.O i.O
a sala asa
l a
gets(name);
da sala a sala as al
w. Pad } w. Pad w .Pa w. Pad w. Pad
ww w w display()
void ww ww ww
.Or g { .O rg .Or g rg
l a i alai
cout<<studid<<":"<<name<<endl; l ai la i.O
sa s sa s a sal
P ada 5 a d a a da a d a a da
ww
.
w w.P
Prepared By : M.Dhanapal.,
w w.P
MCA.,B.Ed 9790573672,
w.P
Literacy Mission MHSS,Tirupur
w ww.P
w w w w w

l a i .Org l ai .Org la i .Org l a i .Org


a Send Your Questions a sa id - padasalai.net@gmail.com
a al
das das & Answer Keys to our daemail das das
sa lai. sala
i .
www.Padasalai.Net sa
i.
lawww.TrbTnpsc.com salai
.
sal
ada ada ada a d a a d a
w w.P w w.P w w.P w w.P w w.P
w w w w w
XI COMPUTER SCIENCE VOLUME II
la i .Org la i .Org l a i .Org l a i .Org
d a sa } da sa d a sa d asa d a sal
a a a a a
w w.P }; w w.P w w.P w w.P w w.P
w w w w w
int main()
i . O rg { i . O rg i . O rg i . O rg
l a mystud MS;asal
a l a l a l
a d asa a d a d asa a d asa a d asa
w.P w.P
MS.register1(); w.P w.P w.P
ww w w
MS.display(); w w w w w w

i.O rg } .Org i.O rg rg


sala sa la i
sala s alai.O al
a da a a as
w. Pad w .Pa w. Pad w. Pad w. Pad
ww ww ww ww ww
2. Write
g
.Orwith example howlawill g
r dynamically initialize
.Oyou g
.Or objects? .Or g
l a i i l a i l a i al
d asa ✓ When the initial d
a are provided during
asvalues d asaruntime then it is called
d asadynamic as
.P a .Pa .P a .P a . Pad
w ww ww .
initialization
w www ww w w ww
Example:
la i .O gr #include<iostream>
la i .Org l a i .Org l a i.Org
d a sa using d a sa
namespace std; d a sa da sa d a sal
a a a a a
w w.P w w.P X
class ww.P w w.P w w.P
w w { w w w
i . O rg float avg;
i .O rg i . O rg i . O rg
l a public: asal a l a l a l

Padasalai
a d asa a d a d asa a d asa a d asa
w.P X(float
w.P a) w.P w.P w.P
ww ww{ ww ww ww
rg avg=a; Org Org Org
i.O i . i . i .
d a sala }
d asa
l a
d asa
l a
d asa
l a
as al
w .P
a void a
w.P disp() w.P
a
w.P
a
w. Pad
ww ww{ ww ww ww
rg cout<<"\nAverage rg :- "<<avg;
la i . O } l a i . O l a i .Org l a i .Org
asa asa asa asa s al
a d }; a d a d a d ada
w .P w.P w.P w.P w .P
ww wwint main() ww ww ww
rg {
l a i . O int avg; la i .Org la i .Org l a i .Org
a a a a al
P a das P adas
cout<<"\nEnter the Average";
P a das P a das Pad
as
w. w. w. w. w.
ww wwcin>>avg; ww ww ww
g X x(avg); // dynamic g initialization .Org
i . O r x.disp(); i . O r i i . O rg
l a l a l a l a sal
a d asa returna d asa
0; a d asa a d asa ada
w.P } www
.P w.P w.P w . P
ww ww ww ww
r g g g g
3. What i.Ordeclaring constructors
lai.O are advantages laof
r Or
lai.O and destructorlai.under public
d a saaccessibility? d a sa d a sa d a sa d a sal
a a a Pa a
w w.P w.P can be definedweither
✓ A constructor
w w.P in private or public w w.section of a class. But
w wit.Pis
w w w w w
advisable to defined in public section of a class ,so that its object can be created in any
g
.Orfunction. .Org .Org .Org
l a i l a i l ai la i
d a sa d a sa da sa d a sa da sal
a a a a a
w w.P 6 Prepared w w.P
By : M.Dhanapal.,
w.P
MCA.,B.Ed 9790573672,
w w.P
Literacy Mission MHSS,Tirupur
w ww.P
w w w w w

l a i .Org l ai .Org la i .Org l a i .Org


a Send Your Questions
a sa id - padasalai.net@gmail.com
a al
das das & Answer Keys to our
daemail das das
sa lai. sala
i .
www.Padasalai.Net i.
lawww.TrbTnpsc.com
sa salai
.
sal
ada ada ada a d a a da
w w.P w w.P w w.P w w.P w w.P
w w w w w
XI COMPUTER SCIENCE VOLUME II
la i .Org la i .Org l a i .Org l a i .Org
d a
4.
saGiven the followingdC++ a sacode, answer the questions
d a sa (i) & (ii). d asa d a sal
a a a a a
w w.P w w.P TestMeOut
class w w.P w w.P ww.P
w w w w w
{
i . O rg public: i . O rg i . O rg i . O rg
l a l a l a l a l
a d asa a d asa //Function 1adasa
~TestMeOut() a d asa a d asa
w.P w.P ww
.P w.P w.P
ww ww{cout<<“Leaving thewexamination hall”<<endl;} ww ww
TestMeOut() //Function 2
g .Org for examination”<<endl;} .Org .Org
l a i.Or {cout<<“Appearing
la i l a i l a i
d a sa void d a sa
MyWork() //Function 3 d a sa d a sa d a sal
a a a a a
w w.P w w.P
{cout<<“Attempting w.P
Questions//<<endl;}
w w w.P w w.P
w w }; w w w
(i) In
i rg Oriented Programming,
.OObject i .Org what is Function i .Org1 referred as andlwhen i .Orgdoesit get
l a
sa invoked / calledd?asa l a sa l a sa a sal
a d a a d a
a automatically when a d a d a
w.P Ans: Its Destructorw.P function and itswexecutedw.P w.P instance of class .Pa
goes
w
w w w w w w w w w
out
.Oofrgscope. .Org .Org .Org
l a i l a i l a i l a i
d a sa(ii) In Object Oriented d a sProgramming,
a what isasFunction
d
a 2 referred asaand
d sa when doesit d a sal
a a a a a
w w.P get w w.P w w.P w w.P w w.P
w w w w w
invoked / called ?
Ans: i . O rg constructor function
Its i .O rgand its executed automatically
i . O rg when instance
i . O rg of class
a
al to l a l a l a l

Padasalai
a d ascomes a d asa a d asa a dasa a d asa
.P scope. ww.P .P .P .P
w ww w ww w ww
w www
5. Write the output of the following C++ program code :
i.O rg #include<iostream>
i .Org i .Org i .Org
a sala using d asa
l a
namespace std; asa
l a
asa
l a
as al
w . Pad a
w.P Calci
class w.P
a d
w.P
a d
w. Pad
ww ww{ ww ww ww
i.O rg char Grade; .Org
i i .Org i .Org
a la int Bonus; l a l a l a al
a s asa asa asa ada
s
w. Pad a
public:
w.P
d
w.P
a d
w.P
a d
w .P
ww wwCalci() {Grade='E'; Bonus=0;}
ww w w
//ascii value of A=65 ww
rg void Down(int O G)
i.O i . rg i .Org i .Org
a sala {
das
a l a
das
a la
das
a l a
as al
w. Pad w.
a
Grade-=G;
P w. P a
w. P a
w. Pad
ww ww} ww ww ww
rg void Up(int G) rg rg rg
a lai.O { l a i . O l a i . O l a i . O
sal
ada
s d
Grade+=G;
a asa a d asa a d asa ada
w.P w.P w.P w.P w . P
ww wwBonus++; ww ww ww
rg }
i.O void Show() i .Org i .Org i .Org
a sala { Pada
sa l a
asa
l a
asa
l a
as al
w. Pad w. w.P
a d
w.P
a d
w. Pad
ww wwcout<<Grade<<"#"<<Bonus<<endl;
ww ww ww
}
i.O rg rg rg rg
s a l a };
sa lai.O sa lai.O sa lai.O sal
P ada 7 a d a a da a d a a da
ww
.
w w.P
Prepared By : M.Dhanapal.,
w w.P
MCA.,B.Ed 9790573672,
w.P
Literacy Mission MHSS,Tirupur
w ww.P
w w w w w

l a i .Org l ai .Org la i .Org l a i .Org


a Send Your Questions a sa id - padasalai.net@gmail.com
a al
das das & Answer Keys to our daemail das das
sa lai. sala
i
www.Padasalai.Net
. i.
lawww.TrbTnpsc.com
sa salai
.
sal
ada ada ada a d a a da
w w.P w w.P w w.P w w.P w w.P
w w w w w
XI COMPUTER SCIENCE VOLUME II
la i .Org la i .Org l a i .Org l a i .Org
d a sa int a
main()
d sa d a sa d asa d a sal
a a a a a
w w.P w{w.P w w.P w w.P ww.P
w w w w w
Calci c;
i . O rg c.Down(3); i . O rg i . O rg i . O rg
l a l a l a l a l
a d asa c.Show();
a d asa a d asa a d asa a d asa
w.P w.P w.P w.P w.P
ww wwc.Up(7); ww ww ww
c.Show();
g c.Down(2); ai.Org .Org .Org
i.Or i i
d a sala c.Show();
d a sa l
d a sa l a
da sal a
d a sal
w. Pa a
w.P 0;
return w.P
a
w.P
a
w.P
a
ww w
w } w w w w w w

i.Org i.Org i.Org i .Org


s a l a s a l a s a l a sa l a al
da Output: a a ada as
w .Pa w.Pad w. Pad w .P w.Pad
ww B#0ww ww ww ww
O rI#1
g rg .Or g .Org
la i . lai.O l ai l a i al
asa G#1
da sa asa a sa as
w .Pad w .Pa w. Pad w.Pad w. Pad
ww ww ww ww ww
6. Write short note on class access specifier.
✓. O g access restriction .to
rThe O g class members is specified
rthe . O rg by public, private, . O rg protected
and
l a i a i a i a i
sal class body. The keywords l al l

Padasalai
a d asa sections within
a d athe a d asa public, private,aand d asprotected are calledadasa
w.P w.P
accesswspecifiers. The default access w.P w.P w.P
ww w ww specifier for members ww is private. ww
Public:
l a ✓
i .OrAgpublic member islaaccessible
i .Org from anywhere l a i Org the class but lwithin
.outside a i .Orga program.
d a sa You can set and
d a a
sget the value of public d a sa members even without
data d a sausing any member dasal
a a a a a
w w .P w.P
function.
w w w.P w w.P w w.P
w w w w w
Protected:
l a i
✓ .OrAgprotected memberlaisi.O rg
very similar to a privatela i Org but it provides
.member l ai
g
.Oradditional
one
d a sa benefit that they
d a a be accessed in childaclasses
scan d sa which are calleddaderived sa classes d a sal
a a a a a
w w .P w.Pclasses).
(inherited
w w w.P w w.P w w.P
w Private:
w w w w

l a

i .OrAg private member lcannota i .Orgbe accessed fromlaoutside i .Org the class. Only lthea i rg member
.Oclass
d a sa functions can access
d a sa private members.dBy a sadefault all the members d a saof a class would be dasal
a private.w.Pa a a a
w w.P w w w.P w w.P w w.P
w 7. Write a short w note on non inline member w function. w w
✓ rWheng Member function rdefined g outside the classrgjust like normal function rg definition
l a i . O a i . O
l you are familiar with a i . O a i . O
l ) then it is be called sasal outline member sal
(Function definitions
a d asa a d asa a d asa da
aoperator ada
. P function .or
P non-inline member function. . P Scope resolution .P (::) is used .for
P
w ww w w w
ww thiswpurpose. ww ww ww
Syntax:
l a i .Org l a i .Org l a i .Org l a i .Org
d a sa d a sa
return_type class_name :: function_name
d a sa(parameter list) dasa d a sal
a { a a a a
w w.P w w.P w w.P w w.P w w.P
w w definition
function w w w
i . O r}g i rg
.Oallocation i .Org i .Org
s l a
8. aWrite a short note on memory
sa l a of objects.
sa l a sa la sal
a d a a d a a da a d a a d a
w w.P 8 Prepared w w.P
By : M.Dhanapal.,
w.P
MCA.,B.Ed 9790573672,
w w.P
Literacy Mission MHSS,Tirupur
w ww.P
w w w w w

l a i .Org l a i .Org la i .Org l a i .Org


a Send Your Questions a sa id - padasalai.net@gmail.com
a al
das das & Answer Keys to our daemail das das
sa lai. sala
i
www.Padasalai.Net
. i.
lawww.TrbTnpsc.com
sa salai
.
sal
ada ada ada a d a a da
w w.P w w.P w w.P w w.P w w.P
w w w w w
XI COMPUTER SCIENCE VOLUME II
la i .Org la i .Org l a i .Org ai .Org
d a sa ✓ The member dfunctions
a sa are created anddplaced a sa in the memory space d a
l
saonly when they are dasal
a a a a a
w w.P defined
w was.Pa part of the class specification.
w w.P w w.P ww.P
w w w w w
✓ Since all the objects belonging to that class use the same member function, no separate
i . O rg i . O rg i . O rg i . O rg
l a space is allocated alfor
a member functions when
l a the objects are created.
a
d asa ✓ Memory space d asrequired for the d asa variables are only
member d sal
aallocated separately d asa
l
a a a a a
w.P .P
ww object because the w.P w.P w.P
ww for weach wwmember variables will wwhold different data values ww for
i . O rdifferent
g objects
i .Org i .Org i .Org
9. aWrite
l a a short note on array la objects. l a l a
d a s d a sa d a sa d a sa d a sal
a • An array which a contains the class type a of element is called array a of objects. a
w w.P w w.P w w.P w w.P w w.P
w • It isdeclared
w and defined in the w same way as any otherwtype of array. w
Example:
g
l a i .OrClass l a i . Org l a i . Org l a i .Org
d a sa A
d a sa d a sa d a sa d a sal
a { a a a a
w w.P w w.P w w.P w w.P w w.P
w w
}a[5]; w w w

l a i .OrHere
g a[5] is array objects
l a i .Orgof class A l a i .Org l a i.Org
d
10.
a saWrite a short note ondnesting a sa of member function. d a sa da sa d a sal
a Pa only public members a a a
w w.P • We know
w w.that ww.Pof a class can be accessedw w.Pby the object of thatwusing
w.P
w dotw operator. w w w
•.OrAgmember function can
i i . rg another member function
call
O i . O rg directly using its name
i . O rgwithout
al a al a al a al a al

Padasalai
das
a das is called Nesting Member
using dot operator
a das functions.
a das a das a
.P .P .P .P .P
w ww w ww www www www
Example:
g
.Or#include<iostream> .Org .Org rg
a i a i a i i.O
d asa
l
using namespace d
a l
asstd; a sa l
a sala as al
w .P
a
class w w.P
a
w. Pad w. Pad w. Pad
ww wnest ww ww ww
{
O r g
. public: .Org .Org .Or g
la i l a i la i l ai al
d asa int x=5,y=5;adas
a
ada
sa a sa
ada
s
w .P
a
w.P w .P w. Pad w .P
ww int sum(
ww ) ww ww ww
{
O r g .Org rg .Org
a i . cout<<x+y; } a i i.O i
das
a l
int call( ) ada
sa l
a sala a sa l a
as al
w. P a . P w. Pad w. Pad w. Pad
ww { www ww ww ww
sum( ); }
O rg O rg rg rg
a i . }a; a i . i.O i.O
asa
l
asa
l
da sala da sala sal
a d void main( )
a d
.Pa .Pa ada
w.P w.P w w w . P
ww ww ); }
{ a.call( ww ww ww
rg rg rg rg
s lai.Oa short note function
11.aWrite
s a i.O
lareturning objects.
s a lai.O s a lai.O al
da da receive object as argument
da and it can also return
da as
w .Pa • Member function
w .Pa w .Pa w .Pa an object. w. Pad
ww Example: ww ww ww ww
O r#include<iostream>
g rg .Org .Org
l a i . using namespace std;lai.O l ai la i
d a sa d a sa da sa d a sa da sal
a a a a a
w w.P 9 Prepared w w.P
By : M.Dhanapal.,
w.P
MCA.,B.Ed 9790573672,
w w.P
Literacy Mission MHSS,Tirupur
w ww.P
w w w w w

l a i .Org l ai .Org la i .Org l a i .Org


a Send Your Questions a sa id - padasalai.net@gmail.com
a al
das das & Answer Keys to our daemail das das
sa lai. sala
i .
www.Padasalai.Net i.
lawww.TrbTnpsc.com
sa salai
.
sal
ada ada ada a d a a da
w w.P w w.P w w.P w w.P w w.P
w w w w w
XI COMPUTER SCIENCE VOLUME II
la i .Org la i .Org l a i .Org l a i .Org
d a sa class test da sa d a sa d asa d a sal
a a a a a
w w.P { w w.P w w.P w w.P ww.P
w w public: w w w
rg int a; rg rg rg
l a i . O int a
set(inti . O
b) a i . O a i . O
d asa {a
d sal d asa
l
d asa
l
d asa
l
a a a a a
w.P w.P a=b; w.P w.P w.P
ww ww }
ww ww ww
i .Org test example(testO
i . c)rg
i.O rg
lai.O
rg
a sala { sa
a d;
la
a sala a s a as al
w. Pad w
ad
.P test w. Pad w. Pad w.Pad
ww ww d.a=c.a; ww ww ww
return d;
i.Org }
i .Org i.Org i .Org
a l a int display() l a l a l a al
a s asa as a
ada
sa as
w. Pad a d
{
w.P cout<<a; w. Pad w .P w. Pad
ww ww ww ww ww
}

la i .Or};g la i .Org l a i .Org l a i.Org


d a sa int main()
d a sa d a sa da sa d a sal
a { a a a a
w w.P test w
e,f;
w.P ww.P w w.P w w.P
w w w w w
e.set(10);
. O g
rf.example(e); .O rg . O rg . O rg
l a i l a i l a i l a i l

Padasalai
a d asa e.display();
a d asa a d asa a d asa a d asa
w.P }
w.P w.P w.P w.P
ww ww ww ww ww
12. What is gdefault constructor?
l a i•.OrA constructor that’slaaccept
i .Orgno parameter is called
l a i rg
.Odefault constructor. l a i .Org
d a sa d a sa d a sa d a sa d a sal
a For Example:.Pa .Pa .Pa .Pa
w w .P w w w w w w w w
w w class test w w w
rg {
la i . O public: l a i .Org l a i .Org l a i .Org
d a sa d asa d a sa d a sa d a sal
a test( a a a a
w w .P w w.P ) w w.P w w.P w w.P
w w { w w w
rg }
l a i . O l a i .Org l a i.Org l a i .Org
d a sa }t;
d a sa d a sa d a sa d a sal
a a constructor? a a a
w w.P 13. What is parameterized w w.P w w.P w w.P w w.P
w w
• A constructor which can takewarguments is called parameterizedw constructor . w
g type of constructor
•.OrThis . O rg to create objectsi.with
helps O rgdifferent initial values. . O rg
l a i l a i a
al function. l a i l
a d asa • This is achieved a d asbya passing parameters a dto
asthe a d asa a d asa
w.P • Declaring w.aPconstructor with arguments w.P hides the compiler .P
wgenerated w.P
constructorw.After
ww ww ww ww w
this we cannot invoke the compiler generated constructor.
For r g
.O Example : .Org .Org .Org
l a i l a i la i la i
d a sa class test
d a sa d a sa d a sa d a sal
a a a a a
w w.P w{w.P ww.P w w.P w w.P
w w w w w
public:
rg rg rg rg
lai.O int A; lai.O lai.O lai.O l
a d asa d asa asa
d Literacy Mission MHSS,Tirupur
d asa dasa
w.P 10 .Pa
Prepared By : M.Dhanapal.,
w .Pa
MCA.,B.Ed 9790573672,
w .Pa w w .P a
ww ww ww ww ww

l a i .Org l ai .Org la i .Org l a i .Org


a Send Your Questions
a sa id - padasalai.net@gmail.com
a al
das das & Answer Keys to our
daemail das das
sa lai. sala
i
www.Padasalai.Net
. i.
lawww.TrbTnpsc.com
sa salai
.
sal
ada ada ada a d a a da
w w.P w w.P w w.P w w.P w w.P
w w w w w
XI COMPUTER SCIENCE VOLUME II
la i .Org la i .Org l a i .Org l a i .Org
d a sa test(int
d a
x)sa d a sa d asa d a sal
a a a a a
w w.P w{w.P w w.P w w.P ww.P
w w w w w
A=x;
i . O rg i . O rg i . O rg i . O rg
l a } l a l a l a l
a d asa }t(5);
a d asa a d asa a d asa a d asa
w.P 14. What is copywconstructer
w.P w.P w.P w.P
ww w and how it’s wwinvoked? ww ww
• rAgconstructor having a referencerg to an already existing rg object of its own iclass rgis called
i . O i . O i . O . O
d a sala copy constructor d a s.ala d a sala d a sala d a sal
a • In other words a a a a
w w.P w w.P Copy Constructor w wis.Pa type of constructorwwhich
w.P is used to create awcopy w.P
w w already existing object of
of an w a class type. w w
• rIt is usually of the form simple (simple&), where simple is the class name. The compiler
l a i .O g l a i .Org l a i .Org l a i .Org
d a sa provides a default
d a saCopy Constructor todallasthe a classes.
d a sa d a sal
a Invoking of .Pa constructor: w.Pa a a
w w.P w wcopy w w w.P w w.P
w o When w an object is passed as a parameter
w to any of thememberw functions w
i.Org ▪ Example void simple::putdata(simple
i .Org x);ai.Or
g
i.Org
d a sala d a sa la
d a sa l
d a sa l a
d a sal
a o When a member a function returns an object a a a
w w.P w w.P w w.P w w.P w w.P
w w
▪ Example simple getdata() w {} w w
. O g
rWhen .O rgreference to an instance . O rgits own class . O rg
la i
o an object is passed
l a i by l a i of l a i l

Padasalai
a d asa a d asa a d asa a dasa a d asa
w.P ▪ For
w.Pexample, simples1, s2(s1); w.P// s2(s1) calls copy constructor
w.P w.P
ww ww ww ww ww
15. Write arg short note on dynamic initialization of objects. rg
l a i .O l a i.Org l a i .O l a i .Org
asa • When the initial asvalues
a are provided during asaruntime then it is called asadynamic as al
a d a d a d a d Pad
w .P .P
initialization.
ww ww
.P
ww
.P w.
ww For Example: w w w ww

l a i .Org #include<iostream>
l a i .Org l a i .Org l a i .Org
asa asa
using namespace std; asa asa s al
a d a d a d a d ada
w .P w.P test
class w.P w.P w .P
ww ww{ ww ww ww

l a i .Org public: i.Org


l a l a i .Org l a i .Org
a a a a al
P a das P a asset(int
dint b)
P a das P a das Pad
as
w. w. { w. w. w.
ww ww ww ww ww
cout<<b;
. O rg } . O rg . O rg . O rg
l a i l a i l a i l a i
asa };asa asa asa sal
a d a d a d a d ada
w.P w.P w.P w.P w . P
ww wwint main() ww ww ww
{
.O r g int x; lai.Or
g .Org .Org
l a i la i la i al
d asa d asa
cout<<"\n Enter the value
d aofsax:"; d asa as
w.P
a a
w.P cin>>x; w.P
a
w.P
a
w. Pad
ww ww ww ww ww
test e;
O r g rg rg rg
lai. lai.O
e.set(x); lai.O lai.O sal
a d asa a d a sa
a da sa
a d a sa
a da
w.P 11 w.P
Prepared By : M.Dhanapal.,
w.P
MCA.,B.Ed 9790573672,
w.P
Literacy Mission MHSS,Tirupur
w.P
ww w w w w w w w w

l a i .Org l ai .Org la i .Org l a i .Org


a Send Your Questions a sa id - padasalai.net@gmail.com
a al
das das & Answer Keys to our daemail das das
sa lai. sala
i
www.Padasalai.Net
. i.
lawww.TrbTnpsc.com
sa salai
.
sal
ada ada ada a d a a d a
w w.P w w.P w w.P w w.P w w.P
w w w w w
XI COMPUTER SCIENCE VOLUME II
la i .Org la i .Org l a i .Org l a i .Org
d a sa da sa d a sa d asa d a sal
a a a a a
w w.P w}w.P w w.P w w.P w w.P
w w w w w
rg rg Part -IV rg rg
l a i . O l a i . O l a i . O l a i . O l
1.saExplain nested class with
a d a a d asaexample. a d asa a d asa a d asa
w.P • Whenwone w.Pclass becomes the member w.Pof another class thenwitw.isPcalled Nested class w and P
w.the
ww w ww
relationship is called containership. w w
Classesrg g
l a i
can be nested in two ways.
.•O By defining a class withinla i .Oranother l a i . Org l a i . Org
d a sa d a sa class
d a sa d a sa d a sal
a • By declaring .Paan object of a class aswa.member
Pa to another class .Pa .Pa
w w.P w w w w w w w
w Defining aw class with in another w w w
• When g a class is declared.Owith
i . O rinner class) and the i
outer
rg inis another
class known
class, the inner
as Enclosingi . O g class is called as Nested
rclass. i . O rgclass (ie the
d a sala • Nested class can d a be
la
sadefined in private as d a
wellsaaslain the public sectiondof a alaEnclosing class. asal
sthe d
w .Pa Example: w .Pa w .Pa w .Pa w .Pa
ww ww#include<iostream> ww ww ww

l a i .Org using namespace


l a i rg
.Ostd; l a i .Org l a i .Org
d a sa class testasa
d d a sa d a sa d a sal
a {w.Pa a a a
w w.P w w w.P w w.P w w.P
w w public: w w w
i . O rg int a=10; rg
i .O i . O rg i . O rg
l a l a l a l a l

Padasalai
intsdisplay()
a d asa a d
{
a a a d asa a d asa a d asa
w.P w.P w.P w.P w.P
ww ww ww
cout<<"\n"<<a; ww ww
s.print();
i . O rg } i .Org i .Org i .Org
sa l a sa l a sa l a sa l a sal
a d a class exam a d a a d a a d a a d a
w w .P { w w.P w w.P w w.P w w.P
w w w w w
public:
.Orintg print() .Org .Org .Org
la i l a i l a i l a i
d a sa { d a sa d a sa d a sa d a sal
a a a a a
w w .P cout<<"\n
w w.Phai ";
w w.P w w.P w w.P
w } w w w w
g
.Or}s; .Org .Org .Org
l a i l a i l a i l a i
d a sa };
d a sa d a sa d a sa d a sal
a int main().Pa a a a
w w.P w w w w.P w w.P w w.P
w { w w w w
test
rg e; rg rg rg
l a i . O e.display(); l a i . O l a i . O l a i . O l
a d asa } a d asa a d asa a d asa a d asa
w.P 2. Mention the w w.P w.P and destructor ww.P w.P
ww w differences between constructor ww w ww
Sno rg Constructorrg rgDestructor
l 1
a i . O Constructor function
l a i .
isOexecuted i .
Destructor
la O function is executed la i .Org
asa sa objects life time dautomatically
awhen asa a
aslife as al
d automatically
d when objects
d
w.P
a
w.P
a a
w.P time ends w.P
a
w. Pad
ww begins
ww ww ww ww
2 Constructor is overloaded Destructor is not overloaded
3i.OrgConstructor have parameter
i. O rg g
i.Ordoesn’t have
Destructor i.Or
g
d a sala d a sala da sala d a sala da sal
a 12 Prepared By : M.Dhanapal.,
a a a a
w w.P w w.P w w.P
MCA.,B.Ed 9790573672,
w.P
Literacy Mission MHSS,Tirupur
w ww.P
w w w w w

l a i .Org l ai .Org la i .Org l a i .Org


a Send Your Questions a sa id - padasalai.net@gmail.com
a al
das das & Answer Keys to our daemail das das
sa lai. sala
i
www.Padasalai.Net
.
sa
i.
lawww.TrbTnpsc.com salai
.
sal
ada ada ada a d a a da
w w.P w w.P w w.P w w.P w w.P
w w w w w
XI COMPUTER SCIENCE VOLUME II
la i .Org la i .Org l a i .Org l a i .Org
d a sa da sa d a sa
parameter d asa d a sal
a a a .Pa a
w w.P 4 w.P is not inherited ww.P Destructor also not
Constructor
w w winherited ww.P
w w w w w
5 Constructor is same name as class Destructor is same name as class
i . O rgname i . O rg name prefixed
i . O rg with ~ tidle i . O rg
l a l a l a l a l
a d asa a d asa a d asa
character
a d asa a d asa
w.P 6 w.Pmany constructor ww.P In a class only one
In a class .P
wdestructor w.P
ww ww w ww ww
3. Define ragclass RESORT with the following
rg description in C++
rg :
l a i .O la i .O l a i .O l a i .Org
d a saPrivate members: dasa d a sa d a sa d a sal
a a a a a
w w.P Rno // Data w w.P to store room number
member w w.P w w.P w w.P
w w w w w
Name //Data member to store user name
a i
Charges
l .Org//Data member tolastore i .Orgper day charge lai.Org l a i .Org
d a sa d a sa d a sa d a sa d a sal
a a ofadays a a
w w.P Days //Data member
w w.P to store the number w w.P w w.P w w.P
w w w
Compute ( ) // A function to calculate total amount as Days
w w

l a .Org and if the


* Charges
i l a i .Org l a i .Org l a i.Org
d a sa//total amount exceeds d a sa11000 then total amount d a sa is 1.02 * d a sa d a sal
a a a a a
w w.P Days *Charges w w.P ww.P w w.P w w.P
w w w w w
Public member:
i . O rg i .O rg i . O rg i . O rg
getinfo(
l a ) // Function to Read
a the information like aname , a
sal l l l

Padasalai
a d asaroom no, charges and a d adays a d asa a dasa a d asa
w.P w.P .P
wwentered details and www
.P w.P
ww dispinfo ( w )w// Function to displaywall ww
total amount
g calculated
l a i .Or l a i. Org l a i . Org l a i . Org
asa
//using COMPUTE function
asa asa asa as al
a d a d a d a d Pad
w .P w.P w.P w.P w.
ww ww ww ww ww
Program:
l a .Org
#include<iostream>
i l a i .Org l a i .Org l a i .Org
asausing namespace std; asa asa asa s al
a d class RESORT w.P a d a d a d ada
w .P w.P w.P w .P
ww { ww ww ww ww
i . O rint
g Rno,Days;
i .Org i .Org i .Org
a l a char name[50]; a l a a la a l a al
P a das P adas
float Charges,total;
P a das P a das Pad
as
w. w.
int compute() w. w. w.
ww ww ww ww ww
{
. O r g
total=Days*Charges; . O rg . O rg . O rg
l a i a i a i a i
asa if(total>11000)asal asa
l
asa
l sal
a d a d a d a d ada
w.P { w.P w.P w.P w . P
ww wwtotal=1.02*Days*Charges; ww ww ww
}
a i .Or}g i.O rg i.O rg i.O rg
a sa l
a sala da sala a sala as al
w .Pad public:
w.Pad w .Pa w. Pad w. Pad
ww int getinfo()
ww ww ww ww
{
r g g :"; i.Org rg
O i.Or
i. cout<<"\n Enter the rno,name,days,charges i.O
sala sala sala s a la sal
P ada 13 a d a a da a d a a da
w . w.P
Prepared By : M.Dhanapal.,
w.P
MCA.,B.Ed 9790573672,
w.P
Literacy Mission MHSS,Tirupur
w.P
ww w w w w w w w w

l a i .Org l ai .Org la i .Org l a i .Org


a Send Your Questions a sa id - padasalai.net@gmail.com
a al
das das & Answer Keys to our daemail das das
sa lai. sala
i .
www.Padasalai.Net sa
i.
lawww.TrbTnpsc.com salai
.
sal
ada ada ada a d a a d a
w w.P w w.P w w.P w w.P w w.P
w w w w w
XI COMPUTER SCIENCE VOLUME II
la i .Org la i .Org l a i .Org l a i .Org
d a sa a sa
cin>>Rno>>name>>Days>>Charges;
d d a sa d asa d a sal
a a a a a
w w.P w.P
compute();
w w w.P w w.P w w.P
w w w w w
}
. O g dispinfo()
rint . O rg . O rg . O rg
l a i l a i l a i l a i l
a d asa {
a d asa a d asa a d asa a d asa
w.P cout<<"\n
w.PRno : "<<Rno; w.P w.P w.P
ww w w
cout<<"\n Name :"<<name; w w w w w w

i . O rcout<<"\n
g Days :"<<Days;rg
i .O i .Org i .Org
l a cout<<"\n Charges :"<<Charges;
la l a l a
d a sa cout<<"\n Total
d a a
sWages:"<<total; d a sa d a sa d a sal
a a a a a
w w.P } w w.P w w.P w w.P w w.P
w w w w w
};
.Orintg main() .Org .Org .Org
l a i l a i l a i l a i
d a sa {
d a sa d a sa d a sa d a sal
a a a a a
w w.P w w.P R;
RESORT
w w.P w w.P w w.P
w w R.getinfo(); w w w
rg R.dispinfo();
l a i . O } l a i .Org l a i .Org l a i .Org
d a
4.
saWrite the output of the d a a
sfollowing d a sa da sa d a sal
a a a a a
w w.P w w.P ww.P w w.P w w.P
w #include<iostream>
w w w w
#include<stdio.h>
i . O rg i .O rg i . O rg i . O rg
using
l a namespace std; l a l a l a l

Padasalai
a d asaclass sub a d asa a d asa a d asa a d asa
w.P { w.P w.P w.P w.P
ww ww ww ww ww
int day, subno;
public
a i .O:rg a i.Org a i .Org i.O rg
d
l
asasub(int,int); // prototype
d asa
l
d asa
l
a sala as al
w .P
a void printsub()w.P a
w.P
a
w. Pad w. Pad
ww w w
{ cout<<" subject number : "<<subno; w w ww ww
cout<<"rgDays : " <<day;
} l a i .O l a i .Org l a i .Org l ai .Org
asa}; asa asa a sa s al
a d a d a d Pad ada
w .P ww
.P sn=12)
sub::sub(intwd=150,int w.P w. w .P
ww ww ww ww
.Org
{ cout<<endl<<"Constructing
g
Or object "<<endl; lai.Or
.the g .Org
a l a i a la i a l a i al
das day=d; das das a sa as
w. P a . P a
w. P a
w. Pad w. Pad
ww sub no=sn;www ww ww ww
}
class i . O rg
stud i . O rg i . O rg i.O rg
l a l a l a sala sal
a d asa{ a d asa a d asa da ada
w.P int rno; www
.P w.P w .Pa w . P
ww ww ww ww
float marks;
public:
a i .Org a i .Org a i .Org i.O rg
d
l
asastud( ) d asa
l
d asa
l
a sala as al
w.P
a a
w.P the object of students
a
w.P "<<endl; w. Pad w. Pad
ww ww
{ cout<<"Constructing ww ww ww
rno=0; g
i .Or
marks=0.0;
l a l a i .Org l ai .Org la i.O rg
s a sa sa s a sal
P ada 14 a d a a da a d a a da
w . w.P
Prepared By : M.Dhanapal.,
w.P
MCA.,B.Ed 9790573672,
w.P
Literacy Mission MHSS,Tirupur
w.P
ww w w w w w w w w

l a i .Org l ai .Org la i .Org l a i .Org


a Send Your Questions a sa id - padasalai.net@gmail.com
a al
das das & Answer Keys to our daemail das das
sa lai. sala
i
www.Padasalai.Net
. i.
lawww.TrbTnpsc.com
sa salai
.
sal
ada ada ada a d a a d a
w w.P w w.P w w.P w w.P w w.P
w w w w w
XI COMPUTER SCIENCE VOLUME II
la i .Org la i .Org l a i .Org l a i .Org
d a sa} d a sa d a sa d asa d a sal
a a a a a
w w.P void getval()w w.P w w.P w w.P w w.P
w w w w w
{
cout<<"Enter
i . O rg the roll number i . O rgthe marks secured ";i.Org
and i . O rg
l a l a l a l a l
a d asacin>>rno>>marks; adasa a d asa a d asa a d asa
w.P } w.P w.P w.P w.P
ww void printdet()w w w w w w w w
{ cout<<"Roll no : "<<rno<<"Marks : "<<marks<<endl; rg
} l a i .Org la i .Org lai.O lai.O
rg
sa s a s a s a as al
da }; da da Pad
a
Pad
w .P a w .Pa w .Pa w. w.
ww class addmission ww { ww ww ww
sub obj;
stud i .O rg
objone; i .Org i .Org i .Org
l a l a l a l a al
d asafloat fees; d asa d asa ada
sa as
w.P
a public : .P a .P a .P w. Pad
ww w ww w ww ww
w
ww
add mission ( )
{ cout<< "Constructing the objectrgof admission "<<endl; rg
l a i .Org lai.O lai.O l a i.Org
s fees=0.0;
a s a s a sa as al
. P ada } . Pada . P ada Pad
a
Pad
w w w w. w.
ww void printdet( ww ) ww ww ww
{ objone.printdet();
O rg
obj.printsub(
i . ); i .O rg i . O rg i.Or
g
l a l a l a l a sal

Padasalai
a d asacout<<"fees : "<<fees<<endla d asa ; a d asa da s a
da
w.P } w.P w.P w.Pa w.Pa
ww ww ww ww ww
};
int a .Org
main()
i a i .Org a i .Org i.O rg
d
l
asa{system("cls"); adasa
l
d asa
l
a sala as al
w .P
a .P w.P
a
w. Pad w. Pad
ww addmission ww
wadm; ww ww ww
cout<<endl<< "Back in main ( )";
return
l a i .Or0;g } l a i .Org l a i .Org l ai .Or g
asaOutput: asa asa a sa s al
a d a d a d Pad ada
w .P w.P w.P w. w .P
ww Constructing wwthe object ww ww ww
Constructing g the object of students
l a i . O
Constructing
r
the object ofl a i .Org
admission l a i .Org l a i .Org
as a as a a s a a sa a sal
w. Pad w.Pa
d
w .Pa
d
w .Pa
d
w .Pa
d
w w Back in main w
w () w w w w w w

i . O rg i . O rg i . O rg i . O rg
l a
5.saWrite the output of the s a
following
l l a l a l
a d a #include<iostream> a d a a a d asa a d asa a d asa
w.P w.P w.P w.P w.P
ww w w
#include<stdio.h> w w w w w w
using namespace std;
a i . Org a i . Org a i . Org i.O rg
d
l
asaclass P d asa
l
d asa
l
a sala asal
w.P
a { public:
w.P
a
w.P
a
w. Pad w. Pad
ww P() w w w w ww ww
{ cout<< rg"\nConstructor of classrPg"; } rg rg
l a i.O l a i.O l ai.O la i.O
s a s a s a s a sal
P ada 15 a d a a da a d a a da
w . w.P
Prepared By : M.Dhanapal.,
w.P
MCA.,B.Ed 9790573672,
w.P
Literacy Mission MHSS,Tirupur
w.P
ww w w w w w w w w

l a i .Org l ai .Org la i .Org l a i .Org


a Send Your Questions a sa id - padasalai.net@gmail.com
a al
das das & Answer Keys to our daemail das das
sa lai. sala
i
www.Padasalai.Net
.
sa
i.
lawww.TrbTnpsc.com salai
.
sal
ada ada ada a d a a da
w w.P w w.P w w.P w w.P w w.P
w w w w w
XI COMPUTER SCIENCE VOLUME II
la i .Org la i .Org l a i .Org l a i .Org
d a sa~ P ( ) da sa d a sa d asa d a sal
a a a a a
w w.P { cout<< w w.P
"\nDestructor of class P "; } w w.P w w.P ww.P
w w w w w
};
i . O rg i . O rg i . O rg i . O rg
class
l a Q l a l a l a l
a d asa{ public: a d asa a d asa a d asa a d asa
w.P w.P w.P w.P w.P
ww Q( ) ww ww ww ww
{ cout<<"\nConstructor of class Qg"; }
O rg .Or .Org rg
~ l Q(
a i . ) la i l a i lai.O al
d asa{ cout<< "\nDestructor d asofaclass Q "; } d asa a s a as
w.P
a
w.P
a
w.P
a
w. Pad w. Pad
ww }; ww ww ww ww
class Rrg
{ lPa i .O obj2;
obj1, l a i .Org l a i .Org l a i .Org
asaQ obj3; asa asa sa as al
a d a d a d ada Pad
w.P w.P w.P w .P w.
ww public: ww ww ww ww
R ( ) rg
{ l a i .O "\nConstructor oflaclass
cout<< i .OrRg ";} l a i .Org l a i.Org
a a a sa al
P a das ~ R ( ) P a das P a das Pad
a
Pad
as
w. w. w. w. w.
ww ww
{ cout<< "\nDestructor of class R ";}ww ww ww
i . O r};g i .O rg i . O rg i.Or
g
l a l a l a l a sal

Padasalai
int main ( )
a d asa a d asa a d asa da s a
da
w.P { w.P w.P w.Pa w.Pa
ww w
R R0;
w w w ww ww

a i .OrQgoq; a i .Org a i .Org i.O rg


d asa
l P op;
d asa
l
d asa
l
a sala asal
w .P
a return 0; .P a .P a
w. Pad w. Pad
ww w ww w ww ww ww
}
i.O rg i.O rg i .Org i .Or g
s a la s a l a sa la sa l a s al
a ada ada a ada
w. Pad .P .P . Pad .P
ww w ww w w w
w ww ww
w
Output:
g
.OrConstructor .Org
of class iP .Org .Org
l a i la la i l a i
d a sa Constructor d sa P
ofaclass d a sa d a sa d a sal
a a a a a
w w.P w.P of class Q
Constructor
w w w.P w w.P w w.P
w w w w w
Constructor of class R
. O g
rConstructor of class iQ
. O rg . O rg . O rg
l a i a a i a i
d asa Constructorad sal P
ofaclass d asa
l
d asa
l
d asa
l
a a a a
w.P w.P of class P
Destructor w.P w.P w.P
ww ww ww ww ww
Destructor of class Q
g
.OrDestructor of classlaRi.Or
g .Org .Org
l a i la i l a i
d a sa Destructor ofd a sa Q
class d a sa d a sa d a sal
a a a a a
w w.P w.P of class P
Destructor
w w w.P w w.P w w.P
w w w w w
Destructor of class P
6. Explain
l a i .Orgabout defining methods
l a i.Orofg class. l a i .Org la i .Org
d a sa d a sa da sa d a sa d a sal
a 16 Prepared By : M.Dhanapal.,
a a a a
w w.P w w.P w w.P
MCA.,B.Ed 9790573672,
w.P
Literacy Mission MHSS,Tirupur
w ww.P
w w w w w

l a i .Org l a i .Org l a i .Org l a i .Org


a Send Your Questions a sa id - padasalai.net@gmail.com
a al
das das & Answer Keys to our daemail das das
sa lai. sala
i .
www.Padasalai.Net i.
lawww.TrbTnpsc.com
sa salai
.
sal
ada ada ada a d a a da
w w.P w w.P w w.P w w.P w w.P
w w w w w
XI COMPUTER SCIENCE VOLUME II
la i .Org la i .Org l a i .Org l ai .Org
d a sa • Member functions da saare the functions thatd a sa
perform specific tasks in
d a
a
a
sclass. Member d a sal
a Pa a a a
w w.P w w.are
functions called as w
methods. w.P w w.P ww.P
w w w w w
• The member functions of agclass can be defined in two g ways.
i . O rg ✓ Insidelathei . O r
class definition i . O r i . O rg
l a l a l a l
a d asa asa the class definition
✓adOutside a d asa a d asa a d asa
w.P o Inside w.P w.P w.P w.P
ww wwthe class definition ww ww ww
o When a member function is defined inside a class, it behaves like inline functions.
.O r g rg member functions.
.OInline .Org .Org
l a i These are called
l a i l a i l a i
d a sa o Example:
d a sa d a sa d a sa d a sal
a a a a a
w w.P w w.P Example
class w w.P w w.P w w.P
w w w w w
{
l a i .Org public: l a i .Org l a i .Org l a i .Org
d a sa d a sa d a sa d a sa d a sal
a int.P
sum(
a ) .Pa .Pa .Pa
w w.P w w w w w w w w
w w { w w w
i.O rg . Org .Or g .Org
a sala }
a salai asa
l ai
a sa l a i
as al
w. Pad }; .Pad
w w. Pad w.Pad w.Pad
ww ww ww ww ww
o Outside
g the class definition
i . O r i . O rg i . O rg i . O rg
la ✓ When Member
al a function defined outside
l a the class just like normall a function l

Padasalai
a d asa d as(Function
definition
a definitions
a d asaare familiar with ) then
you a daitsais be called as a d asa
w.P w.P w.P w.P w.P
ww wwoutline member function ww or non-inline member ww function. Scope resolution ww
operator (::) is used for this purpose. rg
l a i .Org Syntax: l a i.Org l a i .O l a i .Org
dasa d sa a d sa a sa
a sal
a
.Pa .Pa class_name :: function_name
return_type .Pa (parameter ad
.Plist) .Pa
d
w w w w w w
w {w
w ww ww ww
i. O rg function definition i .Org i .Org i .Org
sa la } sa l a sa la sa l a sal
a d a a d a a d a a d a a d a
w w .P w w.P w w.P w w.P w w.P
w w w w w
i.O rExample:
g rg rg .Org
sala class Example
s a lai.O sala
i.O
sa l a i al
a da a a as
w. Pad {w.Pa w. Pad w. Pad w. Pad
ww wwpublic: ww ww ww
rg int sum( ); rg rg rg
a lai.O l a i . O l a i . O l a i . O l
ada
s };
a d asa a d asa a d asa a d asa
w.P w.PExample::sum( ) ww.P
int w.P w.P
ww ww{ w ww ww

l a i .Org }
l a i .Org la i .Org la i .Org
d7.
a saExplain about creating d a sa with example. dasa
objects d a sa d a sal
a .Pa a a .Pa
w w.P ✓ A classw wspecification ww.P
just defines the properties of a wclass. w.P To make use of w aw
class
w w w
specified, the variables of that class type have to be declared.
w w
g class variables are.O
.OrThe rg object. Objects arei.O rg called as instance ofi.class.
Org
i✓ i called also
d a sala d a sala da sala d a sala da sal
a 17 Prepared By : M.Dhanapal.,
a a a a
w w.P w w.P w w.P
MCA.,B.Ed 9790573672,
w.P
Literacy Mission MHSS,Tirupur
w ww.P
w w w w w

l a i .Org l ai .Org la i .Org l a i .Org


a Send Your Questions a sa id - padasalai.net@gmail.com
a al
das das & Answer Keys to our daemail das das
sa lai. sala
i .
www.Padasalai.Net i.
lawww.TrbTnpsc.com
sa salai
.
sal
ada ada ada a d a a d a
w w.P w w.P w w.P w w.P w w.P
w w w w w
XI COMPUTER SCIENCE VOLUME II
la i .Org la i .Org l a i .Org l a i .Org
d a sa ✓ Objects can beda sa in two methods,dasa
created d asa d a sal
a a a a a
w w.P w w.P▪ Global object ww.P w w.P w w.P
w w w w w
▪ Local object
✓ . O g
rGlobal Object : . O rg . O rg . O rg
l a i l a i a i
al function bodies or by al a i l
a d asa d asais declared outsideadallasthe
o If an aobject a d asplacing their namesadasa
w.P w.P .P
ww brace of the class w.P .P
ww as
ww wwimmediately after thewclosing wwdeclaration then it is w called
Global object. These objects can be used by any function in the program
g Object
.OrLocal .Org rg .Org
i✓ i i.O i
d a sala o If an object
d a sa la
is declared with in adfunction
a sala
then it is calleddlocal
a
l a
sa object.It cannot be dasal
a a .Pa a a
w w.P w w.P
accessed from outside the w wfunction. w w.P w w.P
w w w w w
Example:
g
.Or#include<iostream> .Org .Org .Org
l a i l a i l a i l a i
d a sa using namespace
d a a
sstd; d a sa d a sa d a sal
a a a a a
w w.P class P
w w.P w w.P w w.P w w.P
w w w w w
{
la i .Org int a; lai.O
rg
lai.O
rg
lai.O
rg
a sa sa s a s a as al
Pad Pada
public:
P ada P ada Pad
w. w .
int display() www
. w . w.
ww ww ww ww
{
i.O rg i .O rg i . O rg i . O rg
cout<<"\n enter the value:";
sala l a l a l a sal

Padasalai
da d asa cin>>a; d asa dasa da
w .Pa w.P
a
w.P
a
w.P
a
w.Pa
ww ww cout<<"\nwwEntered value is "<<a;ww ww
}
a i .Or};g i.O rg i.O rg rg
i.O
sa l ala ala sala al
Pad
a P b; → Globala objectdas a das Pa da
Pad
as
w . w.P w.P w. w.
ww w
int main()
w w w ww ww
i . O r{g i .Org i .Org i .Org
sa la P c;→local sa l a
object sa la sa l a sal
a d a a d a a d a a d a a d a
b.display();
w w .P w w.P w w.P w w.P w w.P
w w c.display(); w w w
}
l a i .Org l a i .Org l a i .Org l a i .Org
d
8.
a saExplain about how the d aobjects
sa are passed to functiond a sa arguments. d a sa d a sal
a .Paalso be passed as arguments a to a member function a .Pa
w w.P • Objectswcan
w w w.P w w.P just like any other w wdata
w typewof C++.Objects can also be w passed in both ways w w
rg (1) Pass By Value rg rg rg
l a i . O (2) Pass By i .
Reference
l a O l a i . O l a i . O l
a d asaPass By Value adasa a d asa a d asa a d asa
w.P w.P .P
ww the function creates w.P w.P
ww • When wwan object is passed bywvalue wwits own copy of the object ww and
i . O rworks
g on it. Therefore anyg changes made to the object
i . O r i . O rg inside the function i . O rdo
g not affect
d a sala the original object. d a sala d a sala d a sala d a sal
a Example: .Pa a a a
w w.P w w ww.P w w.P w w.P
w #include<iostream>
w w w w
#include<stdio.h>
l a i .Org namespace std; lai.Org l ai .Org l a i .Org
sa using sa sa sa sal
P ada 18 .Pa
d a
.Pa
a
d Literacy Mission MHSS,Tirupur
.Pa
d a a da
ww
. Prepared By : M.Dhanapal.,
w MCA.,B.Ed 9790573672,
w w w.P
w ww ww ww w w

l a i .Org l ai .Org la i .Org l a i .Org


a Send Your Questions
a sa id - padasalai.net@gmail.com
a al
das das & Answer Keys to our
daemail das das
sa lai. sala
i .
www.Padasalai.Net i.
lawww.TrbTnpsc.com
sa salai
.
sal
ada ada ada a d a a da
w w.P w w.P w w.P w w.P w w.P
w w w w w
XI COMPUTER SCIENCE VOLUME II
la i .Org la i .Org l a i .Org l a i .Org
d a sa class P d a sa d a sa d asa d a sal
a a a a a
w w.P { w w.P w w.P w w.P ww.P
w w w w w
int a;
i . O rg i . O rg i . O rg i . O rg
l a public: l a l a l a l
a d asa int d asa x)
assign(int
a a d asa a d asa a d asa
w.P w.P w.P w.P w.P
ww ww{ ww ww ww
g a=x;
l a i.Or } la i.Org l a i .Org lai.O
rg
a sa asa a al
das int.P ada
printing(P a1, P a2) d Pad
a s
Pad
as
w .P a w w.P
a
w. w.
ww ww{ ww ww ww
rg a1.a=20;
l a i.O a2.a=30; salai.
Org l a i .Org l a i .Org
a s a a asa sa as al
Pad a d
cout<<"\n Changed Value a d
"<<a1.a; ada Pad
w. w.P w.P w .P w.
ww wwcout<<"\n Changed Value"<<a2.a;
ww ww ww
}
la i .Org lai.O
rg rg
lai.O l a i.Org
a sa }; sa s a sa as al
Pad int main() w.Pa
da Pad
a
Pad
a
Pad
w . w. w. w.
ww { ww ww ww ww
i . O rPgc,b,d; i .O rg i.O rg i.Or
g
la b.assign(10); asal a sala l a sal

Padasalai
a d asa d da da s a
da
w .P .Pa
c.assign(10);
w w.Pa w .Pa w.Pa
ww ww
d.printing(b,c); ww ww ww
}.Org .Org .Org rg
i i i i.O
a sala a sala a sa l a
a sala as al
w . Pad • .
Pass BywReferencePad . Pad . Pad . Pad
ww w w w ww w ww w ww
• When an object is passed by reference , its memory address is passed to the

la i.Org function so the O


l a i rg function works directly
. called la i .Org on the original lobject
a i .Orgused in the
a sa sa So any changes made
functionacall. a stoa the object inside thedafunction
sa definition are asal
a d d
a in original object. .Pa d a ad
w .P w.P
reflected w w.P w.P
ww ww ww ww ww

a i .Org lai.O
rg i.O rg i .Org
a
l
saExample: s a sala sa l a
as al
Pad ada Pad
a
Pad
a
Pad
w . #include<iostream> w.P w. w. w.
ww w
#include<stdio.h>
w ww ww ww
using i . O rg
namespace std; i . O rg i.O rg i.O rg
l a l a sala sala sal
a d asaclass P a d asa da da ada
w.P { w.P w .Pa w .Pa w . P
ww ww ww ww ww
int a;
r g
.O public: .Org rg rg
a i a i i.O i.O
d asa
l l
asa x)
int assign(int
d da sala a sala asal
w.P
a
w.P
a
w .Pa w. Pad w. Pad
ww ww{ ww ww ww
a=x;
O r g rg .Or g rg
lai. } lai.O l ai la i.O
sal
a d asa a d a sa
a da sa
a d a s a
a da
w.P 19 w.P
Prepared By : M.Dhanapal.,
w.P
MCA.,B.Ed 9790573672,
w.P
Literacy Mission MHSS,Tirupur
w.P
ww w w w w w w w w

l a i .Org l ai .Org la i .Org l a i .Org


a Send Your Questions a sa id - padasalai.net@gmail.com
a al
das das & Answer Keys to our daemail das das
sa lai. sala
i
www.Padasalai.Net
. i.
lawww.TrbTnpsc.com
sa salai
.
sal
ada ada ada a d a a da
w w.P w w.P w w.P w w.P w w.P
w w w w w
XI COMPUTER SCIENCE VOLUME II
la i .Org la i .Org l a i .Org l a i .Org
d a sa int a sa &a1, P &a2)
printing(P
d d a sa d asa d a sal
a a a a a
w w.P w{w.P w w.P w w.P ww.P
w w w w w
a1.a=20;
i . O rg i . O rg i . O rg i . O rg
l a a2.a=30; l a l a l a l
a d asa d
cout<<"\n
a asaChanged Value "<<a1.a;
a d asa a d asa a d asa
w.P w.P w.P w.P w.P
ww wwcout<<"\n Changed Value"<<a2.a;
ww ww ww
g }
};lai.O
r
a i.Org i.O rg
lai.O
rg
das
a
da sa l
a sala a s a as al
w .P a int main()
w .Pa Pad
w. Pad
w. Pad
w.
ww { ww ww ww ww
i . O rPgc,b,d; i .Org i .Org i .Org
sa l a b.assign(10); sa l a sa l a sa l a sal
a d a a d a a d a a d a a d a
c.assign(10);
w w.P w w.P w w.P w w.P w w.P
w w
d.printing(b,c); w w w
} rg g
i.Or
lai.O about invocationsaoflaconstructors. l a i .Org l a i .Org
d
9.saExplain
a d a d a sa d a sa d a sal
a • There are a ways to create an object a Pa a
w w.P w w.Ptwo
w w.P using parameterized w w.constructor w w.P
w w
• Implicit call w w w
i . O rg • Explicit call i.Org i . O rg i . O rg
a
l • Implicit call sal a al a l a l

Padasalai
a d asa • In this
a d a
method ,the parameterized
a d asconstructor is invokeda d asa
automatically a d asa
w.P w.P ww
.P w.P w.P
ww wwwhenever an object iswcreated. ww ww
• Explicit call
l a i .Org • In this method l a i Orgname of the constructor
.,the l a i .Orisg explicitly given tolainvoke
i .Org the
d a sa a sa constructor so that
parameterized
d d a a object can be createdasand
sthe d
a initialized .
d a sal
a a .Pa suitable method asw Pa a
w w .P w.P call method is the
• wExplicit w wmost w it.creates a temporary object,
w w.P
w w w w w
the chance of data loss will not arise. A temporary object lives in memory as long
a i .Org as it is being a used
i .Oring an expression. After a i .O rgit gets destroyed. i.Org
this
d a sa l
Example: d a sa l
d a sa l
d a sala d a sal
a a a a a
w w .P w w.P
#include<iostream> w w.P w w.P w w.P
w w w w w
using namespace std;

l a i .Org class simple


l a i .Org l a i .Org l a i .Org
d a sa {
d a sa d a sa d a sa d a sal
a private: .Pa a a a
w w.P w w a;
int w w.P w w.P w w.P
w w w w w
public:
i . O rg simple(int m)ai.Or
g
i . O rg i . O rg
l a l l a l a l
a d asa {
a d asa a d asa a d asa a d asa
w.P w.m
a= P; w.P w.P w.P
ww wwcout<< "\n Constructorwofwclass-simple invoked for ww w w
implicit and explicit call"<<endl;
}
l a i .Org void putdata()l a i .Org la i .Org la i .Org
d a sa { d a sa d a sa d a sa d a sal
a a .Pa a a
w w.P w w.P
cout<<"\nThe integers are...
w w"<<a<<endl; w w.P w w.P
w w } w w w

lai .Or};g .Org .Org .Org


sa s alai s alai s alai sal
ada a d a a da a d a a da
w w.P 20 Prepared w w.P
By : M.Dhanapal.,
w.P
MCA.,B.Ed 9790573672,
w w.P
Literacy Mission MHSS,Tirupur
w ww.P
w w w w w

l a i .Org l ai .Org la i .Org l a i .Org


a Send Your Questions a sa id - padasalai.net@gmail.com
a al
das das & Answer Keys to our daemail das das
sa lai. sala
i
www.Padasalai.Net
. i.
lawww.TrbTnpsc.com
sa salai
.
sal
ada ada ada a d a a da
w w.P w w.P w w.P w w.P w w.P
w w w w w
XI COMPUTER SCIENCE VOLUME II
la i .Org la i .Org l a i .Org l ai .Org
d a sa int a
main()
d sa d a sa d asa d a sal
a Pa a a a
w w.P w{w. w w.P w w.P ww.P
w w simple s1(10); //implicit w call w w
i . O rg simple s2=simple(30);
i . O rg //explicit call i . O rg i . O rg
l a sal a
cout<<"\n\t\tObject 1\n"; sal a sal a sal
a d asa a d a
s1.putdata(); a d a a d a a d a
w.P w.P w.P w.P w.P
ww wws2.putdata(); ww ww ww
return 0;
i . O rg } i .Org i .Org i .Org
l a
saExplain about characteristic la l
sa of constructor anddadestructors.
sa a sa l a sal
a d a
10. d a d a d a
w.P Characteristics
Paconstructor:
w.of w.P
a
w.P
a
w.P
a
w w w w w w w w w w
• The name of the constructor must be same as that of the class
g
•.OrNo return type can lbe Org for constructor
.specified .Org .Org
l a i a i l a i l a i
d a sa • A constructordcan a sahave parameter list dasa d a sa d a sal
a a a a a
w w.P w w.P
• The constructor function can be w w.P
overloaded w w.P w w.P
w w w w
• They cannot be inherited but a derived class can call the base class constructor
w
•.OrTheg compiler generates g
.Oarconstructor, .Org of a user definedlaconstructor.
in the absence .Org
l a i l a i l ai i
d a sa • Compiler generated d a sa constructor is public d a sa
member function
da sa d a sal
a a is executed automatically a when the object is.Pcreateda a
w w.P w w.P
• The constructor
ww.P w w w w.P
w w
• A constructor w
can be used explicitly to create new object w of its class type w
Characteristics
rg of Destructor: rg rg rg
la i . O a i .O a i . O a i . O
salthe same name as that l l character ‘~’. l

Padasalai
a d asa • The destructor a d ahas a d asofa the class prefixed abydathe
satilde
a d asa
• The destructor
w.P w.P cannot have arguments w.P w.P w.P
ww w
• It has no return type
w w w w w w w
• rDestructors
g cannot be overloaded
rg i.e., there can beronly g one destructor in.O a class
rg
l a i
• .O In the absence of user
l a i . O
defined destructor, it is
l a i . O
generated by the compilerl a i
a sa • The destructor a s a a s a a s a a s al
d d d d d
w .P
a
scope
.Pa isthe
wdestroy
to
executed automatically
object w.P
a when the control reaches
w.P
a the end of class .Pa
w
w w w w w w w w ww
• They cannot be inherited
i.O rg i.O rg i .Org i .Org
s a la s a l a sa la sa l a s al
a ada da Best
Allathe a ada
w. Pad w.P w.P w. Pad w .P
ww ww ww ww ww
i.O rg rg rg .Org
sala s a lai.O sala
i.O
sa l a i al
a ada a a as
w . Pad w.P w.Pad w. Pad w. Pad
ww w w ww ww ww
rg rg rg rg
s a lai.O sala
i.O
sala
i.O
sala
i.O
sal
ada .Pa
da
.Pa
da
.Pa
da ada
w.P w w w w . P
ww ww ww ww ww
i.O rg i.O rg i.O rg i.O rg
a sala a sala da sala asala as al
w. Pad w. Pad w .Pa w. Pad w. Pad
ww ww ww ww ww
i.Org i.Org i .Or g
i.O rg
s a l a s a l a sa l a s a la sal
P ada 21 a d a a da a d a a da
w . w.P
Prepared By : M.Dhanapal.,
w.P
MCA.,B.Ed 9790573672,
w.P
Literacy Mission MHSS,Tirupur
w.P
ww w w w w w w w w

l a i .Org l ai .Org la i .Org l a i .Org


a Send Your Questions a sa id - padasalai.net@gmail.com
a al
das das & Answer Keys to our daemail das das
sa lai. sala
i
www.Padasalai.Net
. i.
lawww.TrbTnpsc.com
sa salai
.
sal
ada ada ada a d a a d a
w w.P w w.P w w.P w w.P w w.P
w w w w w

la i .Org l a i .Org l a i .Org l a i .Org


a sa a sa a sa asa a sal
w w w.P
a d

l a i . O
HSC I FIRST YEAR
rg
w w w.P
a d

l a i . O rg
w w w.P
a d

l a i . O rg
w w w.P
a d

l a i . O rg
w w w.P
a d

l
a d asa a d asa a d asa a d asa a d asa
w.P w.P w.P w.P w.P
ww ww ww ww ww

l a i .Org la i .Org l a i .Org l a i .Org


d a sa d a sa d a sa d a sa d a sal
a a a a a
w w.P w w.P w w.P ww.P w w.P
w w w w w

11
i.O rg i.O rg i.Org i .Org
s a l a s a l a s a l a sa l a al
a a a ada as
w. Pad w. Pad w. Pad w .P w. Pad
ww ww ww ww ww
i.O rg rg .Or g .Org
sala a lai.O l ai l a i al
a da s asa a sa as
w . Pad w .Pa w. Pad w. Pad w. Pad
ww ww ww ww ww
i.O rg i.O rg i.O rg i.Or
g
sala sala sala l a sal

Padasalai
s a
da da da da da
ww
w .Pa

rg
ww
w .Pa
COMPUTER SCIENCE rg
ww
w.Pa

.Org
ww
w .Pa

rg
ww
w.Pa

i.O i.O i i.O


a sala a sala a sa l a
a sala as al
w . Pad w. Pad w. Pad w. Pad w. Pad
ww ww ww ww ww
i.O rg i.O rg i .Org i .Org
s a la s a l a sa la sa l a s al
a ada ada a ada
Pad Pad
w.P
VOLUME –II
w. w .P w. w .P
ww ww ww ww ww
rg rg rg .Org
a lai.O a lai.O sala
i.O
sa l a i al
as ada
s a a as
Pad Pad Pad Pad
w.P
LESSON 15
w . w. w. w.
ww w w ww ww ww
i . O rg i . O rg i.O rg i.O rg
l a l a sala sala sal
a d asa da sa da da ada
w .P w .Pa w .Pa w .Pa w . P
ww ww ww ww ww
i.O rg i.O rg i.O rg i.O rg
a sala a sala da sala asala asal
w. Pad w. Pad w .Pa w. Pad w. Pad
ww ww ww ww ww
i.O rg i.O rg i .Or g
i.O rg
s a l a s a l a sa l a sal s a la
d Prepared By : M.Dhanapal.,
a d a MCA.,B.Ed., 9790573672
da Literacy Mission
d a da
a a a a a
w w.P MHSS,Tirupur w w.P w w.P w w.P w.1P
Page
w
w w w w w

l a i .Org l ai .Org la i .Org l a i .Org


a Send Your Questions a sa id - padasalai.net@gmail.com
a al
das das & Answer Keys to our daemail das das
sa lai. sala
i .
www.Padasalai.Net i.
lawww.TrbTnpsc.com
sa salai
.
sal
ada ada ada a d a a da
w w.P w w.P w w.P w w.P w w.P
w w w w w

la i .Org l a i .Org l a i .Org l a i .Org


a sa a sa a sa asa a sal
a d a d LESSON
a d 15 a d a d
w w.P w w.P w w.P w w.P ww.P
w w w w w
rg rg POLYMORPHISM rg rg
l a i . O l a i . O l a i . O l a i . O l
a d asa a d asa Part
a d asa
–II a d asa a d asa
w.P w.P w.P w.P w.P
ww ww ww ww ww
1. What is function overloading?
i .O✓ rg The ability of thei.function
Org to process the i rg
.Omessage or data in i
more .Orgthan one
sa l a sa la sa l a sa l a sal
a d a a d a
form is.Pcalled a
as function overloading.d a a da a d a
w w.P w w w w.P w w.P w w.P
w ✓ In w other words functionw overloading means two w or more functions win the
i.Org same scope sharei.O rgsame name but their
the
i
g
.Orparameters are different.
i .Org In this
s a l a l a
safunctions that sharedathe l a
sa same name are said l a
stoa be overloaded dasal
da situation, dthe
a d a
a a a a a
w.P and w .Pprocess
the is called w.P overloading. ww.P
function w.P
ww w w w w w w w
2. List the g operator that cannotgbe overloaded.
l a i O r
. ✓ Operator that are l a i .Or overloaded are follows l a i .Org l a i .Org
d a sa d a sa not
d a sa d a sa d a sal
w.P • scope operator
a a ::a a a
w w.P w w w.P w w.P w w.P
w w • sizeof w w w
. O rg • member . O rg selector . . O rg . O rg
l a i l a i l a i l a i l

Padasalai
a d asa a d a• samember pointer selector a d asa * a dasa a d asa
w.P ww
.P • ternary operator .P
ww ?: ww
.P
ww
.P
ww w w w
3. class add{ int x; public: add(int) }; Write an outline definition for the constructor. w

l a i .Org add ::add(int y) l a i.Org l a i .Org l a i .Org


a sa a s a a s a a s a a s al
a d { a d a d a d a d
w w .P w w.Px=y; w w.P w w.P w w.P
w w w w w
.Org .Org .Org .Org
}
l a i l a i l a i l a i
d a a Does the return type
s4. d a saof a function help d sa
inaoverloading a function?
d a sa d a sal
a .Pa return type of woverloaded .Pa .Pa not considered w a
w w .P ✓ No, w wThe w functions w ware w for.P
w w w w w
overloading same data type.
5. aWhat
l i .Orgis the use of overloading
l a i .Org a function? lai.Org l a i .Org
d a sa ✓ Function d a sa
overloading is not d
only a a
simplementing d a sa
polymorphism but also d a sal
a a a a a
w w.P w w.Pthe number of comparisons
reduces w w.P in a program w w.Pmakes the program
and w wto.P
w w w w w
i . O rg execute faster. i.Org i . O rg i . O rg
l a ✓ It also helpsasthe a
al programmer by reducing l a sal a l
a d asa a d a d asa the number ofafunction
a d
names to
a d asa
w.P w.P
bewremembered. w.P w.P w.P
ww w ww ww ww
6. What is overloaded resolution?
i .O✓rg The process of i.selecting Org the most i .Org
appropriate overloaded i Org
.function or
s a l a s a l a s a la s a la sal
d a d a d a d a d a
w.Pa .Pais called overload resolution.
operator
w w .Pa w .Pa w .Pa
ww ww ww ww ww
i.O rg i.Org i .Org
i.O rg
s a l a s a l a sa l a s l
sal
a a
d Prepared By : M.Dhanapal.,
a d a MCA.,B.Ed., 9790573672
da Literacy Mission
d a da
a a a a a
w w.P MHSS,Tirupur w w.P w w.P w w.P w.2P
Page
w
w w w w w

l a i .Org l ai .Org la i .Org l a i .Org


a Send Your Questions a sa id - padasalai.net@gmail.com
a al
das das & Answer Keys to our daemail das das
sa lai. sala
i
www.Padasalai.Net
. i.
lawww.TrbTnpsc.com
sa salai
.
sal
ada ada ada a d a a da
w w.P w w.P w w.P w w.P w w.P
w w w w w

la i .Org la i .Org l a i .Org l ai .Org


d a a
s7. What is da
overloaded
a
sfunction? d a sa d a sa d a sal
a .Pa Pa a a
w w.P ✓ w
The w
term overloading w
meansw.name having two orw w.P distinct meaning.ww.P
more
w w w w w
i.O rg Then function have i . O
more
rg than one distinct i . O
meaning
rg is called overloaded
i . O rg
d a sala function. asal
d
a
d asa
l a
d asa
l a
d asa
l
a a a a a
w.P w.P signature?
8. What is function w.P w.P w.P
ww ww ww ww ww
✓ The functions that share the same name are said to be overloaded and the
l a i .Org process is calledlafunction
i .Org overloading.laThe i
g
.Ornumber and typesl a i
of .O a
rg
function's
d a sa d a sa d a sa da sa d a sal
a a are called the function's
parameters a signature. a a
w w.P w w.P w w.P ww.P w w.P
w 9. Write the w syntax of the operator w overloading function.w w
i.Org i.O rg i.Org i .Org
s a l a s a l a s a l a sa l a al
a a a ada as
w. Pad w. Pad w. Pad w .P w. Pad
ww ww ww ww ww
i.O rg rg .Or g .Org
sala a lai.O l ai l a i al
a da s asa a sa as
w . Pad w .Pa w. Pad w.Pad w. Pad
ww ww ww ww ww
i.O rg i.O rg i.O rg i.Or
g
sala sala sala l a sal

Padasalai
s a
da da da da da
w .Pa w .Pa w.Pa w .Pa w.Pa
ww ww ww ww ww
rg rg Part –III .Org rg
i.O i.O lai i.O
d a sala d a sala d a sa d a sala
d a sal
a 1. What are the a a a a
w w .P w w.P rules for functionwoverloading?
w.P w w.P w w.P
w w overloaded functionwmust differ in the number
✓ The w of its arguments or w data

la i.Org types. l a i .Org la i .Org ai .Org


d a sa ✓ The returndatypesa of overloaded functions
d a sa is not considered d a
l
safor overloading dasal
a .Pa type. a a a
w w .P same
w wdata w w.P w w.P w w.P
w w w w
✓ The default arguments of overloaded functions are not considered as part of w

l a i .Org the parameter list l a i


g
Orfunction
.in overloading.
l a i .Org a i .Org
d a sa2. How does a compiler d a sa decide as to which d a safunction should be dinvoked
a
l
sa when there dasal
a .Pa a a a
w w.P are many
w wfunctions? w.P
Give an example.
w w w.P w w.P
w w w w w
✓ When you call an overloaded function, the compiler determines the most
i . O rg appropriate definition
i . O rg to use, by comparing i . O rg the argument types i . O g have
ryou
l a l a a
al parameter typesasspecified al a l
a d asa asa the function with
used toadcall a d asthe a d in the adasa
w.P ww
.P
definitions. w.P w.P w.P
ww w ww ww ww
✓ The process of selecting the most appropriate overloaded function or
l a i .O g operator is called
r
l a i rg
.Ooverload resolution.la i .Org la i .Org
d a sa Example: d a sa d a sa d a sa d a sal
a a a a a
w w.P w w.Pfloat area(int radius); w w.P → w w.P
area(5); w w.P
w w w w w
float area(int length, int breadth); → area(5,6);
i.O rg i.O rg i .Or g
i.O rg
s a l a s a l a sa l a sals a la
d Prepared By : M.Dhanapal.,
a d a MCA.,B.Ed., 9790573672
da Literacy Mission
d a da
a a a a a
w w.P MHSS,Tirupur w w.P w w.P w w.P w.3P
Page
w
w w w w w

l a i .Org l ai .Org la i .Org l a i .Org


a Send Your Questions a sa id - padasalai.net@gmail.com
a al
das das & Answer Keys to our daemail das das
sa lai. sala
i
www.Padasalai.Net
.
sa
i.
lawww.TrbTnpsc.com salai
.
sal
ada ada ada a d a a d a
w w.P w w.P w w.P w w.P w w.P
w w w w w

la i .Org la i .Org l a i .Org a i .Org


d a sa3. What is operator da a
soverloading? Give d a
somesa example of operators d a
l
sa which can be dasal
a a a a a
w w.P w w.P
overloaded. w w.P w w.P w w.P
w w w w w
✓ rgThe term operator overloading
rg is giving additionalrg functionality to an
rg
l a i . O l a i . O l a i . O l a i . O l
operator.
a d asa a d asa a d asa a d asa a d asa
w.P ✓ Overloaded
w.P operator are +,++,-,--,*,-=,+=,*=,
w.P etc., w.P w.P
ww w w w w
4. Discuss the benefit of constructor overloading? w w w w

l a i OrgA class can havela


.✓ more
i.Orgthan one constructor
l a i rg different signature.
.Owith l a i .Org
d a sa ✓ Constructordaoverloading
sa sa
providesdaflexibility of creating
da a
smultiple type of dasal
a Paa class. a a a
w w.P w.for
objects
w w w.P ww.P w w.P
w w w w
5. class sale ( int cost, discount ;public: sale(sale &); Write a non inline definition w

l a i Orgconstructor specified;
.for l a i .Org l a i .Org l a i .Org
d a sa d a sa
sales::sales(sales &a) d a sa d a sa d a sal
a .Pa .Pa .Pa .Pa
w w.P w w w w w w w w
w w{ w w w
.Org .Org .Org .Org
cost=a.cost;
l a i l a i l a i l a i
d a sa d sa
discount=a.discount;
a d a sa d a sa d a sal
.Pa }ww.P
a .Pa .Pa .Pa
w ww w ww w ww w ww w
i.O rg i.O rg Part-IV i.O rg i.Or
g
sala sala sala l a sal

Padasalai
s a
. P ada 1. What are the
. P da for operator overloading?
arules . P ada .Pa
da
.Pa
da
w w w w w
ww ww ww ww ww
✓ rgPrecedence and Associativity rg of an operator cannotrg be changed.
l a i .O
✓ l a i. O l a i . O l a i .Org
d a sa No new operators
d a sa can be created, only
d a
existing
sa operators can
d a
be
sa overloaded.
d a sal
a ✓ Cannot .redefine
a the meaning of an
a operator’s procedure. a You cannot change.Pa
w w .P w wP w w.P w.P w
w w integers are added. Only
how w additional functions w
w can be to an operatorww
✓ rgOverloaded operators rcannot g have default arguments.
rg g
la i .✓
O l a i . O la i .Oleft l ai Oran
.be
d a sa When binary
d a
operators
sa are overloaded,
d a sa the hand object
d a
must
sa object
d a sal
a .Pa class.
of thewrelevant a a a
w w .P w w w.P w w.P w w.P
w ✓ Operator
w w
that are not overloaded are follows w w
rg • scope
.Org .Org .Org
operator ::
i.O i i i
d a sala d a
la
• sasizeof
d a sa la
d a sa l a
d a sal
a a a a a
w w.P w w.P • member selector w w.P . w w.P w w.P
w w • member pointer w selector * w w
i . O rg • ternaryi . O rgoperator ?: i . O rg i . O rg
l a l a l a l a l
a d asa a d asa a d asa a d asa a d asa
w.P 2. Answerwthe w.Pquestion (i) to (v) after w.Pgoing through the wfollowing
w.P class. w.P
ww w ww w ww
class
rg Book rg rg rg
s a lai.O sa lai .O
sala
i.O ala i.O al
ada { da d a das Pad
as
w .P w .Pa w .Pa w .Pa w.
ww w
int BookCode
w ww
; char Bookname[20];float fees; ww ww
rg
public:
i.O i.O rg i .Org
i.O rg
s a l a s a l a sa l a s a la sal
d Prepared By : M.Dhanapal.,
a d a MCA.,B.Ed., 9790573672
da Literacy Mission
d a da
a a a a a
w w.P MHSS,Tirupur w w.P w w.P w w.P w.4P
Page
w
w w w w w

l a i .Org l ai .Org la i .Org l a i .Org


a Send Your Questions a sa id - padasalai.net@gmail.com
a al
das das & Answer Keys to our daemail das das
sa lai. sala
i .
www.Padasalai.Net sa
i.
lawww.TrbTnpsc.com salai
.
sal
ada ada ada a d a a d a
w w.P w w.P w w.P w w.P w w.P
w w w w w

la i .Org la i .Org l a i .Org l a i .Org


d a sa Book( ) //Function da sa1 d a sa d asa d a sal
a a a a a
w w.P w w.P w w.P w w.P w w.P
w { w w w w
i . rg
fees=1000;
O i . O rg i . O rg i . O rg
l a l a l a l a l
a d asa BookCode=1;adasa a d asa a d asa a d asa
w.P w.P w.P w.P w.P
ww w w
strcpy (Bookname,"C++"); w w w w w w

i.O} rg .Org i.O rg rg


sala sa la i
sala s alai.O al
a da C) //Function 2 Pada a as
w. Pad void display(float
w .Pa w. w. Pad w.Pad
ww { w w w w ww ww
rg .Org .Org
cout<<BookCode<<":"<<Bookname<<":"<<fees<<endl;
i.O i i i .Org
a l a l a l a l a al
a s asa asa asa as
w. Pad } P
w.
a d P a d
w. P a d
w. w. Pad
ww w w
~Book( ) //Function 3 w w w w w w

la i .{Org l a i .Org l a i .Org l a i.Org


d a sa cout<<"End ofdBook a sa Object"<<endl; dasa d a sa d a sal
a a a a a
w w.P w w.P w w.P w w.P w w.P
w } w w w w
i . rg (int SC,char S[ ],float
Book
O i .O rg F) ; //Function 4 i.Org i . O rg
l a l a l a l a l

Padasalai
a d asa }; a d asa a d asa a dasa a d asa
w.P w.P w.P w.P w.P
ww w w w w w w
(i) In the above program, what are Function 1 and Function 4 combined together w w

i.O rg
referred as?
i.O rg i .Org i.O rg
d a sala
Answer: d a sala d asa l a
d a sala d a sal
a a a a a
w w .P w w.P w w.P w w.P w w.P
w w
constructors. function 1 referswdefault constructor and w function 4 refers w

la .Org
parameterized
i constructor
l a i .Org l a i .Org a i .Org
d a sa(ii) Which concept d a sais illustrated by Function3?
d a sa When is d
thisa
l
safunction called/ dasal
a a a a a
w w .P w w.P
invoked? w w.P w w.P w w.P
w w w w w

l a .Org Destructor. la
Answer:
i When
i .Org an instance of la i Org goes out special
.scope l a i .Orgfunction
d a sadestructor gets executed.
d a sa d a sa d a sa d a sal
a .Pa a a a
w w.P (iii) Whatw w
is the use of Function3?w w.P w w.P w w.P
w w w w w
g g g g
ala i.Or Destructor function
Answer: i.Or will de-allocate the
ala i.Ormemory of an object
ala i.Or ala
as a s a s a s sal
ad (iv) .Pa
Write the d
statements ad function1 and .function2
in main to.Pinvoke Pad ada
w.P w w w w . P
ww intww
main( ) ww ww ww
{
l a i .OrgBook b,c1(2,”C++”,185.6);
l a i .Org la i .Org l a i .Org
d a sa d a sa d a sa d a sa d a sal
a a
b.display(150.6); a a a
w w.P w w.P w w.P w w.P w w.P
w } w w w w

l a i .Org l a i .Org l a i .Org la i .Org


d sa
Prepared
a d a sa MCA.,B.Ed., 9790573672
By : M.Dhanapal., da sa Literacy Mission
d a sa da sal
a a a a a
w w.P MHSS,Tirupur w w.P w w.P w w.P w.5P
Page
w
w w w w w

l a i .Org l a i .Org l a i .Org l a i .Org


a Send Your Questions a sa id - padasalai.net@gmail.com
a al
das das & Answer Keys to our daemail das das
sa lai. sala
i
www.Padasalai.Net
. i.
lawww.TrbTnpsc.com
sa salai
.
sal
ada ada ada a d a a da
w w.P w w.P w w.P w w.P w w.P
w w w w w

la i .Org l a i .Org l a i .Org l a i .Org


d a sa(v) Write the definition
da sa for Function4. dasa d asa d a sal
a a a a a
w w.P w
Book(intw.P
SC,char S[ ],float w
F)w.P w w.P ww.P
w w w w w
{rg rg rg rg
l a i . O l a i . O l a i . O l a i . O l
fees=F;
a d asa a d asa a d asa a d asa a d asa
w.P w.P
BookCode=SC; w.P w.P w.P
ww ww
Bookname=S;
ww ww ww

l a i .O}rg la i.Org l a i .Org l a i .Org


a sa3. Write the output a saof the following dprogram.
a sa a s a a s al
a d ad a d
Refer thePaquestion Book backPa d
w w.P w w.P w w.P w. w.
w w (3) in part -IV
progam w ww ww

l a i Org
.Seminar starts now lai.Or
g
l a i .Org l a i .Org
d a sa Welcome to Seminar d a sa d a sa d a sa d a sal
a .Pa a a a
w w.P Recap w
of wPrevious Seminar w w.P
Content w w.P w w.P
w w w w w
Lectures in the seminar on
l a i Org of thanks
.Vote la i .Org l a i .Org l a i.Org
d a sa Vote of thanksdasa d a sa da sa d a sal
a a a a a
w w.P Vote ofw w.P
thanks ww.P w w.P w w.P
w w w w w
rg the program (Refer
4. i.Debug
O i .O rgthe program in page i . O rg 260,Q/No : 4) i.Org
no
a
al Sno a
alcode a
al Resaon la l

Padasalai
a s a s
Error a s a s aCorrect Code asa
a d a d a d a d a d
w.P 1 ww
.P
charstr[20]; w.PData type and variable w.P char str[20]; ww.P
ww w ww ww w
are separated by
rg i.Or
g r g .Org
sa lai.O sa l a whitespace
sa l a i .O
sa l a i
sal
ada 2 a d a
void accept_string a d a
Parenthesis missing ina d a
void a d a
w .P w.P w.Pthe function prototype w.P accept_string(w) w.P
ww w w w w w w w
3 String operator *(String x) Overloaded operator is String operator +
i.O rg i .Org + i .Org (String i .O
x)
rg
s a la sa l a l a
sa to declare the dasa l a sal
a da 4 String.Ps;ada No
a d aneed d a
w .P w w.Pobject. Becauseww .Pa w.P
a
ww w w w w w it is w w
un-used in the program
l a i .5Org strcpy(s.str,str);l a i .Org No needl a i .Org l a i .Org
da sa d a sa d a sa d a sa d a sal
a 6 a
strcat(str,str); a
Right hand sidea strcat(str,x.str); .Pa
w.P w.P w.P w.P w
ww w w w w argument is mentioned w w ww
rg rg wrongly rg rg
a lai.7O l
Header file smissinga i . O
While a i . O
l using strcat #include<string.h>
l a i . O l
ada
s
a d a a a d asa a d asa a d asa
w.P w.P w.Pfunction we must .P
wuse w.P
ww ww ww string.h header file w w w w
8 rg
.Org
No need Org
.Org
goto s;
i.O i i . i
sala 9 } sa l a Class la
sanot terminated da};sa l a sal
.P ada a d a a d a
Pa cout<< a d a
ww
10 w.P
cout>>
w ww.Pcout object use w w.<< w w.P
w w w operator w w
i.Org i.Org i .Org
i.O rg
s a l a s a l a sa l a s a la
sal
d Prepared By : M.Dhanapal.,
a d a MCA.,B.Ed., 9790573672
da Literacy Mission
d a da
a a a a a
w w.P MHSS,Tirupur w w.P w w.P w w.P w.6P
Page
w
w w w w w

l a i .Org l ai .Org la i .Org l a i .Org


a Send Your Questions a sa id - padasalai.net@gmail.com
a al
das das & Answer Keys to our daemail das das
sa lai. sala
i
www.Padasalai.Net
. i.
lawww.TrbTnpsc.com
sa salai
.
sal
ada ada ada a d a a da
w w.P w w.P w w.P w w.P w w.P
w w w w w

la i .Org la i .Org l a i .Org l a i .Org


d a sa 11 Str3=str1+str2; d a sa d
Swapa sathe two coding dacout<<”\n\n
sa d a sal
a a a a a
w w.P w w.P
cout<<”\n\n Concatenated w w.P w w.P Concatenated ww.P
w w w w w
string is”; string is”;
i . O rg i . O rg i . O rg i . O rg
l a l a l a Str3=str1+str2;
l a l
a d asa a d asa a d asa a d asa a d asa
w.P ww
.P w.PNo need w.P w.P
ww 12 w str3.display_string(); ww ww ww
5. Refer rg the page no :261i.O and
rg Q/A:5
l a i . O la l a i . Org l a i . Org
d a a
si.Mention d sa will have the scope
the objectsawhich
d a sa till the end of thedprogram.
a sa d a sal
a a a a a
w w.P Ans: ob,ob1
w w.P w w.P w w.P w w.P
w w w w w
ii. Name the object which gets destroyed in between the program
l a i Org ob
.Ans: l a i .Org l a i .Org l a i .Org
d a sa Name the operator
iii. d a sawhich is over loaded d a a write the statement
sand d a a invokes it.
sthat d a sal
a Pa a a a
w w.P Ans: ==w w.and ob==ob1; w w.P w w.P w w.P
w w w w w
iv. Write out the prototype of the overloaded member function
l a i Org void comp::operator
.Ans: l a i .Org==(comp ob) lai.Org l a i .Org
d a sv.a What types of d a sa
operands are used for the
d a sa
overloaded operator? d a sa d a sal
a .Pa operand and type a a a
w w.P Ans: user
w wdefined w w.Pof operator is binary-relational
w w.P operator w.P
(==)
w
w w w w w
vi.Which constructor will get executed? Write the output of the program
i . O rg i .O rg i . O rg i . O rg
l a Ans: Constructor : ldefault
a constructor is executed
l a in this program l a l

Padasalai
a d asa Output : a d asa a d asa a d asa a d asa
w.P w.P w.P w.P w.P
ww w w
Enter First String:computer w w w w w w

l a i Org Second String:laScience


.Enter i .Org l a i .Org l a i .Org
d a sa Strings are notdEqual a sa d a sa d a sa d a sal
a a a a a
w w .P 6. Explain w w.P function overloading
about w w.Pwith example. ww.P w w.P
w w w w w
Function
rg Overloading: rg rg
l a i . O
✓ l a i O
.function l a i .Omessage l a i .Orgthan one
d a sa The ability
d
of
a sa the to process
d a sa the or data
d a
in
sa more
d a sal
a a a a a
w w .P formwis.Pcalled
w w.P
as function overloading.
w w w.P w w.P
w ✓ In w other words functionw overloading means two w or more functions win the

l a i .Org same scope share l a i .O rgsame name but their


the l a i
g
.Orparameters are different.
a i .Org In this
d a sa situation, d a
the safunctions that sharedathe sa same name are said d a
l
stoa be overloaded dasal
a .Pa .Pa .Pa .Pa
w w.P w w w w w w w w
w w the process is calledwfunction overloading. w
and w
i . rg
Function
O Signature : rg
i . O i . O rg i . O rg
l a ✓ The functions l a l a a
l and the l
a d asa a d asathat share the same a d asa are said to be overloaded
name
a d asa a d asa
w.P w.Pis called function woverloading.
process w.P The number .P types of a function's
wand w.P
ww ww w ww ww
parameters are called the function's signature.
O r g
.Overloaded .Org .Org .Org
l a i resolution:l a i la i la i
d a sa d a sa d a sa d a sa d a sal
a ✓ The process a of selecting the amost appropriate overloaded a function or.Pa
w w.P w w.P w w.P w w.P w
w w
operator is called overload w resolution. w ww
i.Org i.Org i .Or g
i.O rg
s a l a s a l a sa l a s a la
sal
d Prepared By : M.Dhanapal.,
a d a MCA.,B.Ed., 9790573672
da Literacy Mission
d a da
a a a a a
w w.P MHSS,Tirupur w w.P w w.P w w.P w.7P
Page
w
w w w w w

l a i .Org l ai .Org la i .Org l a i .Org


a Send Your Questions a sa id - padasalai.net@gmail.com
a al
das das & Answer Keys to our daemail das das
sa lai. sala
i
www.Padasalai.Net
. i.
lawww.TrbTnpsc.com
sa salai
.
sal
ada ada ada a d a a da
w w.P w w.P w w.P w w.P w w.P
w w w w w

la i .Org la i .Org l a i .Org l ai .Org


d a sa Rules : da sa d a sa d a sa d a sal
a .Pa a Pa a
w w.P ✓ w
The woverloaded function w w.Pdiffer in the number
must w w.of its arguments or ww.P
data
w w w w w
. O r g types. . O rg . O rg . O rg
l a i ✓ The return typel a i
of overloaded l
functions a i is not considered l
for a i overloading l
a d asa same a
data d asa
type. a d asa a d asa a d asa
w.P w.P w.P w.P w.P
ww w w w
✓ The default arguments of overloaded functions are not considered as part of
w w w w w

i rg the parameter listi.in


.OExample: Org
function overloading. rg
i .O i .Org
sa l a sa la sa l a sa l a sal
a d a ad a a d a a d a a d a
w w.P w.P
#include<iostream>
w w w.P w w.P w w.P
w w
#include<string.h> w w w
i rg namespace std;i.Org
.Ousing i .Org i .Org
sa l a a l a
sy,int sa l a sa l a sal
a d a int sum(int d a
x,int z) d a d a d a
w.P w .Pa w .Pa w .Pa w .Pa
w w { w w w w w w w w

i . O rg return x+y+z; i.Org i .Org i.Org


sa l a } sa l a sal a sa l a sal
a d a a d a a d a a d a a d a
w w.P w.Px1,int y1)
int sum(int
w w w.P w w.P w w.P
w w w w w
{
i . O rg i .O rg i . O rg i . O rg
l a return x1+y1; l a l a l a l

Padasalai
a d asa } a d asa a d asa a dasa a d asa
w.P w.P w.P w.P w.P
ww w w
int main() w w w w w w

i.O {rg i.Org i .Org i .Org


d a sala a sa l
cout<<sum(4,5,6)<<endl;
d
a
d a sa l a
d a sa l a
d a sal
a a a a a
w w .P w.P
cout<<sum(5,6);
w w w.P w w.P w w.P
w w w w w
return
i . O rg 0; i .Org i .Org i .Org
sa la } sa l a sa l a sa l a sal
a d a d a d a d a d a
w .P Output:w.Pa w.P
a
w.P
a
w.P
a
w w w w w w
15 w w w w
i .O11rg i .Org i .Org i .Org
l a
sa7. Explain about operator l a
sa overloading with a la
sexample. sa l a sal
a d a d a d a d a d a
w.P Pa
w.term
a
w.P refers to givingwadditionalw.P
a
wto.P
a
w w ✓ w w
The operator w
overloading,
w w functionality w w
rg the normal C++ operators
rg like +,++,-,—,+=,-=,*.<,>.
rg rg
a i . O ✓ a i . O a i . O a i . O
a s al It is also a
a s al
type of polymorphism
a s al
in which an operator
a s al
is overloaded to
asa
l
a d give a
userd defined meaning to a
it.d a d a d
w.P w.P w.P w.P w.P
ww ww
✓ Operator ww
that are not overloaded are follows ww ww
• scope roperator ::
a i .Org a i .O g a i .Org a i .Org
a sa l • sasizeof
a
l
a sa l
a sa l
a sal
a d a d ad a d a d
w w.P w w.P • member selector ww.P . w w.P w w.P
w w • member pointer w selector * and ternary w operator ?: w
i.Org i.Org i .Org
i.O rg
s a l a s a l a sa l a s a la
sal
d Prepared By : M.Dhanapal.,
a d a MCA.,B.Ed., 9790573672
da Literacy Mission
d a da
a a a a a
w w.P MHSS,Tirupur w w.P w w.P w w.P w.8P
Page
w
w w w w w

l a i .Org l ai .Org la i .Org l a i .Org


a Send Your Questions a sa id - padasalai.net@gmail.com
a al
das das & Answer Keys to our daemail das das
sa lai. sala
i
www.Padasalai.Net
. i.
lawww.TrbTnpsc.com
sa salai
.
sal
ada ada ada a d a a da
w w.P w w.P w w.P w w.P w w.P
w w w w w

la i .Org la i .Org l a i .Org l a i .Org


d a sa Operator Overloading da sa Syntax d a sa d a sa d a sal
a a a a a
w w.P w w.P w w.P w w.P ww.P
w w w w w
returnType classname :: Operator Operator Symbol (argument list)
i . O rg i . O rg i . O rg i . O rg
l a { l a l a l a l
a d asa \\ Function body a d asa a d asa a d asa a d asa
w.P w.P w.P w.P w.P
ww } ww ww ww ww
r g r g rg rg
lai.O
Restrictions ai.O
on OperatorlOverloading
sala
i.O lai.O al
d asa das
a a a s a as
w. P a
✓ Following
w .Pa are some restrictions w.Pad to be kept in
Pad
w. Pad
w.
ww ww ww wwmind while implementing ww
operator overloading.
r g rg .Org cannot be changed. .Org
l a i . O • Precedence land a i .OAssociativity i
of anlaoperator l a i
d a sa • No new d a sa
operators can be d a
created, saonly existing operators d a sacan be d a sal
a a a a a
w w.P w w.P
overloaded. w w.P w w.P w w.P
w w w w w
i . O rg • Cannot redefine i . O
the
rg meaning of an operator’s
i . O rg procedure. You i .
cannot
O rg
sa l a change howsa laintegers are added.Onlysa l a additional functions sa l
cana be to an sal
a d a a
operatord a a d a a d a a d a
w w.P w w.P w w.P w w.P w w.P
w •w Overloaded operatorswcannot have default arguments. w w
i . O rg • When binary operators i .O rg are overloaded,Othe
i . rg left hand object must i . O rgbe an
l a a
al relevant class l a l a l

Padasalai
a d asa object ofasthe
a d a d asa a d asa a d asa
w.P Example: w.P w.P w.P w.P
ww ww #include<iostream> ww ww ww

l a i .Org l a .Org
#include<string.h>
i l a i .Org l a i .Org
d a sa using
d a sanamespace std; dasa d a sa d a sal
a a a a a
w w .P w w.Pclass example ww.P w w.P w w.P
w w { w w w

la i .Org public:
l a i .Org l a i .Org l a i .Org
d a sa d a sa int x; d a sa d a sa d a sal
a a int getdata()ww.Pa a a
w w .P w w.P w w.P w w.P
w w { w w w

l a i .Org l a i
g
.Orcout<<"\n Enter thei.xOvalue
l a
rg : ";
l a i .Org
d a sa d a sa cin>>x; d a sa d a sa d a sal
a a a a a
w w.P w w.P } w w.P w w.P w w.P
w w w
example operator -();
w w
i . O rg }e; i . O rg i . O rg i . O rg
l a l a l a l a l
a d asa a asa example::operator-()
example
d a d asa a d asa a d asa
w.P w.P { w.P w.P w.P
ww ww ww ww ww
x=-x;
.O r g r g
.O cout<<"\n value of X g overloading is =.O"<<x;
.Orafter rg
l a i l a i la i la i
d a sa d a sa} d a sa d a sa d a sal
a a a a a
w w.P w w.Pint main() w w.P w w.P w w.P
w w w w w
{
i.Org i.Org i .Or g
i.O rg
s a l a s a l a sa l a s a la
sal
d Prepared By : M.Dhanapal.,
a d a MCA.,B.Ed., 9790573672
da Literacy Mission
d a da
a a a a a
w w.P MHSS,Tirupur w w.P w w.P w w.P w.9P
Page
w
w w w w w

l a i .Org l ai .Org la i .Org l a i .Org


a Send Your Questions a sa id - padasalai.net@gmail.com
a al
das das & Answer Keys to our daemail das das
sa lai. sala
i
www.Padasalai.Net
. i.
lawww.TrbTnpsc.com
sa salai
.
sal
ada ada ada a d a a da
w w.P w w.P w w.P w w.P w w.P
w w w w w

la i .Org la i .Org l a i .Org l a i .Org


d a sa da sa
e.getdata(); d a sa d asa d a sal
a a a a a
w w.P w w.P-e; w w.P w w.P ww.P
w w w w w
return 0;
i . O rg i . O rg i . O rg i . O rg
l a } l a l a l a l
a d asa Output: a d asa a d asa a d asa a d asa
w.P w.P w.P w.P w.P
ww ww ww ww ww
i.O rg .Org i.O rg rg
sala sa la i
sala s alai.O al
a da a a as
w. Pad w .Pa w. Pad w. Pad w. Pad
ww ww ww ww ww
i.O rg i.O rg i.Org i .Org
s a l a s a l a s a l a sa l a al
a a a ada as
w. Pad w. Pad w. Pad w .P w. Pad
ww ww ww ww ww
i.O rg rg .Or g .Org
sala a lai.O l ai l a i al
a da s asa a sa as
w . Pad w .Pa w. Pad w. Pad w. Pad
ww ww ww ww ww
i.O rg i.O rg i.O rg i.Or
g
sala sala sala l a sal

Padasalai
s a
da da da da da
w .Pa w .Pa w.Pa w .Pa w.Pa
ww ww ww ww ww
i.O rg i.O rg i .Org i.O rg
a sala a sala a sa l a
a sala as al
w . Pad w. Pad w. Pad w. Pad w. Pad
ww ww ww ww ww
i.O rg i.O rg i .Org i .Org
s a la s a l a sa la sa l a s al
a ada ada a ada
w. Pad w.P w .P w. Pad w .P
ww ww ww ww ww
i.O rg rg rg .Org
sala s a lai.O sala
i.O
sa l a i al
a ada a a as
w . Pad w.P w. Pad w. Pad w. Pad
ww w w ww ww ww
rg rg rg rg
s a lai.O sala
i.O
sala
i.O
sala
i.O
sal
ada .Pa
da
.Pa
da
.Pa
da ada
w.P w w w w . P
ww ww ww ww ww
i.O rg i.O rg i.O rg i.O rg
a sala a sala da sala a sala asal
w. Pad w. Pad w .Pa w. Pad w. Pad
ww ww ww ww ww
i.O rg i.O rg i .Or g
i.O rg
s a l a s a l a sa l a sal s a la
d Prepared By : M.Dhanapal.,
a d a MCA.,B.Ed., 9790573672
da Literacy Mission
d a da
a a a a a
w w.P MHSS,Tirupur w w.P w w.P w w.P Page
w w10.P
w w w w w

l a i .Org l ai .Org la i .Org l a i .Org


a Send Your Questions a sa id - padasalai.net@gmail.com
a al
das das & Answer Keys to our daemail das das