SlideShare a Scribd company logo
1
Object-Oriented
Programming(OOP)
2
Paradigm Shift in Programming
Programs: Data, Statements, Functions
Programming with flowchart
Program = Data Structure + Algorithms
Structured Programming
– Sequence Instructions
– Decision Making
– Looping
ALGORITHMS
• An algorithm is a sequence of precise instructions for
solving a problem in a finite amount of time.
Properties of an Algorithm:
• It must be precise and unambiguous(accurate
meaning)
• It must give the correct solution in all cases
• It must eventually end.
Understanding the Algorithm
• Possibly the simplest and easiest method to
understand the steps in an algorithm, is by
using the flowchart method. This algorithm is
composed of block symbols to represent each
step in the solution process as well as the
directed paths of each step. (Pictorial
Representation of an Algorithm)
The most common block symbols are:
Problem for Flowchart
• A variable is a symbolic name assigned to a
computer memory which stores a particular
value.
e.g. COUNTER, SUM, AVE
Calculate its Average ?
A flowchart representation of the algorithm
for the above problem can be as follows:
8
History of Object-Oriented ProgrammingHistory of Object-Oriented Programming
 SIMULA ISIMULA I (1962-65) and(1962-65) and SIMULA 67SIMULA 67 (1967) were the(1967) were the
first two object-oriented languages.first two object-oriented languages.
 Developed at the Norwegian Computing Center,Developed at the Norwegian Computing Center,
Oslo, Norway by Ole-Johan Dahl and KristenOslo, Norway by Ole-Johan Dahl and Kristen
Nygaard .Nygaard .
 Simula 67 introduced most of the key concepts ofSimula 67 introduced most of the key concepts of
object-oriented programming: objects and classes,object-oriented programming: objects and classes,
subclasses (“inheritance”), virtual procedures.subclasses (“inheritance”), virtual procedures.
9
Object-Oriented Programming
• Programming for simulation
• Software Crisis
• Software Reuse
• Software IC
• Polymorphism,Inheritance and Encapsulation (PIE).
• Classes as an Abstract Data Type(Abstraction)
• Easy to debug and maintain
• Mainstream in software development
• Software components.
Object Oriented Languages
• Eiffel (B. Meyer)
• CLOS (D. Bobrow, G. Kiczales)
• SELF (D. Ungar et al.)
• Java (J. Gosling et al.)
• BETA (B. Bruun-Kristensen, O. Lehrmann Madsen, B.
Møller-Pedersen, K. Nygaard)
• Other languages add object dialects, such as
TurboPascal
• C++ (Bjarne Stroustrup)
Structured Programming
Concept(Modular Prog.)
Structured programming techniques assist the
programmer in writing effective error free
programs.
Top down approach
Overall program structure divided into
separate subsections
This technique help to make isolated small
pieces of code easier to understand without
having to understand the whole program at
once.
Cont….
After a piece has been tested and studied in
detail individually, it is than integrated into
the overall program structure.
It is possible to write any computer program
by using only three (3) basic control structures
(logical concept’s) :
– Sequence instructions
– Decision Structure(if-else)
– Loop (While, Do While,…)
Ex. are Pascal , C, ADA.
Procedural ProgrammingProcedural Programming
(Procedure oriented)(Procedure oriented)
 Top down approachTop down approach
 Procedures, also known as functions or methodsProcedures, also known as functions or methods
simply contains a series ofsimply contains a series of
computational(Algorithmic) steps to be carriedcomputational(Algorithmic) steps to be carried
out.out.
 procedural programming specify the syntax andprocedural programming specify the syntax and
procedure to write a program.procedure to write a program.
 Big program is a divided into small pieces.Big program is a divided into small pieces.
 Functions are more important than data.Functions are more important than data.
 Input- arguments, output-return values.Input- arguments, output-return values.
 Ex. are C, Algol etc.Ex. are C, Algol etc.
Top down approach
 A complex program divides into smaller
