0% found this document useful (0 votes)
54 views32 pages

OOP - Object Oriented Paradigm

The document provides information about an Object Oriented Programming (OOP) course, including its course outcomes, contents, evaluation criteria, and prerequisites. The course aims to teach students the concepts of OOP using C++, including object-oriented features like inheritance, encapsulation, polymorphism, and exception handling. The course contents are spread over 10 topics across classes and include concepts like classes, objects, operators, files and streams. Students will be evaluated based on assignments, tests, exams and attendance. Prior knowledge of C programming is required.

Uploaded by

Sourin Sarkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views32 pages

OOP - Object Oriented Paradigm

The document provides information about an Object Oriented Programming (OOP) course, including its course outcomes, contents, evaluation criteria, and prerequisites. The course aims to teach students the concepts of OOP using C++, including object-oriented features like inheritance, encapsulation, polymorphism, and exception handling. The course contents are spread over 10 topics across classes and include concepts like classes, objects, operators, files and streams. Students will be evaluated based on assignments, tests, exams and attendance. Prior knowledge of C programming is required.

Uploaded by

Sourin Sarkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

OOP (IT-2001)

KALINGA INSTITUTE OF INDUSTRIAL


TECHNOLOGY

School of Computer Engineering

Strictly for internal circulation (within KIIT) and reference only. Not for outside circulation without permission

Lecture Note
3 Credit Mr. Rajat Behera - Associate Professor
Course Outcome
2

1. Able to differentiate between structures oriented programming and object


oriented programming.
2. Able to use object oriented programming language like C++ and associated
libraries to develop object oriented programs.
3. Able to understand and apply various object oriented features like
inheritance, data abstraction, encapsulation and polymorphism to solve
various computing problems using C++ language.
4. Able to apply concepts of operator-overloading, constructors and
destructors.
5. Able to apply exception handling and use built-in classes from STL.

School of Computer Engineering


Course Contents
3

Sr # Major and Detailed Coverage Area Hrs


1 Object Oriented Paradigm 2
• Evolution of programming paradigm: Procedure oriented programming Vs. Object-
oriented programming (OOP)
• Object oriented programming concepts: Classes, objects, encapsulation and
abstraction, inheritance, polymorphism, dynamic binding, message passing
2 C++ Programming basics 6
• Review of fundamental constructs of C used in C++ : Character set, Keyword,
Constant, Variable, Data types, operator & expression, control structure (branching &
looping), typecasting, array & strings
• C++ Programming basics: Streams based I/O (Input with cin, Output using cout), Type
bool, The setw manipulator, Type conversions, strict type checking, name space, scope
resolution operator (::)
• Variables: Scope & lifetime of variables, variable declaration at the point of use,
Ordinary Variable Vs. Pointer Variable Vs. Reference Variable (variable aliases)
• Function: Parameter passing by value Vs. by address Vs. by reference, inline function,
function overloading, default arguments.

School of Computer Engineering


Course Contents cont…
4

Sr # Major and Detailed Coverage Area Hrs


3 Object and Classes 4
• Defining class with functions and data members
• Access specifier: private Vs. public
• Creating & deleting objects by using new and delete operators respectively,
Array of objects, Objects as function argument
• Static Data members and member functions
• Friend function, friend class
• Function with default arguments, function overloading
4 Constructors and Destructors 3
• Definition of constructors & its uses
• Types of constructors: default constructor, parameterized constructor, copy constructor,
constructor with dynamic allocation, Dynamic Constructors
• Constructor Overloading
• Destructors
Mid Semester

School of Computer Engineering


Course Contents cont…
5

Sr # Major and Detailed Coverage Area Hrs


5 Inheritance 6

• Concept of inheritance: defining derived and base classes, Class hierarchies, public,
private, and protected derivations
• Types of Inheritance: Single Inheritance, Multilevel Inheritance, Multiple Inheritance,
Hierarchical Inheritance, Hybrid Inheritance
• Virtual base class: Function overriding
• Constructors/Destructors in derived classes: Constructors invocation and data
members initialization in derived classes
• Member classes: classes within classes
6 Operator Overloading 3

• Introduction to operator overloading


• Overloading unary operators, binary operators
• Overloading binary operators using friend function
• Rules for overloading operators

School of Computer Engineering


Course Contents cont…
6

Sr # Major and Detailed Coverage Area Hrs


7 Polymorphism 3
• Introduction to pointers: Pointers to objects, pointer to derived class object, this pointer
• Compile time polymorphism : Function Overloading & Operator overloading
• Run time polymorphism : virtual functions, pure virtual functions, abstract class, virtual
constructors & destructors
8 Files and Streams 4
• Introduction to file handling: text file Vs. binary file
• Hierarchy of file stream classes: Functions of File Stream classes
• File modes
• Sequential access:
• The get(), getline() and put() functions
• The read() and write() functions
• Reading and writing class objects
• File pointers & their Manipulations: two file pointers (get pointer, put_pointer), Functions
for manipulation of file pointers (seekg(), seekp(), tellg(), tellp())
• Updating a File: Random Access
• Error handling during file operation: Error handling functions (eof(), fail(), bad(), good())

