Basics of C++ (Lecture 4)
Basics of C++ (Lecture 4)
Lecturer
Wah Engineering College
1. “The Object Oriented Programming in C++”
by Robert Lafore, SAMS, Fourth Edition
LOAD BASEPAY
ADD OVERPAY
STORE GROSSPAY
High-level languages
◦ To speed up programming even further
◦ Single statements for accomplishing substantial
tasks
◦ Translator programs called “Compilers” to
convert high-level programs into machine
language
Global Data:
◦ When two or more functions must access the same data
then the data must be made global
◦ Global data can be accessed by any function in the
program
Global Global Global
Data Data Data
Data
Member
Function
Member
object
Function
object
Data
Data
Member
Member Function
Function
Member
Member Function
Function
Objects
Classes
Encapsulation
Inheritance
Reusability
Polymorphism and overloading
Declaring a class doesn’t create any objects,
just as mere existence of data type int
doesn’t create any variables.
Data
Data
Member
Member Function
Function
Member
Member Function
Function
Derive other (sub-)classes from an existing
class
The original class is called the BASE CLASS;
the others are DERIVED CLASSES
Each class shares common characteristics
with the class from which it was derived, and
can also add its own modifications, additions.
For instance, VEHICLE is a class from which
Base class
F A
Feature
F B
Feature
F A
Feature
F A
Feature F A
Feature
F B
Feature
F B
Feature F B
Feature
F
Feature D
F C
Feature F F
Feature
F
Feature E
Derived classes
One class can be distributed to other
programmers for use in their own programs
In OOP, the concept of inheritance leads to
the idea of Reusability
A programmer can take an existing class and,
without modifying it, add additional features
and capabilities to it
Using operators or functions in different ways
depending on what they are operating on is
called polymorphism (lit. one thing with several
distinct forms)
Overloading is a special case of polymorphism,
e.g. +, -, /, << etc.