pieces, makes efficient and easy to
understand a program.
Begins from the top level.
Emphasize the planning and complete
understanding of a program
No coding can begins until a sufficient level of
module details has been reached.
Advantages of the Top-Down
Design Method
• It is easier to comprehend the solution of a smaller and less
complicated problem than to grasp the solution of a large and
complex problem.
• It is easier to test segments of solutions, rather than the
entire solution at once. This method allows one to test the
solution of each sub-problem separately until the entire
solution has been tested.
• It is often possible to simplify the logical steps of each sub-
problem, so that when taken as a whole, the entire solution
has less complex logic and hence easier to develop.
• A simplified solution takes less time to develop and will be
more readable.
• The program will be easier to maintain.
Bottom up approach
Reverse top down approach.
 Lower level tasks are first carried out and are
then integrated to provide the solution of a
single program.
Lower level structures of the program are
evolved first then higher level structures are
created.
It promotes code reuse.
It may allow unit testing.
Concept of Class and ObjectConcept of Class and Object
 ““ClassClass” refers to a blueprint. It defines the variables and” refers to a blueprint. It defines the variables and
methods the objects support. It is the basic unit ofmethods the objects support. It is the basic unit of
Encapsulation. It also defines as the Collection of aEncapsulation. It also defines as the Collection of a
similar types of objects.similar types of objects.
 ““ObjectObject” is an instance(Properties) of a class. Each” is an instance(Properties) of a class. Each
object has a class which defines its data and behavior.object has a class which defines its data and behavior.
18
Structure of a Class in C++Structure of a Class in C++
class name {
declarations
constructor definition(s)
method definitions
}
attributes and
symbolic constants
how to create and
initialize objects
how to manipulate
the state of objects
These parts of a class can
actually be in any order
Sample classSample class
#include<iostream.h>#include<iostream.h>
class Pencilclass Pencil
{{
public String color = “red”;public String color = “red”;
public int length;public int length;
public float diameter;public float diameter;
setcolor(string);setcolor(string);
public void setColor (Stringpublic void setColor (String
newColor) {newColor) {
color = yellow;color = yellow;
}}
}}
private: private members are
accessible
only in the class itself.
protected: protected members are
accessible in classes in the
same package, in
subclasses of the class and
inside the class.
public: public members are
accessible anywhere
(outside the class).
Members of class
Features of OOP
Polymorphism
Inheritance
Encapsulation
(PIE)
Polymorphism
“Poly”= Many, “Morphism”= forms
For ex. We want to find out max. out of three
no., We can pass integer, float etc.
Two types –
 Compile time polymorphism.
 Run time polymorphism.
Polymorphism
World
India China USA
Rajasthan New delhi Washington New york
Inheritance
 Mechanism of deriving a new class from an
already existing class.
5 types of inheritance
 Single level
 Multilevel
 Multiple
 Hierarchical
 Hybrid
Base classFlower
Rose
Rajasthan
Jaipur
World
IndiaDerived class
Single level
Multi levelBird
Parrot Sparrow
Multiple
Base class
Derived class
Class A
{
};
Class B:public A
{
};
Class C:public B
{
};
Class D: public C
{
};
Multi level
Class AClass A
{{
};};
Class BClass B
{{
};};
Class C:public A, Public BClass C:public A, Public B
{{
};};
MultipleMultiple
Class baseClass base
{{
Data members andData members and
Functions;Functions;
};};
ClassClass
derived:public basederived:public base
{{
Data members andData members and
functions;functions;
};};
Single LevelSingle Level
Hierarchical Inheritance
A
B C D
E F IHG J
I Half(Hierarchical)
Class D
Class B Class C
Class A
Class CClass B
Class D
Class B Class C
Class A
II Half (Multiple )
Hybrid
Hybrid = Hierarchical + Multiple
Class D
Class A
Class B Class C
Hybrid = Multi level+ Multiple
Ex. of Inheritance
RTU
Engg. college
ECE Deptt.EE Deptt.CS Deptt. Civil Deptt.
Parent class
Child class
Sub classes of child class
PPP INHERITANCE
(CLASS MEMBERS)
 PUBLIC :
