0% found this document useful (0 votes)
3 views24 pages

Chapter 1 Introduction

This document introduces Object-Oriented Programming (OOP) in C++, highlighting its necessity due to limitations in procedural programming. It explains key concepts such as attributes, behaviors, and features of OOP, emphasizing the importance of data hiding and real-world modeling. The document also lists popular OOP languages and assigns reading from a related book for further understanding.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views24 pages

Chapter 1 Introduction

This document introduces Object-Oriented Programming (OOP) in C++, highlighting its necessity due to limitations in procedural programming. It explains key concepts such as attributes, behaviors, and features of OOP, emphasizing the importance of data hiding and real-world modeling. The document also lists popular OOP languages and assigns reading from a related book for further understanding.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

HEWAD UNIVERSITY

Object Oriented Programming ‫هیــــواد پوهنــتون‬

OOP in cpp
Chapter 1
Introduction

Ahmad Jalal Zalal

Department
HEWAD University of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

In the end of this Chapter

• Why OOP?

• Attributes.

• Behavior.

• Features of OOP.

• OOP language.
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Why Do We Need Object-Oriented Programming?

Object-oriented programming was developed because


limitations were discovered in earlier approaches to
programming.
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Why Do We Need Object-Oriented Programming?

C, Pascal, FORTRAN, and similar languages are procedural


languages. That is, each statement in the language tells the
computer to do something. Get some input, add these numbers,
divide by six, display that output.

A program in a procedural language is a list of instructions.


HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Why Do We Need Object-Oriented Programming?

In object oriented programming, program is divided into small


parts called objects. Procedural programming follows top down
approach.

Procedural programming does not have any proper way for


hiding data so it is less secure. Object oriented
programming provides data hiding so it is more secure.
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Why Do We Need Object-Oriented Programming?

In a procedural program, one written in C for example, there are


two kinds of data. Local data is hidden inside a function, and is
used exclusively by the function.

Local data on the other hand is closely related to its function


and is safe from modification by other functions.
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Why Do We Need Object-Oriented Programming?

However, when two or more functions must access the same


data and this is one of the most important data in a program then
the data must be made global.

Global data can be accessed by any function in the program.


HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Why Do We Need Object-Oriented Programming?


HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Why Do We Need Object-Oriented Programming?


HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Why Do We Need Object-Oriented Programming?

This large number of connections causes problems in several


ways. First, it makes a program’s structure difficult to
conceptualize. Second, it makes the program difficult to
modify/change.

A change made in a global data item may necessitate rewriting


all the functions that access that item.
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Why Do We Need Object-Oriented Programming?

For example, in our inventory program, someone may decide


that the product codes for the inventory items should be changed
from 5 digits to 10 digits. This may necessitate a change from a
short to a long data type.

Data Type Size (in bytes) Range


short int 2 -32,768 to 32,767
long int 4 -2,147,483,648 to 2,147,483,647
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Why Do We Need Object-Oriented Programming?

The second and more important problem with the procedural


paradigm is that its arrangement of separate data and functions
does a poor job of modeling things in the real world.
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Object Oriented Programming

OOP is a programming technique in which programs are written


on the basis of objects.

Object is a collection of data and functions.


Object is represent a person, place or thing in real world.
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Object Oriented Programming

In the physical world we deal with objects such as people,


cars, etc.

Such objects aren’t like data and they aren’t like functions.
Complex real-world objects have both attributes )‫ صفـت‬،‫ (ویژگی‬and
behavior )‫ سلوک‬،‫(طرز رفتار‬.
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Object Oriented Programming

Attributes are the characteristics of the class that help to differ


it from other classes.

Attributes are also called properties and behaviors are


called functions as well. Properties are presented with different
data types, and behaviors are described using functions.
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Object Oriented Programming

Behaviors are the tasks that an object performs.

For example a person's attributes include their age, name, and


height, while their behaviors include the fact that a person can
speak, run, walk, and eat.
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Object Oriented Programming

Lets map a person class:

Attribute

Behavior
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Object Oriented Programming

So neither data nor functions, by themselves, model real-world


objects effectively.
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Class Activity

What are the attributes and behaviors of car?


What are the attributes and behaviors of TV?
What are the attributes and behaviors of watch?
What are the attributes and behaviors of fan?
What are the attributes and behaviors of heater?
What are the attributes and behaviors of phone?
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Features of OOP

• Object
• Classes
• Real World Modeling
• Reusability
• Information hiding
• Polymorphism
• Etc.
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

OOP Programming language

• C++
• Java
• C#
• PHP
• Python
• etc.
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Assignment

Read the book “Object Oriented Programming in C++ by


Robert Lafore 4th Edition” from page 10-25 (36-51) and answer
the questions.
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

In this Chapter

• Why OOP?

• Attributes.

• Behavior.

• Features of OOP.

• OOP language.
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

End of Chapter 1

Any Questions???

You might also like