School of Computer Engineering


Course Contents cont…
7

Sr # Major and Detailed Coverage Area Hrs


9 Exception Handling 2
• Basics Of Exception Handling
• Exception Handling Mechanism: The keyword try, throw and catch
10 Templates 2
• Need of template
• Class Templates: Definition, Class Template with multiple parameters
• Function Templates: Definition, Function Template with multiple parameters
End Semester

School of Computer Engineering


Recommended Books
8

Textbook
 Object Oriented Programming with C++ by Reema Thareja, 2nd Edition
Reference Books
 Object Oriented Programming with C++, E. Balaguruswamy, 7th Edition, 2013 TMG
Hill
 C++ completes reference, Herbert Schildt, TMG Hill, 4th Edition, 2002.
 C++ How to Program, Deitel and Deitel, Pearson Education Asia, 8th Edition, 2011.
 Object Oriented Programming with Ansi and Turbo C++, Ashok N Kamthane,
Pearson Education, 1st Edition, 2003.

School of Computer Engineering


Evaluation and Prerequisites
9

Grades will be based on Prerequisites


PC (CS-1001)
 Assignments/class tests/quizzes = 20 marks

 Midterm exam - 30 marks

 End term exam - 50 marks

20 marks evaluation Attendance


 5 assignments = 5 X 2 = 10 marks Sr # Range Mark (out of 5)
1 > 90 % 100 %
 2 written test = 2 X 2.5 = 5 marks
2 > 80 % and < 90 % 50 %
 Attendance = 5 marks 3 < 80 % 0%

School of Computer Engineering


Evolution of Programming Paradigm
10

Programming Paradigm
 Paradigm means methodology.
 A programming paradigm is a fundamental style of computer programming or the
programming technique that defines how the structure and basic elements of a
computer program is built.
 While some programming languages strictly follow a single paradigm, others may
draw concepts from more than one.
Types of Programming Paradigm
 Monolithic Programming – emphasizes on finding a solution
 Structured Programming – focus on modules
 Procedure-oriented Programming – lays stress on algorithms
 Object-oriented Programming – emphasizes on classes and objects

School of Computer Engineering


Monolithic Programming
11

 It indicates the program which contain a single


function for the large program.
 A program is not divided into parts and hence is the
name.
 It is a single thread of execution. When the program
size increases it leads inconvenience and difficult to
maintain.
 The program contains jump statements such as goto
that transfers control to any statement as specified in
it.
 The global data can be accessed and modified from
any part of the program and hence posing a serious
threat to its veracity.
 It is suitable for developing small and simple
applications
 Example: Basic
School of Computer Engineering
Evolution of Programming Paradigm cont…
12

Structured Programming
 Programming tasks can be split into smaller sections known as functions or
subroutines, which can be called whenever they are required.
 It is often (but not always) associated with a “top down” approach to design.
 It attempts to divide the problem into smaller blocks or procedures which interact
with other.
 The aim is to clearly define the structure of the program before writing program code.
 Examples: Pascal, Ada, C
Procedure-oriented Programming
 It basically consists of writing a list of instructions for the computer to follow and
organizing these instructions into groups known as functions.
 The primary focus is on functions.
 Examples: COBOL, FORTRAN

School of Computer Engineering


Procedure-oriented Programming cont…
13

Typical Program Structure of Procedure-oriented Programming

School of Computer Engineering


Procedure-oriented Programming cont…
14

Characteristics
 Emphasis is on doing things (algorithms)
 Larger programs are divided into smaller programs known as functions
 Most of the functions share global data
 Data move openly around the system from function to function
 Functions transform data from one form to another
 Employs top-down approach in program design
Relationship of data and functions

School of Computer Engineering


Object-oriented Programming
15

 It treat data as a critical element in the program development and does not allow it to
flow freely around the system.
 It ties data more closely to the functions that operate on it, and protects it from
accidental modification from outside functions.
 OOP allows decomposition of a problem into a number of entities called objects and
then build data functions around these objects
 The data of an object can be accessed only by the functions associated with that object.
Functions of one object can access the functions of another objects
Organization of data and functions

School of Computer Engineering


Object-oriented Programming cont…
16

Characteristics
 Emphasis is on data rather than procedure.
 Programs are divided into objects.
 Data structures are designed such that they characterize
the objects.
 Functions that operate on the data of an object are tied
together in the data structure.
 Data is hidden and can not be accessed by external
functions.
 Objects may communicate with each other through
functions.
 New data and functions can be added easily whenever
necessary.
 Follows bottom-up approach in program design
School of Computer Engineering
Basic Concepts
17

The object oriented language supports mechanism to define, create, store and
manipulate objects and allow communication between objects. Some of the
concepts are as follows -
 Classes
 Objects
 Data abstraction
 Encapsulation
 Inheritance
 Polymorphism
 Dynamic Binding
 Message Passing
 Overloading

School of Computer Engineering


Classes
18

 Classes are user-defined data types.


 A class is a collection of data member and member functions.
 Variable declared in class are called data member and functions declared in class are
