SlideShare una empresa de Scribd logo
1 de 22
Lecture 02



Fundamentals
      of
Object-Oriented
Programming
What Are Objects?

Software objects model real-world objects or abstract concepts.
     dog, bicycle, queue

Real-world objects have states and behaviors.
      Dogs' states: name, color, breed, hungry
      Dogs' behaviors: barking, fetching

How do software objects implement real-world objects?
     Use variables/data to implement states.
     Use methods/functions to implement behaviors.

An object is a software bundle of variables and related methods.
Software Object
        Visual Representation


Instance Variables Vs Instance Methods
Software Bicycle
Visual Representation
What Are Classes?


• A class is a blueprint or prototype defining the
  variables and methods common to all objects of
  a certain kind.

• An object is an instance of a certain class.

• After you have created a class, you must create
  an instance of it before you can use.

• Class variables and class methods.
What Are Messages?




Software objects interact and communicate with
each other by sending messages to each other.
Components Of A Message




 The object to whom the message is addressed
(YourBicycle)
The name of the method to perform (changeGears)
Any parameters needed by the method (lowerGear)
O-O Principles

• Abstraction - take only important
  information
• Encapsulation - hiding or combine data
  and operations on data in a single unit.
• Inheritance - create new objects from
  existing objects.
• Polymorphism-the ability to use the same
  expression to denote different operations.
Encapsulation

• The objects' variables make up the center of
  the object.

• Methods surround and hide the object's
  center from other objects.

• Benefit of encapsulation: Modularity &
  Information Hiding.

• For implementation or efficiency reasons, an
  object may wish to expose some of its
  variables or hide some of its methods.
Inheritance

• Inheritance allows classes to be defined in terms of
  other classes.

• Each subclass inherits variables and methods from its
  superclass.

• Subclasses can add variables and methods to the
  ones they inherit from the superclass.

• Subclasses can also override inherited methods and
  provide specialized implementations for those
  methods.
Class Hierarchy
             (Inheritance Hierarchy)




Superclass vs Subclass.
Base Class vs Derived Class.
Polymorphism and Overloading

• Polymorphism allows the use of operators or functions
  in different ways, depending on the data they are
  operating on.

• When an existing operator (eg. + or =) is given the
  capability to operate on a new data type, it is said to
  be overloaded.

• Overloading is a kind of polymorphism; it is also an
  important feature of OOP.
• Example of operator overloading and polymorphism)
• the + operator know how to treat an integer and a float
  differently.
Benefits of OOP
                       Reusability

• Once written, created, and debugged, a class can be
  distributed to other programmers for use in their own
  programs.

• Reusability facilitates component-based software
  design and implementation.

• A programmer can also take an existing class and,
  without modifying it, add additional features and
  capabilities to it.
Benefits of OOP
               Creating New Data Types

• Objects and classes give the programmer a
  convenient way to construct new data types.

• Many features of C++ are intended to facilitate the
  creation of new data types.

• The ability to create new data types leads to
  extensible languages and programs.

• In C++, new data types can be built on top of existing
  (system or user-defined) data types.
C++ Program Structure

                           #include <iostream.h>
Header files
preprocessor statements
class      Data            int main( )    // VOID
           Members
{ …..
           and Member      {
}          Functions
main( )   Variable
                           cout << “Welcome to C++”;
{ ……      declarations &   return 0;
          valid C++
}         statements
                           }
Example 2

