Professional Documents
Culture Documents
UNIT - II
Syllabus:
PART – A
A function that has access to the private member of the class but is not itself
a member of the class is called friend functions.
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 1
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
Polymorphism is the ability to take more than one form. An operation may
exhibit different behaviors in different. The behavior depends upon the type
of data used. Polymorphism is of two types. They are
Function overloading
Operator overloading
Function overloading means we can use the same function name to create
functions that perform a variety of different tasks.
i. int add( int a, int b); //add function with 2 arguments of same type
ii. int add( int a, int b, int c); //add function with 3 arguments of same type
iii. double add( int p, double q); //add function with 2 arguments of different
type
//Function calls
C++ has the ability to provide the operators with a special meaning for a
data type. This mechanism of giving such special meanings to an operator is
known as Operator overloading. It provides a flexible option for the creation
of new definitions for C++ operators.
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 2
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
function body
12. How will you overload Unary & Binary operator using member
functions?
When binary operators are overloaded using member functions, it takes one
explicit argument. Also the left hand side operand must be an object of the
relevant class.
13. How will you overload Unary and Binary operator using Friend
functions?
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 3
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
When unary operators are overloaded using friend function, it takes one
reference argument (object of the relevant class) When binary operators are
overloaded using friend function, it takes two explicit arguments.
op object_name or object_name op
Operator op (x);
Operator op (x , y)
16. List out the operators that cannot be overloaded using Friend
function.
Assignment operator =
Function call operator ( )
Subscripting operator [ ]
Class member access operator (.)
17. What is meant by casting operator and write the general form of
overloaded casting operator.
{
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 4
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
Conversion from basic data type to class type can be done in destination
class. Using constructors does it. Constructor takes a single argument
whose type is to be converted.
class time
int hrs,mins;
public:
………….
mins =t % 60;
};
Using Type Casting operator, conversion from class to basic type conversion
can be done. It is done in the source class itself.
double sum=0;
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 5
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
for(int I=0;I<size;I++)
sum=sum+v[ i ] *u[ i ] ;
objX is the object of class X and objY is an object of class Y. The class Y type
data is converted into class X type data and the converted value is assigned
to the obj X. Here class Y is the source class and class X is the destination
class.
Eg:
Base class
Derived class
Here class A is the base class from which the class D is derived. Class D is
the public derivation of class B hence it inherits all the public members of B.
But D cannot access private members of B.
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 6
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
If a class is derived from more than one base class, it is called multiple
inheritance.
Derived class
If a number of classes are derived from a single base class then it is called
hierarchical inheritance.
If a class is derived from a class, which in turn is derived from another class,
is called multilevel inheritance. This process can be extended to any number
of levels.
Eg:
Intermediate
Multilevel inheritance
Multiple inheritance
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 7
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
The class result will have both the multilevel and multiple inheritances.
Student
Student
Test
Result
Sports
A class that serves only as a base class from which derived classes are
derived. No objects of an abstract base class are created. A base class that
contains pure virtual function is an abstract base class.
Eg: Processing of students‟ results. Assume that class sports derive the roll
number from class student. Class test is derived from class Student. Class
result is derived from class Test and sports.
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 8
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
PART - B
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 9
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
Definition:
Syntax:
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 10
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
Example:
{ y = - y;
int x; z = -z;
int y; }
public: {
x=a; S.display( );
y=b; return 0;
z=c; }
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 11
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
{ S: X = 10 Y = -20 Z= 30
cout<<”y=”<<y<<” “;
cout<<”z=”<<z<<”\n “;
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 12
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
Definition: “Friend functions may be used in the place of member functions for
overloading a binary operator, the only difference being that a friend function
requires two arguments to be explicitly passed to it, while a member function
requires only one.”
Example:
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 13
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
};
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 14
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
Refer Q.No:4
// operator function {
out<<s.a;
return out; }
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 15
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
6. Write a C++ program that takes two values of time (hr, min, sec) and output
their sum using constructors and operator overloading (Nov/Dec 2009)
PROGRAM:
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 16
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 17
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
7. Write a C++ program that takes (x,y) co-ordinates of two points and output
the distance between them using constructors. Nov/Dec 2009
PROGRAM:
`
8. Explain Type conversion using suitable C++ coding
Type Conversion
o Definition: “when constants and variables of different types are
mixed in an expression. An assignment operation can be applied for
automatic type conversion. The type of data to the right of an
assignment operator is automatically converted to the type of the
variable on the left is called as type conversion”
o User defined conversion
o Wrapper class
o Built –in data type conversion
User Defined conversion
o Definition: When we need to convert between different types, we can
guide the complier how to convert from one type to another by writing
operator function or constructor.
Wrapper Class
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 18
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
To convert data from a basic types to a user-defined type, the conversion function
should be defined in user-defined object‟s class in the form of the constructor.
Syntax
constructor(Basic Type)
……………..
……………..
It converts the data members of an object to basic data types and returns a basic
data item.
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 19
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
Syntax:
Operator typename()
----
PROGRAM
#include<string.h> #include<iostream.h>
class Cartesian; {
{ double y;
public: {
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 20
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
{ double
ta=polarpoint.getangle();
return radius;
x=tr*cos(ta);
}
y=tr*sin(ta);
double getangle()
}
{
operator polar()
return angle;
{
}
double ta=atan(x/y);
void show()
double tr=sqrt(x*x+y*y);
{
return polar(tr,ta);
cout<<”(“<<radius<<”,”<<angle<
<”)\n”; }
} void show()
}; {
cout<<”(”<<x<<”,”<<y<<”)\n”;
};
TEMPLATE
Definition:
”C++ supports a mechanism known as templates to implement the concept of
generic programming. Template allows us to generate a family of classes or family
of function to handle different data type. Template classes and function illuminate
code duplication for different types and thus make program development easier and
manageable”.
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 21
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
Two specifications:
1. Class template
2. Function template
1. Function Template
Definition:
” The generic function outlined by specification of a generic type using template
keyword. The actual function is defined later using the template”.
Format:
template<class T>
return type function name (arguments of typeT)
{
//
//body of the function with type T
//wherever appropriate
};
Where template is a keyword , typename T is a template data type.
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 22
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 23
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 24
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
Output:
5 is bigger
3.4 is bigger
B is bigger
Mohit is bigger
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 25
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 26
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 27
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
};
Note:
A class created from a class template is called template class.
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 28
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
insert!"; cout<<mystack.pop()<<"\n";
} cout<<mystack.pop()<<"\n";
else stack <char>yourstack;
{ mystack.push(„n‟);
stack array[stack mystack.push(„o);
pointer]=value; cout<<mystack.pop()<<"\n";
stack pointer ++; cout<<mystack.pop()<<"\n";
}
} }
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 29
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
value) cout<<mystack.pop()<<"\n";
stack <char>yourstack;
{
mystack.push(„n‟);
if (stack pointer==9)
mystack.push(„o);
{
cout<<mystack.pop()<<"\n";
cout<<"stack overflow! can't insert!";
cout<<mystack.pop()<<"\n";
}
else
}
{
stack array[stack pointer]=value;
stack pointer ++;
}
}
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 30
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
Output
x:12
y:b
x:c
y:Rohit
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 31
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 32
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
Inheritance:
Definition:
The mechanism of deriving a new class from an old one is called inheritance
(or) derivation.
The new class is referred as base class and new one is called derived or sub-
class.
Base class:
Derived or sub-class:
Single inheritance
Multiple inheritance
Hierarchical inheritance
Multilevel inheritance
Hybrid inheritance
1. Single Inheritance
Definition:
Single class is derived from a single base class. The derived class may inherit
all or partial properties of base class.
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 33
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
Syntax
//data members
//member functions
};
//data members
//member functions
};
Example
class A.
……………
……………
};
class B : public A
…………
…………
};
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 34
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
Program
//single.cpp
void ReadData( ) {
{ Student S1;
} Name : Rohit
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 35
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
}; Sex :M
{ Branch : CSE
private:
int Rollno;
char *Branch;
public:
void ReadData( )
Person::ReadData( );
cout<< “Roll no : “;
cin>>Rollno;
cout<<”Branch :”;
cin>>Branch;
2. Multiple inheritances
Refers to the act of derivation of a single class from several base classes.
A B
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 36
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
Syntax
Example
class A
……………..
……………..
};
class B
……………..
…………….
};
……………
……………
};
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 37
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
Program
void DisplayData( ) }
{ void DisplayData( )
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 38
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
{ }
protected: };
int Sub2Marks; {
public: Result r;
{ r.TotalMarks( );
cin>>Sub1Marks; }
}; Subject1 Marks: 96
Subject2 Marks: 95
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 39
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
3. Multilevel inheritance
Syntax:
class Base-class-name
};
};
};
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 40
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
Program
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 41
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
}; };
{ Exam e;
private: e.ReadData( );
char *Branch; }
public: Output
{ Sex :M
Person::ReadData( ); Age : 21
//Calling base class member
Roll no: 1234
function
Branch : CSE
cout<< “Roll no : “;
Marks Scored in Subject1:75
cin>>Rollno;
Marks Scored in Subject2:78
cout<<”Branch :”;
Name : Rohit
cin>>Branch;
Sex :M
}
Age : 21
void DisplayData( )
Roll no: 1234
{
Branch : CSE
Person::DisplayData( );
//calling base class member Marks Scored in Subject1:75
function
Marks Scored in Subject2:78
cout<<”Roll no:<<Rollno<<endl;
Total Marks scored: 153
cout<<”Branch :<<Branch<<endl;
};
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 42
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
4. Hierarchical inheritance
B C D
The traits of one class may be inherited by more than one class.
Syntax
class Base-class-name
-----------
};
-----------
};
………..
};
5. Hybrid inheritance
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 43
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
B C
Syntax:
class Base-class-name1
………….
};
…………
};
class Base-class-name2
…………
};
………….
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 44
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
Derivation of a class from other derived classes, which are derived from the
same base class, is called multipath inheritance.
B C
D
Example:
{ {
………. ……….
}; };
{ {
………. ………
}; };
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 45
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
12. Write a C++ program for virtual base class (Multipath Inheritance).
Definition:
Derivation of a class from other derived classes, which are derived from the
same base class, is called multipath inheritance.
Grand
Parent
Parent1 Parent2
B C
Child
D
Example:
{ {
………. ………
}; };
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 46
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
#include<conio.h> {
class A int s;
{ };
int p; {
}; D obj;
public:
int r;
};
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 47
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
Public Derivation
Private Derivation
Protected Derivation
Inheriting class in a way that public and protected members of the base
class retain their status in the derived class
Syntax:
Class base
};
};
The members of the base class are called the derivation known as public
derivation and consist of the following:
1. The public members of the base class are treated as public members of the
derived class.
3. If we have defined some members as protected in the base class, they are
available as protected in the derived class.
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 48
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
PROGRAM:
Inheriting class in a way that a public and protected member of the base
class becomes private members of the derived class.
Class base
{
body of the base
};
Class derived: private base
{
body of the derived
};
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 49
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
The members of the base class are called the derivation known as private
derivation and consist of the following:
1. Public members of the base class are treated as private members of the
derived class.
2. Like public derivation, private members of base class are inherited and thus
not available to derived.
3. If we have defined some members as protected in the base class, they are
available as private in the derived class.
PROGRAM:
Inheriting class in a way that a public and protected member of the base
class becomes protected members of the derived class.
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 50
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
Syntax:
Class base
{
body of the base
};
Class derived: protected base
{
body of the derived
};
The derivation is called protected derivation. The base class elements are
treated as follows:
1. The public members of the base class are treated as protected members of
the derived class.
3. If we have some members as protected in the base class, they are available
as protected in the derived class.
PROGRAM:
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 51
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
14. Write a C++ program handling the following details for students and staff
using inheritance. Student details: Name, address and percentage of marks,
Staff details : Name, address and salary. Create appropriate base and derived
classes. Input the details and output them (Nov/Dec 2010)
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 52
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
Polymorphism
Polymorphism
Runtime
Compile Time
Overview
Pointer object
This pointer
Virtual Functions
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 53
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
1. Introduction
Function overloading:
A single function name can be used for various purposes (with different
arguments)
Operator overloading:
Runtime polymorphism
2. Pointer object
Advantages
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 54
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
3. This Pointer
Definition
The name “this” is a keyword. The pointer this allows to access the current object
only.‟ This‟ pointer is used within a method to access an object member. It is also
used to return the address of the current object.
Program
#include<iostream> A disp( )
#include<conio> {
using namespace std; return *this;
class A //returns the address of an object
{ }
private: };
int x; void main( )
public: {
A( ) {} A(10);
A(int a) A a1,a2;
{ a2=a1.Disp( );
this->x=a; }
//accessing data member
}
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 55
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
VIRTUAL FUNCTIONS:
Definition:
Explanation:
The class has an additional storage requirement when atleast one virtual
function is defined inside.
Virtual table:
Note:
The virtual table may also be created when we use run time type information [
RTTI ].
The function in the derived class must have same name as of the virtual
function defined in the base class and the same prototype.
The function in the derived class need not be preceded by the virtual
keyword.
The virtual function must be defined in the base class, it may have an empty
body.
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 56
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
Program:
Virtual Destructors
Syntax
class shape
public:
};
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 57
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
The function in the derived class must have same name as of the virtual
function defined in the base class and the same prototype.
The function in the derived class need not be preceded by the virtual
keyword.
The virtual function must be defined in the base class, it may have an
empty body.
Program
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 58
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
Default arguments to virtual function works, when you supply explicit value
to replace the default value
Program
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 59
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
Program:
C++ allows you to create a special kind of virtual function called a pure
virtual function (or abstract function) that has no body at all! A pure
virtual function simply acts as a placeholder that is meant to be redefined by
derived classes.
Syntax
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 60
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
Program
ABSTRACT CLASS:
Definition:
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 61
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
Example
// Virtual function.
void NonAbstractMemberFunction2();
};
Introduction
Contained objects are said to have a part-of relationship with the container
objects
Example:
class Engine
{
………
};
Class Car
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 62
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
{
…….
Engine e; //composition of object of the class engine
};
Program:
Inheritance Composition
Inheritance is a derivation of Containing an object of class
properties of existing class into another class
into a new class
The relationship between the “has-a” or “part-of”
classes is “is-a”relationship. relationship
E.g Vehicle Scooter
E.g Face[Nose]
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 63
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
PART – A
PART - B
1. Create classes that contain one data member. Overload all the four
arithmetic operators so that they operate on the objects of that class.
[Nov/Dec 2011]
Refer-Q-No: 1
2. Describe the syntax of the different forms of inheritance in
C++.[Nov/Dec 2011]
Refer-Q-No: 11
3. What are virtual functions? Explain with a suitable program. [Nov/Dec
2011]
Refer-Q-No: 15
4. What is dynamic binding? How is it achieved? [Nov/Dec 2011]
Refer-Q-No: 15
5. Write a C++ program to implement C= A+B, C=A-B and C=A*B where A,B
and C are objects containing a int value (vector). [May/Jun 2012]
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 64
Mailam Engineering College, Mailam.
Department of Information Technology
(CS2311/U-II)
Refer-Q-No: 1
6. Explain run time polymorphism with example program. [May/Jun 2012]
Refer-Q-No: 15
7. Explain about the implementation of runtime polymorphism in C++
with an example. [Nov/Dec 2012]
Refer-Q-No: 15
8. Explain the types of inheritance with example. [Nov/Dec 2012]
Refer-Q-No: 11
9. Explain the usage of template in C++.[Nov/Dec 2012]
Refer-Q-No: 9 & 10
10. Explain how left shift and right shift operator are overloaded with an
example. [Nov/Dec 2012]
Refer-Q-No: 4
11. Write a C++ program using operator overloading to add two time values
in the format HH:MM:SS to the resulting time along with rounding off
when 24 hours is reached. A time class is created and operator + is
overloaded to add the two time class objects. [May/Jun 2013]
Refer-Q-No: 6
12. Explain in detail about friend function in C++ with example. [May/Jun
2013]
Refer-Q-No: 3 and 2 mark Refer_Q-No:2
11. What is multiple inheritances? Discuss the syntax and rules of
multiple inheritances in C++. How can you pass parameters to the
constructors of base classes in multiple inheritances? Explain with
suitable example. [May/Jun 2013]
Refer-Q-No: 13
12. What is the difference between a virtual function and a pure virtual
function? Give example of each. [May/Jun 2013]
Refer-Q-No: 15
13. Explain friend function with an example. [Nov/Dec 2013]
Refer-Q-No: 3
14. Write a C++ program to concatenate two strings using + operator
overloading. [Nov/Dec 2013]
Refer-Q-No: 3
15. What is inheritance? List out the advantages of inheritance [Nov/Dec
2013]
Refer-Q-No: 11
16. Write a C++ program to implement hierarchical inheritance. [Nov/Dec
2013]
Refer-Q-No: 12
Prepared By
S.Amutha AP/IT,
Mathivanan AP/IT. 65