known as member functions.
 Objects are variables of the type class. Once a class has been defined, we can create
any number of objects belonging to that class.
 Each object is associated with the data of type class with which they are created.
 If car has been defined as a class, then the statement car Mercedes, car Bmw and car
Audi is an object belonging to the class car.
 It is a logical structure

School of Computer Engineering


Classes Example
19

Class?

Objects?

School of Computer Engineering


Objects
20

 Objects are the basic run-time entities in an object-oriented system.


 They may represent a person, a place, a bank account, etc.
 Objects take up space in the memory and have an associated address like a structure
in C.
 When a program is executed, the objects interact by sending messages to one another.
 Every object have data structures called attributes and behavior called operations
 Example : account
 attributes: Account Number, Account Type, Name Balance
 behavior: Deposit, Withdraw, Enquire

Note

 Class is a logical structure


 Object is a physical actuality

School of Computer Engineering


Object Representation Style
21

School of Computer Engineering


Data Abstraction
22

 Data abstraction refers to providing only essential information to the outside world
and hiding their background details, i.e. to represent the needed information in
program without presenting the details.
 Example - TV, which you can turn on and off, change the channel, adjust the volume,
and add external components such as speakers, VCRs, and DVD players, BUT you do
not know its internal details, that is, you do not know how it receives signals over the
air or through a cable, how it translates them, and finally displays them on the screen.
Thus, we can say a television clearly separates its internal implementation from its
external interface and you can play with its interfaces like the power button, channel
changer, and volume control without having zero knowledge of its internals.
 Another Example - Okay. Bank does
not need all these
customer information
for the business.

School of Computer Engineering


Data Encapsulation
23

 The wrapping of data and functions into a single unit is known as


encapsulation.
 The data is not accessible to the outside world, and only those functions
which are wrapped in the class can access it.
 These functions provide the interface between the object’s data and the
program. This insulation of the data from direct access by the program is
called data hiding or information hiding.
 The attributes wrapped in the classes are called
data members and the functions that operate on
these data are called methods or member
functions.

School of Computer Engineering


Inheritance
24

 Inheritance is the process by which objects of one class acquire the properties
of objects of another class.
 It supports the concept of hierarchical classification.
 Each derived class shares common characteristics with the class from which
it is derived.
 The main benefits of the Inheritance is code reusability i.e. add additional
features to an existing class without modifying it.

School of Computer Engineering


Inheritance Example
25

School of Computer Engineering


Polymorphism
26

 Polymorphism is a Greek term and it means the ability to take more than one
form.
 An operation may exhibit different behaviors in different instances and the
behavior depends upon the type of data used in the operation.
 Example –
 For adding two number operation will generate sum of two number.
 For adding two string operation will concanete two string.
 Add(3, 5) gives 8 and Add(“hello”, “world”) gives “hello world”

School of Computer Engineering


Dynamic Binding
27

 Binding refers to the linking of a procedure call to the code to be executed in


response to the call.

Happens at Happens at
compile time run time

 Dynamic binding ( late binding ) means that the code associated with a given
procedure call is not known until the time of the call at run-time.
 It is associated with polymorphism and inheritance.

School of Computer Engineering


Message Passing
28

 It is a process of invoking an operation on an object.


 Objects communicate with one another by sending and receiving information.
 A message for an object is a request for execution of a function.
 The receiving object will invoke a function and generates results
 Message passing involves specifying:
 The name of the object
 The name of the function
 The information to be send
 Example - student.setData(id, name);

Object Message Information

School of Computer Engineering


Overloading
29

 Overloading is one type of Polymorphism.


 It allows an object to have different meanings, depending on its context. When
an existing operator or function begins to operate on new data type, or class,
it is understood to be overloaded.
 The process of making an operator to exhibit different behaviors in different
instances is known as operator overloading. E.g. 3+5 equates to 8 and “Hello”
+ “ World” equates to “Hello World”
 Using a single function name to perform different types of tasks is known as
function overloading. E.g. sum(3, 5) equates to 8 and sum(3, 5, 7) equates to
15

School of Computer Engineering


Advantages of OOP
30

 Through inheritance, redundant code is eliminated and extend the use of


existing classes.
 The principal of data hiding helps the programmer to build the secure
program.
 Message passing techniques for communication between objects makes the
interface descriptions with external systems much simpler.
 Multiple instances of an objects can co-exists with out any interference and
can be easily managed.
 Easily upgradable from small system to large system.

School of Computer Engineering


31

School of Computer Engineering


Home Work (HW)
32

 How are data and functions organized in an object oriented system?

 What do you mean by dynamic binding? How it is useful in OOP?

 Describe how data are shared by functions in a procedure-oriented program.

 What is object-oriented programming? How it is different from the


procedure-oriented programming?
 What are the merits and demerits of OOP?

 Explain the concept of OOP

 Differentiate between class and object

 Differentiate between syntax errors and logical errors

 What is procedure-oriented programming? What are its main


characteristics?

School of Computer Engineering

You might also like