0% found this document useful (0 votes)
0 views29 pages

Lecture1 CPP

The document provides an overview of Object Oriented Programming (OOP) concepts, focusing on languages like C++ and Java, highlighting their differences in syntax and structure. It discusses key features of OOP such as encapsulation, polymorphism, and inheritance, along with the importance of data abstraction. Additionally, it covers modern C++ features like new-style headers and namespaces, as well as basic console input/output operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views29 pages

Lecture1 CPP

The document provides an overview of Object Oriented Programming (OOP) concepts, focusing on languages like C++ and Java, highlighting their differences in syntax and structure. It discusses key features of OOP such as encapsulation, polymorphism, and inheritance, along with the importance of data abstraction. Additionally, it covers modern C++ features like new-style headers and namespaces, as well as basic console input/output operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

CSTE 2101: Object Oriented Programming

(OOP).
New beginning

just skim therough them


Most used programming languages among developers
worldwide as of 2024
Object Oriented Programming with C++.
• Not pure OOP, we may write a program without
OOP syntax.
Object Oriented Programming with Java.
• Pure OOP, we cannot write a program without OOP
syntax.
Object Oriented Programming with C++.
• First, we study OOP with C++.
Reference Books:
1. Teach Yourself C++ by Herbert Schildt
2. Object Oriented Programming with C++ by E
Balaguruswamy
What is Object Oriented Programming?
• Object Oriented Programming (OOP) allows
decomposition of a problem into a number of
entities called objects and then builds data and
functions around these objects.
What is Object Oriented Programming?
• C is a structured programming language.
• Structured programming language relies on well-
defined control structures, code blocks and stand-
alone subroutine that support recursion and local
variable.
• The essence of structured programming language is
the reduction of a program into its constituents
parts.
• Using Structured programming language, the
average programmer can create and maintain
programs that are up to 50,000 lines long.
Key features of OOP
• Emphasize on data rather than procedure.
• Programs are divided into what are known as
object.
• Data is hidden and cannot be accessed by external
functions.
• Objects may communicate with each other through
functions.
• New data and functions can be easily added
whenever necessary.
All OOP languages, including C++, share
three common defining characteristics:
• Encapsulation
• Polymorphism
• Inheritance
Data Abstraction and Encapsulation
• Encapsulation is the mechanism that binds together
code and the data it manipulates, and keeps both
safe from outside interference and misuse.
• In an object-oriented language, code and data can
be combined in such a way that a self-contained
“black box” is created.
• When code and data are linked together in this
fashion, an object is created.
• Within an object, code, data or both may be private
to that object or public.
Data Abstraction and Encapsulation
• Abstraction refers to the set of representing
essential features without including the background
details or explanations.
• Classes use the concept of the abstraction and are
defined as a list of abstract attributes such as size,
weight and cost, and functions to operate on these
attributes.
• The attributes are sometimes called the data
members because they hold information.
• The function that operate on these data are
sometimes called methods or member functions.
Data Abstraction and Encapsulation
• As the classes use the concept of data abstraction,
they are known as Abstract Data Types (ADT).
Polymorphism
• Polymorphism is the quality that allow one name to
be used for two or more related but technically
different purpose.
• Using single function name to perform different
types of tasks is known as function overloading.
Inheritance
• Inheritance is the process by which one object can
acquire the properties of another.
Two Version of C++
• The difference between old-style and modern code
involve two new features:
-- new style headers and
-- the namespace statement
Two Version of C++
• The difference between old-style and modern code
involve two new features:
-- new style headers and
-- the namespace statement
The New C++ Header

• here stdio.h is the name of the file used by the I/O


functions, and the preceding statement cause that
file to be included in your program.
• The key point is that the #include statement include
a file.
The New C++ Header
• The new-style headers do not specify filenames.
• Instead, they simply specify standard identifiers.
• The new-style C++ headers are abstractions that
simply guarantee that appropriate prototypes and
definitions required have been declared.
• Here some of the new-style headers:
<iostream>
<fstream>
Namespace
• A namespace is simply a declarative region.
• The purpose of a namespace is to localize the
names of identifiers to avoid name collisions.

To bring the std namespace into visibility


C++ Console I/O

This statement causes the string to be displayed on the


computer’s screen.
cout is a predefined stream that is automatically
linked to the console when a C++ program begins
execution.
By using the << output operator, it is possible to
output any of C++’s basic types.
C++ Console I/O
In general, to output to the console, use this form of
the <<operator;

To input the value from the keyboard, use the >>


input operator.

In general,
Example
Example
It is possible to output more than one value in a single
I/O expression.
Example
This program prompts the user for an integer value.
Example
This program prompts the user for an integer value, a
floating-point value and a string.
C++ comments
Some differences between C and C++

Another difference is that in C++, if a function is


declared as returning a value, it must return a value.
In C, a non-void function is not required to actually
return a value. If it doesn’t, a garbage value is
“returned”.
Introducing Class
Introducing Class

You might also like