Class B: public A
{
};
** the line class B: public A tells the compiler that we are
inheriting class A in class B in public mode. In public mode
inheritance note the followings:
a. all the public members of class A becomes public members
of class b
b. All the protected members of class A becomes protected
members of class B
c. Private members are never inherited.
Encapsulation
Encapsulation is the mechanism that binds
the data & function in one form known as
class. The data & function may be private or
public.
Animal
Dog Cat Fish
Mutt Poodle Gold Beta
Objects binds together in form of
a Class…
“Bjarne Stroustrup”
develops C++ (1980’s)
Brings object oriented
concepts into the C
programming language
34
Why Reading Language C++ ?
• As a better C
• As an Object-Oriented Programming Language
• Faster than other OO Languages
• It derives using the increment (++) operator of
C, because it have some advanced features of
C.
35
Using C++
• File | New…
• Projects | Win32 Console Application
– Project Name, Location
– Files | C++ Source File
– File, Location
• Edit Program
• Build | Compile ***.cpp
• Build | Build ***.exe
• Build | Execute ***.exe
• Execute and stop the program
C++ Character set
A – Z= 26 = 65 to 90
a – z = 26 = 97 to 122
0 – 9 = 10 = 48 to 57
Symbols = 34= other values
TOTAL = 96
ASCII ValuesASCII Values
C++ Data types
S. No DATA TYPE Size (in bytes) RANGE
1 Short int 2 -32768 to +32767
2 Unsigned short
int
2 0 to 65535
3 long int 4 -2147483648 to 2147483647
4 Float 4 3.4e-38 to 3.4e+38
5 Char 1 -128 to 127
6 Unsigned char 1 0 to 255
7 Unsigned long int 4 0 to 4294967295
8 Double 8 1.7e-308 to 1.7e+308
9 Long double 10 1.7e-308 to 1.7e+308
C++ Tokens
Keywords (63)
Identifiers
Constants (2)
Strings
Operators (18)
Special Symbols
C++ Constants
Non Numeric constantsNon Numeric constantsNumeric ConstantsNumeric Constants
Real ConstantsReal Constants
Integer ConstantsInteger Constants
String ConstantsString Constants
Character ConstantsCharacter Constants
Decimal, Octal, HexDecimal, Octal, Hex
C++ Operators
S. No OPERATORS SYMBOLS
1. Arithmetic +,-,/,*,%
2. Logical &&,||,!
3. Relational <,>,>=,<=,==,!=
4. Assignment =
5. Increment ++
6. Decrement --
7. Comma ,
8. Conditional (Ternary) ?:
9. Bitwise &,|,^,!,>>,<<
10. Special Operator Sizeof
11. Extraction >>
12. Insertion <<
13. Dynamic Memory Allocator New
14. Dynamic memory De-allocator Delete
41
Some streams in<iostream.h>
• cout
• cin
• Operator << (Insertion)
• Operator >> (Extraction)
• endl
C vs C++
C Program
#include<stdio.h>
void main()
{
int a;
printf (“ Enter the value ”);
scanf(“%d”, &a);
printf(“n a=%d”,a);
}
C++ Program
#include<iostream.h>
void main()
{
int a;
cout<<“Enter the value”;
cin>>a;
cout<<endl<<“a=”<<a;
}
43
Program Hello
// This program outputs the message
// Hello! to the screen
#include <iostream.h>
void main()
{
cout <<"Hello!"<< endl;
}
44
Stream Input/Output
Keyboard
Console Unit
INDIA
INDIA
Stream Input
Stream Output
45
Program Average
#include <iostream.h>
void main() {
int x;
int y;
cout <<"Enter two numbers n";
cin >> x >> y;
cout <<"Their average is: ";
cout << (x + y)/2.0 << endl;
}
46
Structures
#include<iostream.h>
Void main() {
struct book{
int page_no;
char name[15];
};
book b1;
b1.page_no=125;
b1.name =“oops”;
cout <<“Book Name"<< b1.name <<“Book
page no"<< b1.page_no <<endl; }
47
Call by Reference
#include <iostream.h>
#include<conio.h>
void swap(int *, int *);
void main() {
int i=7, j=-3;
Clrscr();
swap(&i,&j);
cout <<"i = "<< i << endl
<<"j = "<< j << endl;
getch();
}
void swap(int *a, int *b) {
int t;
t = *a;
*a = *b;
*b = t;
48
Return by reference
• Example
int val1() {
//……
return i;
}
//……
j = val1();
i j
Temporary
storage
8 8 8
Matrix Multiplication
#include<iostream.h>
#include<conio.h>
void main()
{
int row1,col1,row2,col2;
int i,j,k;
int mat1[5][5],mat2[5][5],multi[5][5];
clrscr();
cout<<"enter the row for first matrixn";
cin>>row1;
cout<<"enter column for first matrixn";
cin>>col1;
cout<<"enter elements of first matrixn";
for(i=0;i<row1;i++)
{
for(j=0;j<col1;j++)
{
cin>>mat1[i][j];
}
}
cout<<"enter the row of second matrixn";
cin>>row2;
cout<<"enter column for second matrixn";
cin>>col2;
cout<<"enter elements of second matrixn";
for(i=0;i<row2;i++)
{
for(j=0;j<col2;j++)
{
cin>>mat2[i][j];
}
}
if(col1==row2)
{
cout<<"multiplication of matrices isn";
for(i=0;i<row1;i++)
{
for(j=0;j<col1;j++)
{
multi[i][j]=0;
for(k=0;k<col1;k++)
{
multi[i][j]+=mat1[i][k]*mat2[k][j];
}
cout<<multi[i][j];
}
cout<<endl;
}
}
else
cout<<"multiplication is not compatible";
getch();
}
53
Inline Functions
#include <iostream.h>
inline void swap(int&, int&);
int main() {
int i=7, j=-3;
swap(i,j);
cout <<"i = "<< i << endl
<<"j = "<< j << endl;
return 0;
}
void swap(int& a, int& b) {
int t;
t = a;
a = b;
b = t;
}
Overloading
A class can have more than one method with the
same name as long as they have different parameter
list.
public class Pencil
{
public void setPrice (float
newPrice) {
price = newPrice;
}
public void setPrice (Pencil p) {
price = p.getPrice();
}
“HAVE A NICE DAY”

More Related Content

What's hot (20)

PPT
1 Intro Object Oriented Programming
Docent Education
 
PPSX
Object Oriented Programming Overview for the PeopleSoft Developer
Lee Greffin
 
PPTX
Object Oriented Technologies
Tushar B Kute
 
PPT
Introduction to oop
Kumar
 
PPTX
Oop c++class(final).ppt
Alok Kumar
 
PPTX
Chapter 04 object oriented programming
Praveen M Jigajinni
 
PPTX
1 unit (oops)
Jay Patel
 
PPTX
OOP Unit 2 - Classes and Object
dkpawar
 
PPTX
SKILLWISE - OOPS CONCEPT
Skillwise Group
 
PDF
Java Programming Paradigms Chapter 1
Sakthi Durai
 
PPT
Oops And C++ Fundamentals
Subhasis Nayak
 
PDF
Introduction to oops concepts
Nilesh Dalvi
 
PDF
C++ [ principles of object oriented programming ]
Rome468
 
PPTX
Concepts of oops
Sourabrata Mukherjee
 
PPTX
Object-oriented programming
Neelesh Shukla
 
PPT
Oop Presentation
Ghaffar Khan
 
PPT
Oops ppt
abhayjuneja
 
PPTX
Need of object oriented programming
Amar Jukuntla
 
PPTX
Learn Concept of Class and Object in C# Part 3
C# Learning Classes
 
PDF
Object oriented programming interview questions
Keet Sugathadasa
 
1 Intro Object Oriented Programming
Docent Education
 
Object Oriented Programming Overview for the PeopleSoft Developer
Lee Greffin
 
Object Oriented Technologies
Tushar B Kute
 
Introduction to oop
Kumar
 
Oop c++class(final).ppt
Alok Kumar
 
Chapter 04 object oriented programming
Praveen M Jigajinni
 
1 unit (oops)
Jay Patel
 
OOP Unit 2 - Classes and Object
dkpawar
 
SKILLWISE - OOPS CONCEPT
Skillwise Group
 
Java Programming Paradigms Chapter 1
Sakthi Durai
 
Oops And C++ Fundamentals
Subhasis Nayak
 
Introduction to oops concepts
Nilesh Dalvi
 
C++ [ principles of object oriented programming ]
Rome468
 
Concepts of oops
Sourabrata Mukherjee
 
Object-oriented programming
Neelesh Shukla
 
Oop Presentation
Ghaffar Khan
 
Oops ppt
abhayjuneja
 
Need of object oriented programming
Amar Jukuntla
 
Learn Concept of Class and Object in C# Part 3
C# Learning Classes
 
Object oriented programming interview questions
Keet Sugathadasa
 

Similar to Oop(object oriented programming) (20)

PPTX
Introduction to Object oriented Programming basics
SwatiAtulJoshi
 
PPTX
1 intro
abha48
 
PPTX
OOSD1-unit1_1_16_09.pptx
ShobhitSrivastava15887
 
PPTX
Chapter - 1.pptx
murugeswariSenthilku
 
PPTX
Introduction to C++
murugeswariSenthilku
 
PPTX
POP vs OOP Introduction
Hashni T
 
PPTX
JAVA PROGRAMMINGD
Niyitegekabilly
 
PPTX
Birasa 1
Niyitegekabilly
 
PPTX
JAVA PROGRAMMING
Niyitegekabilly
 
PPTX
2-oops-concepts_about_c++_btech_cse.pptx
NitinGarg168992
 
PPTX
General oop concept
Avneesh Yadav
 
PPTX
Introduction to Object Oriented Programming
Md. Tanvir Hossain
 
PPTX
oop.pptx
KabitaParajuli3
 
PPTX
Object oriented programming in python
nitamhaske
 
PPTX
SE-IT JAVA LAB OOP CONCEPT
nikshaikh786
 
PPTX
OOP-1.pptx
iansebuabeh
 
PPT
Data structure and problem solving ch02.ppt
Ping261512
 
PPTX
chapterOne.pptxFSdgfqdzwwfagxgghvkjljhcxCZZXvcbx
berihun18
 
PDF
UNIT1- OBJECT ORIENTED PROGRAMMING IN JAVA- AIML IT-SPPU
ApurvaLaddha
 
Introduction to Object oriented Programming basics
SwatiAtulJoshi
 
1 intro
abha48
 
OOSD1-unit1_1_16_09.pptx
ShobhitSrivastava15887
 
Chapter - 1.pptx
murugeswariSenthilku
 
Introduction to C++
murugeswariSenthilku
 
POP vs OOP Introduction
Hashni T
 
JAVA PROGRAMMINGD
Niyitegekabilly
 
Birasa 1
Niyitegekabilly
 
JAVA PROGRAMMING
Niyitegekabilly
 
2-oops-concepts_about_c++_btech_cse.pptx
NitinGarg168992
 
General oop concept
Avneesh Yadav
 
Introduction to Object Oriented Programming
Md. Tanvir Hossain
 
oop.pptx
KabitaParajuli3
 
Object oriented programming in python
nitamhaske
 
SE-IT JAVA LAB OOP CONCEPT
nikshaikh786
 
OOP-1.pptx
iansebuabeh
 
Data structure and problem solving ch02.ppt
Ping261512
 
chapterOne.pptxFSdgfqdzwwfagxgghvkjljhcxCZZXvcbx
berihun18
 
UNIT1- OBJECT ORIENTED PROGRAMMING IN JAVA- AIML IT-SPPU
ApurvaLaddha
 
Ad

Recently uploaded (20)

PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PPTX
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PPTX
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
PDF
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
PPTX
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
PPTX
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PDF
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
Human Resources Information System (HRIS)
Amity University, Patna
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
Ad

Oop(object oriented programming)

  • 2. 2 Paradigm Shift in Programming Programs: Data, Statements, Functions Programming with flowchart Program = Data Structure + Algorithms Structured Programming – Sequence Instructions – Decision Making – Looping
  • 3. ALGORITHMS • An algorithm is a sequence of precise instructions for solving a problem in a finite amount of time. Properties of an Algorithm: • It must be precise and unambiguous(accurate meaning) • It must give the correct solution in all cases • It must eventually end.
  • 4. Understanding the Algorithm • Possibly the simplest and easiest method to understand the steps in an algorithm, is by using the flowchart method. This algorithm is composed of block symbols to represent each step in the solution process as well as the directed paths of each step. (Pictorial Representation of an Algorithm)
  • 5. The most common block symbols are:
  • 6. Problem for Flowchart • A variable is a symbolic name assigned to a computer memory which stores a particular value. e.g. COUNTER, SUM, AVE Calculate its Average ?
  • 7. A flowchart representation of the algorithm for the above problem can be as follows:
  • 8. 8 History of Object-Oriented ProgrammingHistory of Object-Oriented Programming  SIMULA ISIMULA I (1962-65) and(1962-65) and SIMULA 67SIMULA 67 (1967) were the(1967) were the first two object-oriented languages.first two object-oriented languages.  Developed at the Norwegian Computing Center,Developed at the Norwegian Computing Center, Oslo, Norway by Ole-Johan Dahl and KristenOslo, Norway by Ole-Johan Dahl and Kristen Nygaard .Nygaard .  Simula 67 introduced most of the key concepts ofSimula 67 introduced most of the key concepts of object-oriented programming: objects and classes,object-oriented programming: objects and classes, subclasses (“inheritance”), virtual procedures.subclasses (“inheritance”), virtual procedures.
  • 9. 9 Object-Oriented Programming • Programming for simulation • Software Crisis • Software Reuse • Software IC • Polymorphism,Inheritance and Encapsulation (PIE). • Classes as an Abstract Data Type(Abstraction) • Easy to debug and maintain • Mainstream in software development • Software components.
  • 10. Object Oriented Languages • Eiffel (B. Meyer) • CLOS (D. Bobrow, G. Kiczales) • SELF (D. Ungar et al.) • Java (J. Gosling et al.) • BETA (B. Bruun-Kristensen, O. Lehrmann Madsen, B. Møller-Pedersen, K. Nygaard) • Other languages add object dialects, such as TurboPascal • C++ (Bjarne Stroustrup)
  • 11. Structured Programming Concept(Modular Prog.) Structured programming techniques assist the programmer in writing effective error free programs. Top down approach Overall program structure divided into separate subsections This technique help to make isolated small pieces of code easier to understand without having to understand the whole program at once.
  • 12. Cont…. After a piece has been tested and studied in detail individually, it is than integrated into the overall program structure. It is possible to write any computer program by using only three (3) basic control structures (logical concept’s) : – Sequence instructions – Decision Structure(if-else) – Loop (While, Do While,…) Ex. are Pascal , C, ADA.
  • 13. Procedural ProgrammingProcedural Programming (Procedure oriented)(Procedure oriented)  Top down approachTop down approach  Procedures, also known as functions or methodsProcedures, also known as functions or methods simply contains a series ofsimply contains a series of computational(Algorithmic) steps to be carriedcomputational(Algorithmic) steps to be carried out.out.  procedural programming specify the syntax andprocedural programming specify the syntax and procedure to write a program.procedure to write a program.  Big program is a divided into small pieces.Big program is a divided into small pieces.  Functions are more important than data.Functions are more important than data.  Input- arguments, output-return values.Input- arguments, output-return values.  Ex. are C, Algol etc.Ex. are C, Algol etc.
  • 14. Top down approach  A complex program divides into smaller pieces, makes efficient and easy to understand a program. Begins from the top level. Emphasize the planning and complete understanding of a program No coding can begins until a sufficient level of module details has been reached.
  • 15. Advantages of the Top-Down Design Method • It is easier to comprehend the solution of a smaller and less complicated problem than to grasp the solution of a large and complex problem. • It is easier to test segments of solutions, rather than the entire solution at once. This method allows one to test the solution of each sub-problem separately until the entire solution has been tested. • It is often possible to simplify the logical steps of each sub- problem, so that when taken as a whole, the entire solution has less complex logic and hence easier to develop. • A simplified solution takes less time to develop and will be more readable. • The program will be easier to maintain.
  • 16. Bottom up approach Reverse top down approach.  Lower level tasks are first carried out and are then integrated to provide the solution of a single program. Lower level structures of the program are evolved first then higher level structures are created. It promotes code reuse. It may allow unit testing.
  • 17. Concept of Class and ObjectConcept of Class and Object  ““ClassClass” refers to a blueprint. It defines the variables and” refers to a blueprint. It defines the variables and methods the objects support. It is the basic unit ofmethods the objects support. It is the basic unit of Encapsulation. It also defines as the Collection of aEncapsulation. It also defines as the Collection of a similar types of objects.similar types of objects.  ““ObjectObject” is an instance(Properties) of a class. Each” is an instance(Properties) of a class. Each object has a class which defines its data and behavior.object has a class which defines its data and behavior.
  • 18. 18 Structure of a Class in C++Structure of a Class in C++ class name { declarations constructor definition(s) method definitions } attributes and symbolic constants how to create and initialize objects how to manipulate the state of objects These parts of a class can actually be in any order
  • 19. Sample classSample class #include<iostream.h>#include<iostream.h> class Pencilclass Pencil {{ public String color = “red”;public String color = “red”; public int length;public int length; public float diameter;public float diameter; setcolor(string);setcolor(string); public void setColor (Stringpublic void setColor (String newColor) {newColor) { color = yellow;color = yellow; }} }}
  • 20. private: private members are accessible only in the class itself. protected: protected members are accessible in classes in the same package, in subclasses of the class and inside the class. public: public members are accessible anywhere (outside the class). Members of class
  • 22. Polymorphism “Poly”= Many, “Morphism”= forms For ex. We want to find out max. out of three no., We can pass integer, float etc. Two types –  Compile time polymorphism.  Run time polymorphism.
  • 23. Polymorphism World India China USA Rajasthan New delhi Washington New york
  • 24. Inheritance  Mechanism of deriving a new class from an already existing class. 5 types of inheritance  Single level  Multilevel  Multiple  Hierarchical  Hybrid
  • 25. Base classFlower Rose Rajasthan Jaipur World IndiaDerived class Single level Multi levelBird Parrot Sparrow Multiple Base class Derived class
  • 26. Class A { }; Class B:public A { }; Class C:public B { }; Class D: public C { }; Multi level Class AClass A {{ };}; Class BClass B {{ };}; Class C:public A, Public BClass C:public A, Public B {{ };}; MultipleMultiple Class baseClass base {{ Data members andData members and Functions;Functions; };}; ClassClass derived:public basederived:public base {{ Data members andData members and functions;functions; };}; Single LevelSingle Level
  • 28. I Half(Hierarchical) Class D Class B Class C Class A Class CClass B Class D Class B Class C Class A II Half (Multiple ) Hybrid Hybrid = Hierarchical + Multiple Class D Class A Class B Class C Hybrid = Multi level+ Multiple
  • 29. Ex. of Inheritance RTU Engg. college ECE Deptt.EE Deptt.CS Deptt. Civil Deptt. Parent class Child class Sub classes of child class
  • 30. PPP INHERITANCE (CLASS MEMBERS)  PUBLIC : Class B: public A { }; ** the line class B: public A tells the compiler that we are inheriting class A in class B in public mode. In public mode inheritance note the followings: a. all the public members of class A becomes public members of class b b. All the protected members of class A becomes protected members of class B c. Private members are never inherited.
  • 31. Encapsulation Encapsulation is the mechanism that binds the data & function in one form known as class. The data & function may be private or public.
  • 32. Animal Dog Cat Fish Mutt Poodle Gold Beta Objects binds together in form of a Class…
  • 33. “Bjarne Stroustrup” develops C++ (1980’s) Brings object oriented concepts into the C programming language
  • 34. 34 Why Reading Language C++ ? • As a better C • As an Object-Oriented Programming Language • Faster than other OO Languages • It derives using the increment (++) operator of C, because it have some advanced features of C.
  • 35. 35 Using C++ • File | New… • Projects | Win32 Console Application – Project Name, Location – Files | C++ Source File – File, Location • Edit Program • Build | Compile ***.cpp • Build | Build ***.exe • Build | Execute ***.exe • Execute and stop the program
  • 36. C++ Character set A – Z= 26 = 65 to 90 a – z = 26 = 97 to 122 0 – 9 = 10 = 48 to 57 Symbols = 34= other values TOTAL = 96 ASCII ValuesASCII Values
  • 37. C++ Data types S. No DATA TYPE Size (in bytes) RANGE 1 Short int 2 -32768 to +32767 2 Unsigned short int 2 0 to 65535 3 long int 4 -2147483648 to 2147483647 4 Float 4 3.4e-38 to 3.4e+38 5 Char 1 -128 to 127 6 Unsigned char 1 0 to 255 7 Unsigned long int 4 0 to 4294967295 8 Double 8 1.7e-308 to 1.7e+308 9 Long double 10 1.7e-308 to 1.7e+308
  • 38. C++ Tokens Keywords (63) Identifiers Constants (2) Strings Operators (18) Special Symbols
  • 39. C++ Constants Non Numeric constantsNon Numeric constantsNumeric ConstantsNumeric Constants Real ConstantsReal Constants Integer ConstantsInteger Constants String ConstantsString Constants Character ConstantsCharacter Constants Decimal, Octal, HexDecimal, Octal, Hex
  • 40. C++ Operators S. No OPERATORS SYMBOLS 1. Arithmetic +,-,/,*,% 2. Logical &&,||,! 3. Relational <,>,>=,<=,==,!= 4. Assignment = 5. Increment ++ 6. Decrement -- 7. Comma , 8. Conditional (Ternary) ?: 9. Bitwise &,|,^,!,>>,<< 10. Special Operator Sizeof 11. Extraction >> 12. Insertion << 13. Dynamic Memory Allocator New 14. Dynamic memory De-allocator Delete
  • 41. 41 Some streams in<iostream.h> • cout • cin • Operator << (Insertion) • Operator >> (Extraction) • endl
  • 42. C vs C++ C Program #include<stdio.h> void main() { int a; printf (“ Enter the value ”); scanf(“%d”, &a); printf(“n a=%d”,a); } C++ Program #include<iostream.h> void main() { int a; cout<<“Enter the value”; cin>>a; cout<<endl<<“a=”<<a; }
  • 43. 43 Program Hello // This program outputs the message // Hello! to the screen #include <iostream.h> void main() { cout <<"Hello!"<< endl; }
  • 45. 45 Program Average #include <iostream.h> void main() { int x; int y; cout <<"Enter two numbers n"; cin >> x >> y; cout <<"Their average is: "; cout << (x + y)/2.0 << endl; }
  • 46. 46 Structures #include<iostream.h> Void main() { struct book{ int page_no; char name[15]; }; book b1; b1.page_no=125; b1.name =“oops”; cout <<“Book Name"<< b1.name <<“Book page no"<< b1.page_no <<endl; }
  • 47. 47 Call by Reference #include <iostream.h> #include<conio.h> void swap(int *, int *); void main() { int i=7, j=-3; Clrscr(); swap(&i,&j); cout <<"i = "<< i << endl <<"j = "<< j << endl; getch(); } void swap(int *a, int *b) { int t; t = *a; *a = *b; *b = t;
  • 48. 48 Return by reference • Example int val1() { //…… return i; } //…… j = val1(); i j Temporary storage 8 8 8
  • 49. Matrix Multiplication #include<iostream.h> #include<conio.h> void main() { int row1,col1,row2,col2; int i,j,k; int mat1[5][5],mat2[5][5],multi[5][5]; clrscr(); cout<<"enter the row for first matrixn";
  • 50. cin>>row1; cout<<"enter column for first matrixn"; cin>>col1; cout<<"enter elements of first matrixn"; for(i=0;i<row1;i++) { for(j=0;j<col1;j++) { cin>>mat1[i][j]; } } cout<<"enter the row of second matrixn"; cin>>row2; cout<<"enter column for second matrixn"; cin>>col2; cout<<"enter elements of second matrixn";
  • 53. 53 Inline Functions #include <iostream.h> inline void swap(int&, int&); int main() { int i=7, j=-3; swap(i,j); cout <<"i = "<< i << endl <<"j = "<< j << endl; return 0; } void swap(int& a, int& b) { int t; t = a; a = b; b = t; }
  • 54. Overloading A class can have more than one method with the same name as long as they have different parameter list. public class Pencil { public void setPrice (float newPrice) { price = newPrice; } public void setPrice (Pencil p) { price = p.getPrice(); }
  • 55. “HAVE A NICE DAY”