#include <iostream.h>                Sum = a + b + c;
int main ( )                         cout << “ the sum is “<< sum;
{ int a , b, c, sum =0;
  cout << “ enter a value “<<endl;      OTHER DATA TYPES
  cin >> a;                                   Char
                                                int
  cout << “ enter b value “<<endl;           long int
                                               float
  cin >> b;
                                              double
  cout << “ enter c value “<<endl;
  cin >> c;
Input / Output

Cout - used for printing out the output
Syntax :
      Cout << “Message if needed”<< variablename;
      << is called the insertion operator.
Cin - used for getting a input from the keyboard
Syntax:
      Cin >> variable name;
      >> is called the extraction operator
Other Points

Remark statement - it is a non executable statement
                      used for documentation
                    //       or   /* statements */
escape sequences:
      n - new line
      t - horizontal tab
      r - carriage return
      a - bell
       - back slash ” - double quotations
Lecture02
Lecture02
Lecture02
Lecture02

Más contenido relacionado

La actualidad más candente

C++ programming introduction
C++ programming introductionC++ programming introduction
C++ programming introductionsandeep54552
 
pointers,virtual functions and polymorphism
pointers,virtual functions and polymorphismpointers,virtual functions and polymorphism
pointers,virtual functions and polymorphismrattaj
 
Chapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-classChapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-classDeepak Singh
 
Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Sanjit Shaw
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Michelle Anne Meralpis
 
Java oops PPT
Java oops PPTJava oops PPT
Java oops PPTkishu0005
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructorsNilesh Dalvi
 
Object Oriented Programming using C++ Part I
Object Oriented Programming using C++ Part IObject Oriented Programming using C++ Part I
Object Oriented Programming using C++ Part IAjit Nayak
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member FunctionsMOHIT AGARWAL
 
Inheritance : Extending Classes
Inheritance : Extending ClassesInheritance : Extending Classes
Inheritance : Extending ClassesNilesh Dalvi
 

La actualidad más candente (20)

C++ programming introduction
C++ programming introductionC++ programming introduction
C++ programming introduction
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
pointers,virtual functions and polymorphism
pointers,virtual functions and polymorphismpointers,virtual functions and polymorphism
pointers,virtual functions and polymorphism
 
Chapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-classChapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-class
 
Objective c slide I
Objective c slide IObjective c slide I
Objective c slide I
 
Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)
 
Python - OOP Programming
Python - OOP ProgrammingPython - OOP Programming
Python - OOP Programming
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
Java oops PPT
Java oops PPTJava oops PPT
Java oops PPT
 
Constructors destructors
Constructors destructorsConstructors destructors
Constructors destructors
 
Inheritance
InheritanceInheritance
Inheritance
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
 
Object Oriented Programming using C++ Part I
Object Oriented Programming using C++ Part IObject Oriented Programming using C++ Part I
Object Oriented Programming using C++ Part I
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
 
iOS Basic
iOS BasiciOS Basic
iOS Basic
 
Inheritance : Extending Classes
Inheritance : Extending ClassesInheritance : Extending Classes
Inheritance : Extending Classes
 
106da session5 c++
106da session5 c++106da session5 c++
106da session5 c++
 
Python oop class 1
Python oop   class 1Python oop   class 1
Python oop class 1
 
Basic c#
Basic c#Basic c#
Basic c#
 

Destacado

Fundamentals of oop lecture 2
Fundamentals of oop lecture 2Fundamentals of oop lecture 2
Fundamentals of oop lecture 2miiro30
 
Oop.concepts
Oop.conceptsOop.concepts
Oop.conceptstahir266
 
12 object oriented programming
12 object oriented programming12 object oriented programming
12 object oriented programmingjigeno
 
Module1 elementary concepts of objects and classes
Module1 elementary concepts of objects and classes  Module1 elementary concepts of objects and classes
Module1 elementary concepts of objects and classes MersonSir
 
6. Exception Handling
6. Exception Handling6. Exception Handling
6. Exception HandlingNilesh Dalvi
 
A COMPLETE FILE FOR C++
A COMPLETE FILE FOR C++A COMPLETE FILE FOR C++
A COMPLETE FILE FOR C++M Hussnain Ali
 

Destacado (10)

Fundamentals of oop lecture 2
Fundamentals of oop lecture 2Fundamentals of oop lecture 2
Fundamentals of oop lecture 2
 
