SlideShare a Scribd company logo
1 of 55
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

Introduction to oop
Introduction to oop Introduction to oop
Introduction to oop
Kumar
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).ppt
Alok Kumar
 
1 unit (oops)
1 unit (oops)1 unit (oops)
1 unit (oops)
Jay Patel
 

What's hot (20)

1 Intro Object Oriented Programming
1  Intro Object Oriented Programming1  Intro Object Oriented Programming
1 Intro Object Oriented Programming
 
Object Oriented Programming Overview for the PeopleSoft Developer
Object Oriented Programming Overview for the PeopleSoft DeveloperObject Oriented Programming Overview for the PeopleSoft Developer
Object Oriented Programming Overview for the PeopleSoft Developer
 
Object Oriented Technologies
Object Oriented TechnologiesObject Oriented Technologies
Object Oriented Technologies
 
Introduction to oop
Introduction to oop Introduction to oop
Introduction to oop
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).ppt
 
Chapter 04 object oriented programming
Chapter 04 object oriented programmingChapter 04 object oriented programming
Chapter 04 object oriented programming
 
1 unit (oops)
1 unit (oops)1 unit (oops)
1 unit (oops)
 
OOP Unit 2 - Classes and Object
OOP Unit 2 - Classes and ObjectOOP Unit 2 - Classes and Object
OOP Unit 2 - Classes and Object
 
SKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPTSKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPT
 
Java Programming Paradigms Chapter 1
Java Programming Paradigms Chapter 1 Java Programming Paradigms Chapter 1
Java Programming Paradigms Chapter 1
 
Oops And C++ Fundamentals
Oops And C++ FundamentalsOops And C++ Fundamentals
Oops And C++ Fundamentals
 
Introduction to oops concepts
Introduction to oops conceptsIntroduction to oops concepts
Introduction to oops concepts
 
C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]
 
Concepts of oops
Concepts of oopsConcepts of oops
Concepts of oops
 
Object-oriented programming
Object-oriented programmingObject-oriented programming
Object-oriented programming
 
Oop Presentation
Oop PresentationOop Presentation
Oop Presentation
 
Oops ppt
Oops pptOops ppt
Oops ppt
 
Need of object oriented programming
Need of object oriented programmingNeed of object oriented programming
Need of object oriented programming
 
Learn Concept of Class and Object in C# Part 3
Learn Concept of Class and Object in C#  Part 3Learn Concept of Class and Object in C#  Part 3
Learn Concept of Class and Object in C# Part 3
 
Object oriented programming interview questions
Object oriented programming interview questionsObject oriented programming interview questions
Object oriented programming interview questions
 

Similar to Oop(object oriented programming)

object oriented programming part inheritance.pptx
object oriented programming part inheritance.pptxobject oriented programming part inheritance.pptx
object oriented programming part inheritance.pptx
urvashipundir04
 
c++session 1.pptx
c++session 1.pptxc++session 1.pptx
c++session 1.pptx
PadmaN24
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)
Jay Patel
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1st
Connex
 

Similar to Oop(object oriented programming) (20)

Summer Training Project On C++
Summer Training Project On  C++Summer Training Project On  C++
Summer Training Project On C++
 
SE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPTSE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPT
 
object oriented programming part inheritance.pptx
object oriented programming part inheritance.pptxobject oriented programming part inheritance.pptx
object oriented programming part inheritance.pptx
 
General oop concept
General oop conceptGeneral oop concept
General oop concept
 
c++session 1.pptx
c++session 1.pptxc++session 1.pptx
c++session 1.pptx
 
Unit 1 introduction to c++.pptx
Unit 1 introduction to c++.pptxUnit 1 introduction to c++.pptx
Unit 1 introduction to c++.pptx
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)
 
cs8251 unit 1 ppt
cs8251 unit 1 pptcs8251 unit 1 ppt
cs8251 unit 1 ppt
 
c#.pptx
c#.pptxc#.pptx
c#.pptx
 
Csharp introduction
Csharp introductionCsharp introduction
Csharp introduction
 
Unit 5.ppt
Unit 5.pptUnit 5.ppt
Unit 5.ppt
 
73d32 session1 c++
73d32 session1 c++73d32 session1 c++
73d32 session1 c++
 
Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptx
 
Topic 1 PBO
Topic 1 PBOTopic 1 PBO
Topic 1 PBO
 
OOPS_Unit_1
OOPS_Unit_1OOPS_Unit_1
OOPS_Unit_1
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1st
 
Object Oriented Programming using C++ - Part 1
Object Oriented Programming using C++ - Part 1Object Oriented Programming using C++ - Part 1
Object Oriented Programming using C++ - Part 1
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
C++ & VISUAL C++
C++ & VISUAL C++ C++ & VISUAL C++
C++ & VISUAL C++
 
UNIT1-JAVA.pptx
UNIT1-JAVA.pptxUNIT1-JAVA.pptx
UNIT1-JAVA.pptx
 

Recently uploaded

Recently uploaded (20)

WSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in UgandaWSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in Uganda
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of TransformationWSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAMWSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - Kanchana
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
 

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”