Lecture 1 Cpp

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 16

Object Oriented Programming

using C++

Topic: Object Oriented Thinking


Contents

Programming Paradigms

Need for OOP

Procedure Oriented vs OOP

OOP Concepts

Abstraction

Encapsulation

Inheritance

Polymorphism
Programming Paradigms


Procedure Oriented Programming


Logic Programming


Functional Programming


Object Oriented Programming
Procedure Oriented Programming

Emphasis on procedure in terms of
underlying machine model.

Ability to reuse the code

Eg: C, PASCAL , C++
Procedure Oriented Programming

Factorial Program in C:

#include<stdio.h>
int main()
{
int i,fact=1,number;
printf("Enter a number: ");
scanf("%d",&number);
for(i=1;i<=number;i++){
fact=fact*i; }
printf("Factorial of %d is:

%d",number,fact);
return 0;
Logic Programming

Emphasis on knowledge base and the problem


Very much like proof of mathematical


statement


Solves logical problems like puzzles, series

Eg: Prolog
Logic Programming
Format : relation(entity1, entity2,

....k'th entity).
Example :
friends(raju, mahesh).
singer(sonu).
odd_number(5).
These facts can be interpreted as :
raju and mahesh are friends.
sonu is a singer.
Functional
Programming

Based on Mathemetical Functions and Lists


Language independent


Execution of series of Mathematical functions


Eg: LISP , Javascript
Functional
Programming

Example – LISP: Factorial of ‘n’


Program:
(defun factorial (n)
(if (= n 0)
1
(* n (factorial (- n 1))) ) )
(loop for i from 0 to 16
do (format t "~D! = ~D~%" i
(factorial i)) )
Object Oriented Programming

Emphasis on Data rather than Process.

Object is the basic entity is object.

Handle almost all kind of real life problems.
Eg: SIMULA, SMALLTALK , C++, JAVA
Object Oriented Programming
class factorial{ void main()
int f, n; {
public:
factorial ob;
void fact();
ob.fact();
};
getch();
void factorial::fact()
{ }
f=1;
cout<<"\nEnter a Number:";
cin>>n;
for(int i=1;i<=n;i++)
f=f*i;
cout<<"\nFactorial of "<<n<<" is"<<f; }
Need for OOP
To make your code:

Easier to read, manage,

update and implement.

Performance improvement by fast execution

Data Security

Easy code updation

Simplify
Eminent Persons

Alan Kay
Inventor – OOP

Bjarne Stroustrup James Gosling


Inventor – C++ Inventor- JAVA
POP vs OOP
POP OOP
Program is Program is
divided into divided into
functions. objects.
Top-down Bottom-up
approach. approach.
Limited Data Data Security
Security using access
specifiers
Examples: C, Examples:
FORTRAN, C++, Java,
Pascal, Basic Python
etc.
OOP Concepts
Summary


Programming Paradigms


Object Oriented Programming


POP vs OOP


OOP Principles

You might also like