ITFT - Oops
ITFT - OopsITFT - Oops
ITFT - Oops
 
Oop concepts
Oop conceptsOop concepts
Oop concepts
 
Oop.concepts
Oop.conceptsOop.concepts
Oop.concepts
 
12 object oriented programming
12 object oriented programming12 object oriented programming
12 object oriented programming
 
Question bank unit i
Question bank unit iQuestion bank unit i
Question bank unit i
 
7. Multithreading
7. Multithreading7. Multithreading
7. Multithreading
 
Module1 elementary concepts of objects and classes
Module1 elementary concepts of objects and classes  Module1 elementary concepts of objects and classes
Module1 elementary concepts of objects and classes
 
6. Exception Handling
6. Exception Handling6. Exception Handling
6. Exception Handling
 
A COMPLETE FILE FOR C++
A COMPLETE FILE FOR C++A COMPLETE FILE FOR C++
A COMPLETE FILE FOR C++
 

Similar a Lecture02 (20)

c++ Unit I.pptx
c++ Unit I.pptxc++ Unit I.pptx
c++ Unit I.pptx
 
Programming Language
Programming  LanguageProgramming  Language
Programming Language
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
 
Nitin Mishra 0301EC201039 Internship PPT.pptx
Nitin Mishra 0301EC201039 Internship PPT.pptxNitin Mishra 0301EC201039 Internship PPT.pptx
Nitin Mishra 0301EC201039 Internship PPT.pptx
 
Introduction Of C++
Introduction Of C++Introduction Of C++
Introduction Of C++
 
Presentation 4th
Presentation 4thPresentation 4th
Presentation 4th
 
Objective-C for iOS Application Development
Objective-C for iOS Application DevelopmentObjective-C for iOS Application Development
Objective-C for iOS Application Development
 
Introduction to c_plus_plus
Introduction to c_plus_plusIntroduction to c_plus_plus
Introduction to c_plus_plus
 
Introduction to c_plus_plus (6)
Introduction to c_plus_plus (6)Introduction to c_plus_plus (6)
Introduction to c_plus_plus (6)
 
SRAVANByCPP
SRAVANByCPPSRAVANByCPP
SRAVANByCPP
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
 
C#2
C#2C#2
C#2
 
Learn c++ Programming Language
Learn c++ Programming LanguageLearn c++ Programming Language
Learn c++ Programming Language
 
c++ UNIT II.pptx
c++ UNIT II.pptxc++ UNIT II.pptx
c++ UNIT II.pptx
 
C++ tutorials
C++ tutorialsC++ tutorials
C++ tutorials
 
Software Engineering
Software EngineeringSoftware Engineering
Software Engineering
 
Unit 1
Unit  1Unit  1
Unit 1
 
73d32 session1 c++
73d32 session1 c++73d32 session1 c++
73d32 session1 c++
 
Oops lecture 1
Oops lecture 1Oops lecture 1
Oops lecture 1
 

Más de elearning_portal (14)

Lecture05
Lecture05Lecture05
Lecture05
 
Lecture21
Lecture21Lecture21
Lecture21
 
Lecture19
Lecture19Lecture19
Lecture19
 
Lecture18
Lecture18Lecture18
Lecture18
 
Lecture17
Lecture17Lecture17
Lecture17
 
Lecture16
Lecture16Lecture16
Lecture16
 
Lecture10
Lecture10Lecture10
Lecture10
 
Lecture09
Lecture09Lecture09
Lecture09
 
Lecture07
Lecture07Lecture07
Lecture07
 
Lecture06
Lecture06Lecture06
Lecture06
 
Lecture20
Lecture20Lecture20
Lecture20
 
Lecture03
Lecture03Lecture03
Lecture03
 
Lecture01
Lecture01Lecture01
Lecture01
 
Lecture04
Lecture04Lecture04
Lecture04
 

Último

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 

