EC6301 OBJECT ORIENTED PROGRAMMING AND DATA STRUCTURES
SYLLABUS-REGULATION 2013
OBJECTIVES: To comprehend the fundamentals of object oriented
programming, particularly in C++. To use object oriented
programming to implement data structures. To introduce linear,
non-linear data structures and their applications.UNIT I DATA
ABSTRACTION & OVERLOADINGOverview of C++ Structures Class Scope
and Accessing Class Members Reference Variables Initialization
Constructors Destructors Member Functions and Classes Friend
Function Dynamic Memory Allocation Static Class Members Container
Classes and Integrators ProxyClasses Overloading: Function
overloading and Operator Overloading.
UNIT II INHERITANCE & POLYMORPHISMBase Classes and Derived
Classes Protected Members Casting Class pointers and
MemberFunctions Overriding Public, Protected and Private
Inheritance Constructors and Destructors inderived Classes Implicit
Derived Class Object To Base Class Object Conversion CompositionVs.
Inheritance Virtual functions This Pointer Abstract Base Classes
and Concrete Classes Virtual Destructors Dynamic Binding.
UNIT III LINEAR DATA STRUCTURESAbstract Data Types (ADTs) List
ADT array-based implementation linked list implementation singly
linked lists Polynomial Manipulation - Stack ADT Queue ADT -
Evaluating arithmeticexpressions
UNIT IV NON-LINEAR DATA STRUCTURESTrees Binary Trees Binary tree
representation and traversals Application of trees:
Setrepresentation and Union-Find operations Graph and its
representations Graph Traversals Representation of Graphs
Breadth-first search Depth-first search - Connected components.
UNIT V SORTING and SEARCHINGSorting algorithms: Insertion sort -
Quick sort - Merge sort - Searching: Linear search Binary
SearchTOTAL: 45 PERIODSOUTCOMES:Upon completion of the course,
students will be able to: Explain the concepts of Object oriented
programming. Write simple applications using C++. Discuss the
different methods of organizing large amount of data.TEXT BOOKS:1.
Deitel and Deitel, C++, How To Program, Fifth Edition, Pearson
Education, 2005.2. Mark Allen Weiss, Data Structures and Algorithm
Analysis in C++,Third Edition, Addison-Wesley, 2007.
REFERENCES:1. Bhushan Trivedi, Programming with ANSI C++, A
Step-By-Step approach, Oxford UniversityPress, 2010.2. Goodrich,
Michael T., Roberto Tamassia, David Mount, Data Structures and
Algorithms in C++,7thEdition, Wiley. 2004.3. Thomas H. Cormen,
Charles E. Leiserson, Ronald L. Rivest and Clifford Stein,
"Introduction to Algorithms", Second Edition, Mc Graw Hill, 2002.4.
Bjarne Stroustrup, The C++ Programming Language, 3rdEdition,
Pearson Education, 2007.5. Ellis Horowitz, Sartaj Sahni and Dinesh
Mehta, Fundamentals of Data Structures in C++,Galgotia
Publications, 2007.
EC6301 OBJECT ORIENTED PROGRAMMING AND DATA STRUCTURES
UNIT-1 DATA ABSTRACTION AND OVERLOADING
1.1. OVERVIEW OF C++
Introduction of C++ / Basic concepts of OOPS / OVERVIEW OF
C++
Before starting to learn C++ it is essential that one must have
a basic knowledge of the concepts of Object oriented programming.
Some of the important object oriented features are namely: Objects
Classes Inheritance Data Abstraction Data Encapsulation
Polymorphism Overloading Reusability
In order to understand the basic concepts in C++, the programmer
must have a command of the basic terminology in object-oriented
programming. Below is a brief outline of the concepts of
Object-oriented programming languages:
Objects: Object is the basic unit of object-oriented
programming. Objects are identified by its unique name. An object
represents a particular instance of a class. There can be more than
one instance of an object. Each instance of an object can hold its
own relevant data. An Object is a collection of data members and
associated member functions also known as methods.
Classes: Classes are data types based on which objects are
created. Objects with similar properties and methods are grouped
together to form a Class. Thus a Class represent a set of
individual objects. Characteristics of an object are represented in
a class as Properties(Attributes) . The actions that can be
performed by objects becomes functions of the class and is referred
to as Methods (Functions).
Inheritance: Inheritance is the process of forming a new class
from an existing class or base class. The base class is also known
as parent class or super class, The new class that is formed is
called derived class. Derived class is also known as a child class
or sub class. Inheritance helps in reducing the overall code size
of the program, which is an important concept in object-oriented
programming.
Data Abstraction: Data Abstraction increases the power of
programming language by creating user defined data types. Data
Abstraction also represents the needed information in the program
without presenting the details.
Data Encapsulation: Data Encapsulation combines data and
functions into a single unit called Class. When using Data
Encapsulation, data is not accessed directly; it is only accessible
through the functions present inside the class. Data Encapsulation
enables the important concept of data hiding possible.
Polymorphism: Polymorphism allows routines to use variables of
different types at different times. An operator or function can be
given different meanings or functions. Polymorphism refers to a
single function or multi-functioning operator performing in
different ways.
Overloading: Overloading is one type of Polymorphism. It allows
an object to have different meanings, depending on its context.
When an exiting operator or function begins to operate on new data
type, or class, it is understood to be overloaded.
Reusability: This term refers to the ability for multiple
programmers to use the same written and debugged existing class of
data. This is a time saving device and adds code efficiency to the
language. Additionally, the programmer can incorporate new features
to the existing class, further developing the application and
allowing users to achieve increased performance. This time saving
feature optimizes code, helps in gaining secured applications and
facilitates easier maintenance on the application.
1.2. STRUCTURES
Structure of C++ Program : Layout of C++ ProgramC++ Programming
language is most popular language after C Programming language. C++
is first Object oriented programming language.We have summarize
structure of C++ Program in the following Picture
Structure of C++ ProgramSection 1 : Header File Declaration
Section1. Header files used in the program are listed here.2.
Header File providesPrototype declarationfor different library
functions.3. We can also includeuser define header file.4.
Basically all preprocessor directives arewrittenin this
section.Section 2 : Global Declaration Section1. Global Variables
are declared here.2. Global Declaration may include Declaring
Structure Declaring Class Declaring VariableSection 3 : Class
Declaration Section1. Actually this section can be considered as
sub section for the global declaration section.2. Class declaration
and all methods of that class are defined here.Section 4 : Main
Function1. Each and every C++ program always starts with main
function.2. This is entry point for all the function. Each and
every method is called indirectly through main.3. We can create
class objects in the main.4. Operating system call this
functionautomatically.Section 5 : Method Definition Section1. This
is optional section . Generally this method was used in C
Programming.
1.3. CLASS SCOPE AND ACCESSING CLASS MEMBERS Access Specifiers /
Control in ClassesNow before studying how to define class and its
objects, lets first quickly learn what are access specifiers.Access
specifiers in C++ class defines the access control rules. C++ has 3
new keywords introduced, namely,1. public2. private3.
protectedThese access specifiers are used to set boundaries for
availability of members of class be it data members or member
functionsAccess specifiers in the program, are followed by a colon.
You can use either one, two or all 3 specifiers in the same class
to set different boundaries for different class members. They
change the boundary for all the declarations that follow them.
PublicPublic, means all the class members declared under public
will be available to everyone. The data members and member
functions declared public can be accessed by other classes too.
Hence there are chances that they might change them. So the key
members must not be declared public.class PublicAccess{ public: //
public access specifier int x; // Data Member Declaration void
display(); // Member Function decaration}
PrivatePrivate keyword, means that no one can access the class
members declared private outside that class. If someone tries to
access the private member, they will get a compile time error. By
default class variables and member functions are private.class
PrivateAccess{ private: // private access specifier int x; // Data
Member Declaration void display(); // Member Function
decaration}
ProtectedProtected, is the last access specifier, and it is
similar to private, it makes class member inaccessible outside the
class. But they can be accessed by any subclass of that class. (If
class A is inherited by class B, then class B is subclass of class
A. We will learn this later.)class ProtectedAccess{ protected: //
protected access specifier int x; // Data Member Declaration void
display(); // Member Function decaration}
1.4. REFERENCE VARIABLES INITIALIZATION
Think of a variable name as a label attached to the variable's
location in memory. You can then think of a reference as a second
label attached to that memory location. Therefore, you can access
the contents of the variable through either the original variable
name or the reference. For example, suppose we have the following
example:int i = 17;We can declare reference variables for i as
follows.int& r = i;Read the & in these declarations
asreference. Thus, read the first declaration as "r is an integer
reference initialized to i" and read the second declaration as "s
is a double reference initialized to d.". Following example makes
use of references on int and double:#include using namespace std;
int main (){ // declare simple variables int i; double d; //
declare reference variables int& r = i; double& s = d; i =
5; cout f=7; would cause trouble, because b // doesn't have an f
field. But you can force the issue.
pointer_to_derived=static_cast(&b); // Allowed}If you wanted to
store the pointer's value in an integer, the following wouldn't
workclass base { public: int i; };
int main () { base b; int i; i=&b;}You can't
usei=static_cast(&b);either, because the types aren't similar
enough. You need to usei=reinterpret_cast(&b);, but
thereinterpret_castshould be used with care because it can lead to
dangerous situations, as this code fragment illustrates...int main
() { base *pointer_to_base; int i=-1;
pointer_to_base=reinterpret_cast(i);}The compiler lets this happen,
butpointer_to_basewon't point to a valid location for an object on
today's machines.Writing member functionsClasses can not only
contain variables, they can contain functions too. Conversion
routines are ideal candidates for inclusion within a class. Here
thederivedclass is being extended so that it can deal with the
problems mentioned above. An extra constructor (a copy constructor)
is added so that a derived object can be created as a copy of a
base object, the derived object'sffield being initialised to
0.class base { public: int i; };
class derived: public base { public: float f; derived(const
base& b) { i=b.i; f=0; }; };
int main () { base b; derived d=b;}
2.4 Overriding
If we inherit a class into the derived class and provide a
definition for one of the base class's function again inside the
derived class, then that function is said to beoverridden, and this
mechanism is calledFunction Overridingclass Base{ public: void
show() { cout