Último (20)

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 

Lecture02

  • 1. Lecture 02 Fundamentals of Object-Oriented Programming
  • 2. What Are Objects? Software objects model real-world objects or abstract concepts. dog, bicycle, queue Real-world objects have states and behaviors. Dogs' states: name, color, breed, hungry Dogs' behaviors: barking, fetching How do software objects implement real-world objects? Use variables/data to implement states. Use methods/functions to implement behaviors. An object is a software bundle of variables and related methods.
  • 3. Software Object Visual Representation Instance Variables Vs Instance Methods
  • 5. What Are Classes? • A class is a blueprint or prototype defining the variables and methods common to all objects of a certain kind. • An object is an instance of a certain class. • After you have created a class, you must create an instance of it before you can use. • Class variables and class methods.
  • 6. What Are Messages? Software objects interact and communicate with each other by sending messages to each other.
  • 7. Components Of A Message The object to whom the message is addressed (YourBicycle) The name of the method to perform (changeGears) Any parameters needed by the method (lowerGear)
  • 8. O-O Principles • Abstraction - take only important information • Encapsulation - hiding or combine data and operations on data in a single unit. • Inheritance - create new objects from existing objects. • Polymorphism-the ability to use the same expression to denote different operations.
  • 9. Encapsulation • The objects' variables make up the center of the object. • Methods surround and hide the object's center from other objects. • Benefit of encapsulation: Modularity & Information Hiding. • For implementation or efficiency reasons, an object may wish to expose some of its variables or hide some of its methods.
  • 10. Inheritance • Inheritance allows classes to be defined in terms of other classes. • Each subclass inherits variables and methods from its superclass. • Subclasses can add variables and methods to the ones they inherit from the superclass. • Subclasses can also override inherited methods and provide specialized implementations for those methods.
  • 11. Class Hierarchy (Inheritance Hierarchy) Superclass vs Subclass. Base Class vs Derived Class.
  • 12. Polymorphism and Overloading • Polymorphism allows the use of operators or functions in different ways, depending on the data they are operating on. • When an existing operator (eg. + or =) is given the capability to operate on a new data type, it is said to be overloaded. • Overloading is a kind of polymorphism; it is also an important feature of OOP. • Example of operator overloading and polymorphism) • the + operator know how to treat an integer and a float differently.
  • 13. Benefits of OOP Reusability • Once written, created, and debugged, a class can be distributed to other programmers for use in their own programs. • Reusability facilitates component-based software design and implementation. • A programmer can also take an existing class and, without modifying it, add additional features and capabilities to it.
  • 14. Benefits of OOP Creating New Data Types • Objects and classes give the programmer a convenient way to construct new data types. • Many features of C++ are intended to facilitate the creation of new data types. • The ability to create new data types leads to extensible languages and programs. • In C++, new data types can be built on top of existing (system or user-defined) data types.
  • 15. C++ Program Structure #include <iostream.h> Header files preprocessor statements class Data int main( ) // VOID Members { ….. and Member { } Functions main( ) Variable cout << “Welcome to C++”; { …… declarations & return 0; valid C++ } statements }
  • 16. Example 2 #include <iostream.h> Sum = a + b + c; int main ( ) cout << “ the sum is “<< sum; { int a , b, c, sum =0; cout << “ enter a value “<<endl; OTHER DATA TYPES cin >> a; Char int cout << “ enter b value “<<endl; long int float cin >> b; double cout << “ enter c value “<<endl; cin >> c;
  • 17. Input / Output Cout - used for printing out the output Syntax : Cout << “Message if needed”<< variablename; << is called the insertion operator. Cin - used for getting a input from the keyboard Syntax: Cin >> variable name; >> is called the extraction operator
  • 18. Other Points Remark statement - it is a non executable statement used for documentation // or /* statements */ escape sequences: n - new line t - horizontal tab r - carriage return a - bell - back slash ” - double quotations