SlideShare a Scribd company logo
OBJECT ORIENTED PROGRAMING
IN C++
Byaruhanga Moses
byaruhanga_moses@yahoo.com
Introduction
Objectives:
• To introduce Object-Oriented Programming
(oop) and Generic Programming
• To show how to use these programming
scheme with the C++ programming language
to build “ good” programs
Need for good programming method:
Problems:
• Software projects cost are going up and
hardware costs are going down
• Software development time is getting longer
and maintenance cost are getting higher
• Software errors are getting more frequent as
hardware errors become almost non-existent
• Too many project have serous failures(Budget,
time, errors)
Why Object Technology?
Expectation are:
• Reducing the effort, complexity and cost of
dev’t and maintenance of software systems
• Reducing the time to adapt an existing system
(quicker reaction to changes in the business
environment). Flexibility, reusability.
• Increasing the reliability of the system
Why C++:
• C++ supports writing high quality programs
(support object orientation)
• C++ is used by hundred of thousands of
programmers in every application domain
- this use is supported by hundreds of
libraries,
- hundreds of textbooks, several technical
journals, many conferences.
• Application domain:
- system programming : operating systems,
devices drivers. Here direct manipulation of
hardware under real-time constraints are
important.
- banking , trading , insurance: maintainability,
ease of extension, ease of testing and
reliability are important.
- Graphics and user interface programs
- Computer Communication programs
What is programming ?
• Like any human language, a programming
language provides a way to express concepts
• Program development involves creating models
of real world situations and building computer
programs based on these modules
• Computer programs describes the methods of
implementing the model
• Computer programs may contain computer
world representations of the things that
constitute the solutions of real world problems
Abstraction
modeling
REAL WORLD
PROGRAMMER COMPUTER
If successful , the object oriented way will be significantly
easier, more flexible, and efficient than the alternatives
as problems grow larger and more complex
Problem
space
implementation
Solution
space
Programming
languages
Learning programming language
 Like human language, programming language
also have syntax and grammar rules.
 Knowledge about programmer rules of a
programming language is not enough to write
“good” programs
 The most important thing to do when learning
programming is to focus on concept but not get
lost in language –technical details
 Design techniques are far more important than
an understanding of details; that understanding
comes with time and practice.
• Before the rules of the programming
language, the programming scheme must be
understood.
• Your purpose in learning c++ must not be
simply to learn a new syntax for doing things
the way you used to, but to learn new and
better ways of building systems.
• Use compilers which support the latest c++
standard ,ISO/IEC14882(1998)
Quality matrix of a Software
 A program must do its job correctly. It must be useful
and usable
 A program must perform as fast as necessary(Real-
time constraints)
 A program must not waste system
resources(processor time, memory ,disk capacity ,
network capacity)too much
 It must be reliable
 It must be easy to update the program
 A good software must have sufficient documentation
(user manual) ……. user
 Source code must be readable and understandable
 It must be easy to maintain and update(change) the
program according to new requirement
cont
 An error must not affect other parts of a program(locality
of errors)
 Modules of the program must be reusable in further
projects
 A software project must be finished before its deadline
 A good software must have sufficient documentation
(about development)
 software developer
 Object oriented programming technique enable s
programmer to build high quality programs. While
designing and coding a program these quality metric must
be kept always in mind
• Software Development process
C++
Task/Problem
Analysis/planning
Design/modeling
implementation
Test
Documentation
Product
• Problem/task identifications.
• Analysis: Gaining a clear understanding of the
problem. Understanding requirements. They may
change during (or after) development of the system!
Building the programming team
• Design: identifying the key concepts involved in a
solution. Models of the key concepts are created.
this stage has a strong effect on the quality of the
software. Therefore, before the coding, verification
of the created model must be done.
design process is connected with the programming
scheme.. Here our design style is object -oriented
• Coding: the solution(model)is expressed in a program.
Coding is connected with the programming language . In
this course we will use c++
• Documentation: each phase of a software project must
be clearly explained. A user manual should be also
written.
• Testing: At the end , the behavior of the program for
possible inputs must be examined
they are important design principles and design patterns,
which helps us developing high-quality software. The
unified Modeling Language(UML)
is useful to express the model.
The Unified(software Development) Process –Up
A software development process describes an
approach to building, deploying and possibly
maintaining software.
The unified process is a popular iterative software
development process for building object- oriented
systems. It promotes several best practices.
• Iterative : development is organized into a series of
short, fixed-length(for e.g. three -weeks)
• Mini- projects called iterations ; the outcome
of each is a requirement analysis, design,
implementation, and testing activities
• Incremental, evolutionary
• Risk-driven
Requirements
Analysis
Design
Implementation
Testing
Requirements
Analysis
Design
Implementation
Testing
The system
grows
incrementally
Iterations fixed in
length
product
Time
Product
An iteration step 4 weeks for
example
Procedural programming Technique
• Pascal , C, BASIC, Fortran, and similar traditional
programming languages are procedural languages.
That is , each statement in the language tells the
computer to do something
• In a procedural language, the emphasis is on doing
things(function).
• A program is divided into functions and –ideally, at
least-each function has a clearly defined purpose and
a clearly defined interface to the other functions in
the program
SHARED (GLOBAL) DATA
Main program Functions
Problems with procedural
programming
• Data is undervalued
• Data is , after all, the reason for a program’s
existence. The important part of a program about a
school for example, are not functions that display the
data or functions that checks for correct input; they
are student, teacher data.
• Procedural programs( functions and data structures)
don’t model the real world very well. The real world
does not consist of functions
• Global data can be corrupted by functions that have
no business changing it
Cont..
• To add new data items, all the functions that
access the data must be modified so that they
can also access these new items.
• Creating new data types is difficult.
• It is also possible to write good programs by
using procedural programming(C programs). But
object- oriented programming offers
programmers many advantages, to enable them
to write high-quality programs
The Object Oriented Approach
The fundamental idea behind object oriented
programming is:
• The real world consist of objects. Computer
programs may contain computer world
representations of the things (objects) that
constitute the solutions of real world problems
• Real world object have two parts:
1.Attributes (property or state: characteristics that can
change)
2. Behavior (or abilities: things they can do, or
responsibilities)
to solve a programming problem in an object-oriented
language , the programmer no longer asks how the
problem will be divided into functions , but how it
will be divided into objects.
the emphasis is on data.
What kinds of things become objects in object-oriented
programs?
• Human entities: Employees, customers, sales people,
worker, manager
• Graphics program: point, line, square, circle…
• Mathematics: Complex numbers, matrix
• Computer user environment: Windows,
menus, buttons
• Data-storage constructs: Customized arrays,
stacks linked lists
The Object- Oriented Approach cont..
Thinking interms of objects rather than functions has a
helpful effect on design process of programs. This
results from the close match between objects in the
programming sense and objects in the real world.
To create software models of real world objects
both data and the functions that operate on
that data are combined into a single program
entity. Data represent the attributes (state) ,
and functions represent the behavior of an
object. Data and its function are said to be
encapsulated into a single entity
An object’s functions, called member functions
in c++ typically provide the only way to access
its data. The data is hidden , so it is safe from
accidental alteration
Encapsulation and data hiding are key terms in
the description of object- oriented language
If you want to modify the data in an object, you
know exactly what functions interact with it:
the member functions in the object. No other
functions can access the data. This simplifies
writing, debugging and maintaining the
program
Example for an object: a point in a graphics program
A point on a plane has two attributes; x-y coordinates.
Abilities (behavior, responsibilities) of a point are,
moving on the plane, appearing on the screen and
disappearing.
We can create a module for 2 dimensional points with
the following parts:
Two integer variables (x, y ) to represent x and y
coordinates
A function to move the point: move
A function to print the point on the screen: print
A function to hide the point: hide
Once the module has been built and tested, it is
possible to create many objects of this model,
in main program.
point point1, point2 , point3 ;
.
.
Point1.move(50,30);
Point1.print();
The model of an Object
A c++ program typically consists of a number
of objects that communicate with each other by calling
one another’s member functions.
y
x print
hide
move
Data (attributes)
Functions (abilities, behavior,
responsibilities)
Structure of an object – oriented
program:
message
message
message
message
message
Main program
Objects
Procedural Programming vs OO
Approach
Procedural programming:
• Procedural languages still requires one to think in terms of
the structure of the computer rather than the structure of
the problem you are trying to solve.
• The programmer must establish the association between
the machine model and the model of the problem that is
actually being solved.
• The effort required to perform this mapping produces
programs that are difficult to write and expensive to
maintain. Because the real world thing and their models on
the computer are quite different.
Con’d
• Example: real world thing : student
• Computer model: char *, int, float,…
it is said that the C language is closer to the computer
than the problem
Object – Oriented Programming;
• The object – oriented approach provides tools for the
programmer to represent elements in the problem
space.
• We refer to the elements in the problem space and
their representations in the solution space as
“objects”
• The idea is that the program is allowed to adapt itself to
the problem by adding new types of objects ., so when
you read the code describing the solution, you are reading
words that also express the problem.
• OOP allows you to describe the problem in terms of the
problem, rather than in terms of the computer where the
solution will run
• Benefits of the oop:
- readability
- understandability
- low probability of errors
- maintenance
-reusability , …. teamwork
C++: As a better c
• C++ was devloped from the C programmming
language. By adding some features to it . These
features can be collected in three groups:
1. Non-object-oriented features .which can be
used in coding phase. These are not involved
with the programing technique.
2. Features which suport object-oriented
programming
35
3. features which support generic
programming. With minor exceptions. C++ is a
superset of c.
C++
Non object-oriented
extensions
Object-oriented
extensions
Generic programming
extension
C
Minor exceptions: C
code that is not C++
C++’s Enhancement to C(Non-
object-oriented)
• Caution: the better one knows c, the harder it
seems to be to avoid writing c++ in c style,
thereby losing some of the potential benefits
of c++ .
1. always keep object-oriented and generic
programming techniques in mind.
2. always use c++ style coding technique
which has many advantages over c style. On
object-oreinted features of a c++ compiler
can be also in writing procedural programs
single line comments:
C++ allows you to begin a comment with // and
use the remainder of the line for comment
text.
a + b = c; // this is a comment
declarations and definitions in c++
Remember; there is a difference between a
declaration and a definition.
declaration introduces a name – an identifier-
to the compile. It tells the compiler “ this
function or this variable exists somewhere,
and here is what it should look like.
A definition, says.” make this variable here” or
“ make this function here” it allocates storage
for the name.
example;
Extern int i; // declaration
Int i; // definition
Struct complexT{ // declaration
float re,im;
};
complexTc1,c2; //definition
Void fuuc(int,int); //declaration (its body is a
definition
• In c, declarations and definitions must occur at
the beginning of a block.
• In c++ declarations and definitions can be placed
any where an executable statement can appear,
except that they must appear prior to the point
at which they are first used. This improves the
readability of the program.
• A variable lives only in the block, in which it was
defined. This is the scope of this variable
int a = 0;
for (inti=0;i<100;i++){ // I is dfined at the
beginning of the for
loop
a++;
int p=12; // definition of p
…… // scope of p
} // end of scope for I and p
• Scope Operator (::)
a definition in a block (local name) can hide a
definition in an enclosing block or a global
name. it is possible to use a hidden global
name by using the scope resolution operator::
int y=o; //Global y
intx =1; // Global x
void f(){ // Function is a new block
intx=5; // Local x=5, it hide global x
:: x++; // Global x=2
X++; //Local x=6
y++; // Global y =1,scope operator is
not necessary
}
Caution: it is not recommended to give identical
names to global and local data, if it is not
mandatory.
• Like in c . In C++ the same operator may have
more than one meaning. The scope operator
has also many different tasks, which are
presented in the next chapters.
Namespaces
When a program reaches a certain size it’s
typically broken up into pieces, each of which is
built and maintained by a different person or
group.
Since c effectively has a single arena where all
the identifier and function names lives, this
means that all the developers must be careful
not to accidentally use the same names in
situations where they can conflict.
the same problem comes out if a programmer
try to use the same names as the names of
library functions.
Standard c++ has a mechanism to prevent this
collision: the namespace keyword.
Each set of C++ definitions in a library or
programs is “ wrapped” in a namespace, and if
some other definition has an identical name,
but is in a different namespace, then there is
no collision.
example: namespace programmer1{
//programmer1’s namespace
int iflag; // programmer1’s iflag
void g(int); // programmer1’s g function
: // other variables
} // end of namespace
namespace programmer2{ // programmer2’s
namespace
int iflag; //programmer2’s iflag
:
} // end of namespace
Accessing the variable:
Programmer1::iflag =3; // programmer1’s iflag
Programmer2::iflag = -345; // programmer2’s
iflag
Programmer1::g(6); // programmer1’s g
function
If a variable or function does not belong to any
namespace, then it is defined in the global
namespace. It can be accessed without a
namespace name and scope operator.
• Using declaration:
This declaration makes it easier to access variable and
functions ,which are defined in a namespace
Using programmer1::flag; // apples to a single
item in the namespace
Iflag =3; //programmer1::iflag=3
Programmer2::iflag = -345;
Programmer1::g(6);
OR
Using namespace programmer1; //applies to all elements in
the namespace
Iflag = 3 ; // proggrammer1:: flag = 3;
g(6); //programmer1’s function g
Programmer2::flag = -345;

More Related Content

Similar to Introduction to oop (Lect 1).ppt object oriented programming (20)

Oop lec 2(introduction to object oriented technology)
Oop lec 2(introduction to object oriented technology)Oop lec 2(introduction to object oriented technology)
Oop lec 2(introduction to object oriented technology)
Asfand Hassan
 
Oop basic overview
Oop basic overviewOop basic overview
Oop basic overview
Deborah Akuoko
 
IET307 OOP - object oriented programming concepts.pptx
IET307 OOP - object oriented programming concepts.pptxIET307 OOP - object oriented programming concepts.pptx
IET307 OOP - object oriented programming concepts.pptx
BasithAb2
 
DOC-20210303-WA0017..pptx,coding stuff in c
DOC-20210303-WA0017..pptx,coding stuff in cDOC-20210303-WA0017..pptx,coding stuff in c
DOC-20210303-WA0017..pptx,coding stuff in c
floraaluoch3
 
C++ & VISUAL C++
C++ & VISUAL C++ C++ & VISUAL C++
C++ & VISUAL C++
Makaha Rutendo
 
C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]
Rome468
 
LECTURE NOTES ON Object Oriented Programming Using C++
LECTURE NOTES ON Object Oriented Programming Using C++LECTURE NOTES ON Object Oriented Programming Using C++
LECTURE NOTES ON Object Oriented Programming Using C++
SandeepAwasthi15
 
The Big Picture
The Big PictureThe Big Picture
The Big Picture
Munazza-Mah-Jabeen
 
OODP Unit 1 OOPs classes and objects
OODP Unit 1 OOPs classes and objectsOODP Unit 1 OOPs classes and objects
OODP Unit 1 OOPs classes and objects
Shanmuganathan C
 
Introduction to oop with c++
Introduction to oop with c++Introduction to oop with c++
Introduction to oop with c++
Shruti Patel
 
Oop in c++ lecture 1
Oop in c++  lecture 1Oop in c++  lecture 1
Oop in c++ lecture 1
zk75977
 
Lecture 1.pptx
Lecture 1.pptxLecture 1.pptx
Lecture 1.pptx
IndraKhatri
 
Object Oriented Programming Lecture Notes
Object Oriented Programming Lecture NotesObject Oriented Programming Lecture Notes
Object Oriented Programming Lecture Notes
FellowBuddy.com
 
Oop(object oriented programming)
Oop(object oriented programming)Oop(object oriented programming)
Oop(object oriented programming)
geetika goyal
 
Unit1 jaava
Unit1 jaavaUnit1 jaava
Unit1 jaava
mrecedu
 
C++ notes.pdf
C++ notes.pdfC++ notes.pdf
C++ notes.pdf
RajanBagale3
 
CSE202.pptx
CSE202.pptxCSE202.pptx
CSE202.pptx
JoyBoy45
 
POP vs OOP Introduction
POP vs OOP IntroductionPOP vs OOP Introduction
POP vs OOP Introduction
Hashni T
 
M.c.a (sem iii) paper - i - object oriented programming
M.c.a (sem   iii) paper - i - object oriented programmingM.c.a (sem   iii) paper - i - object oriented programming
M.c.a (sem iii) paper - i - object oriented programming
रवींद्र वैद्य
 
C++
C++C++
C++
Rome468
 
Oop lec 2(introduction to object oriented technology)
Oop lec 2(introduction to object oriented technology)Oop lec 2(introduction to object oriented technology)
Oop lec 2(introduction to object oriented technology)
Asfand Hassan
 
IET307 OOP - object oriented programming concepts.pptx
IET307 OOP - object oriented programming concepts.pptxIET307 OOP - object oriented programming concepts.pptx
IET307 OOP - object oriented programming concepts.pptx
BasithAb2
 
DOC-20210303-WA0017..pptx,coding stuff in c
DOC-20210303-WA0017..pptx,coding stuff in cDOC-20210303-WA0017..pptx,coding stuff in c
DOC-20210303-WA0017..pptx,coding stuff in c
floraaluoch3
 
C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]
Rome468
 
LECTURE NOTES ON Object Oriented Programming Using C++
LECTURE NOTES ON Object Oriented Programming Using C++LECTURE NOTES ON Object Oriented Programming Using C++
LECTURE NOTES ON Object Oriented Programming Using C++
SandeepAwasthi15
 
OODP Unit 1 OOPs classes and objects
OODP Unit 1 OOPs classes and objectsOODP Unit 1 OOPs classes and objects
OODP Unit 1 OOPs classes and objects
Shanmuganathan C
 
Introduction to oop with c++
Introduction to oop with c++Introduction to oop with c++
Introduction to oop with c++
Shruti Patel
 
Oop in c++ lecture 1
Oop in c++  lecture 1Oop in c++  lecture 1
Oop in c++ lecture 1
zk75977
 
Object Oriented Programming Lecture Notes
Object Oriented Programming Lecture NotesObject Oriented Programming Lecture Notes
Object Oriented Programming Lecture Notes
FellowBuddy.com
 
Oop(object oriented programming)
Oop(object oriented programming)Oop(object oriented programming)
Oop(object oriented programming)
geetika goyal
 
Unit1 jaava
Unit1 jaavaUnit1 jaava
Unit1 jaava
mrecedu
 
CSE202.pptx
CSE202.pptxCSE202.pptx
CSE202.pptx
JoyBoy45
 
POP vs OOP Introduction
POP vs OOP IntroductionPOP vs OOP Introduction
POP vs OOP Introduction
Hashni T
 

Recently uploaded (20)

Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdfForestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
ChalaKelbessa
 
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptxSEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
PoojaSen20
 
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptxPests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Arshad Shaikh
 
LDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad UpdatesLDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad Updates
LDM & Mia eStudios
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
Quiz Club of PSG College of Arts & Science
 
Optimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptxOptimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptx
UrmiPrajapati3
 
Nice Dream.pdf /
Nice Dream.pdf                              /Nice Dream.pdf                              /
Nice Dream.pdf /
ErinUsher3
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptxjune 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptxFinal Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Celine George
 
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad LevelLDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDM & Mia eStudios
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx
Arshad Shaikh
 
Smart Borrowing: Everything You Need to Know About Short Term Loans in India
Smart Borrowing: Everything You Need to Know About Short Term Loans in IndiaSmart Borrowing: Everything You Need to Know About Short Term Loans in India
Smart Borrowing: Everything You Need to Know About Short Term Loans in India
fincrifcontent
 
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxDiptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Arshad Shaikh
 
la storia dell'Inghilterra, letteratura inglese
la storia dell'Inghilterra, letteratura inglesela storia dell'Inghilterra, letteratura inglese
la storia dell'Inghilterra, letteratura inglese
LetiziaLucente
 
Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdfForestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
ChalaKelbessa
 
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptxSEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
PoojaSen20
 
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptxPests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Arshad Shaikh
 
LDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad UpdatesLDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad Updates
LDM & Mia eStudios
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
Optimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptxOptimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptx
UrmiPrajapati3
 
Nice Dream.pdf /
Nice Dream.pdf                              /Nice Dream.pdf                              /
Nice Dream.pdf /
ErinUsher3
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptxjune 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptxFinal Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Celine George
 
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad LevelLDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDM & Mia eStudios
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx
Arshad Shaikh
 
Smart Borrowing: Everything You Need to Know About Short Term Loans in India
Smart Borrowing: Everything You Need to Know About Short Term Loans in IndiaSmart Borrowing: Everything You Need to Know About Short Term Loans in India
Smart Borrowing: Everything You Need to Know About Short Term Loans in India
fincrifcontent
 
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxDiptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Arshad Shaikh
 
la storia dell'Inghilterra, letteratura inglese
la storia dell'Inghilterra, letteratura inglesela storia dell'Inghilterra, letteratura inglese
la storia dell'Inghilterra, letteratura inglese
LetiziaLucente
 
Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
Ad

Introduction to oop (Lect 1).ppt object oriented programming

  • 2. Introduction Objectives: • To introduce Object-Oriented Programming (oop) and Generic Programming • To show how to use these programming scheme with the C++ programming language to build “ good” programs Need for good programming method: Problems: • Software projects cost are going up and hardware costs are going down
  • 3. • Software development time is getting longer and maintenance cost are getting higher • Software errors are getting more frequent as hardware errors become almost non-existent • Too many project have serous failures(Budget, time, errors)
  • 4. Why Object Technology? Expectation are: • Reducing the effort, complexity and cost of dev’t and maintenance of software systems • Reducing the time to adapt an existing system (quicker reaction to changes in the business environment). Flexibility, reusability. • Increasing the reliability of the system
  • 5. Why C++: • C++ supports writing high quality programs (support object orientation) • C++ is used by hundred of thousands of programmers in every application domain - this use is supported by hundreds of libraries, - hundreds of textbooks, several technical journals, many conferences.
  • 6. • Application domain: - system programming : operating systems, devices drivers. Here direct manipulation of hardware under real-time constraints are important. - banking , trading , insurance: maintainability, ease of extension, ease of testing and reliability are important. - Graphics and user interface programs - Computer Communication programs
  • 7. What is programming ? • Like any human language, a programming language provides a way to express concepts • Program development involves creating models of real world situations and building computer programs based on these modules • Computer programs describes the methods of implementing the model • Computer programs may contain computer world representations of the things that constitute the solutions of real world problems
  • 8. Abstraction modeling REAL WORLD PROGRAMMER COMPUTER If successful , the object oriented way will be significantly easier, more flexible, and efficient than the alternatives as problems grow larger and more complex Problem space implementation Solution space Programming languages
  • 9. Learning programming language  Like human language, programming language also have syntax and grammar rules.  Knowledge about programmer rules of a programming language is not enough to write “good” programs  The most important thing to do when learning programming is to focus on concept but not get lost in language –technical details  Design techniques are far more important than an understanding of details; that understanding comes with time and practice.
  • 10. • Before the rules of the programming language, the programming scheme must be understood. • Your purpose in learning c++ must not be simply to learn a new syntax for doing things the way you used to, but to learn new and better ways of building systems. • Use compilers which support the latest c++ standard ,ISO/IEC14882(1998)
  • 11. Quality matrix of a Software  A program must do its job correctly. It must be useful and usable  A program must perform as fast as necessary(Real- time constraints)  A program must not waste system resources(processor time, memory ,disk capacity , network capacity)too much  It must be reliable  It must be easy to update the program  A good software must have sufficient documentation (user manual) ……. user  Source code must be readable and understandable  It must be easy to maintain and update(change) the program according to new requirement
  • 12. cont  An error must not affect other parts of a program(locality of errors)  Modules of the program must be reusable in further projects  A software project must be finished before its deadline  A good software must have sufficient documentation (about development)  software developer  Object oriented programming technique enable s programmer to build high quality programs. While designing and coding a program these quality metric must be kept always in mind
  • 13. • Software Development process C++ Task/Problem Analysis/planning Design/modeling implementation Test Documentation Product
  • 14. • Problem/task identifications. • Analysis: Gaining a clear understanding of the problem. Understanding requirements. They may change during (or after) development of the system! Building the programming team • Design: identifying the key concepts involved in a solution. Models of the key concepts are created. this stage has a strong effect on the quality of the software. Therefore, before the coding, verification of the created model must be done. design process is connected with the programming scheme.. Here our design style is object -oriented
  • 15. • Coding: the solution(model)is expressed in a program. Coding is connected with the programming language . In this course we will use c++ • Documentation: each phase of a software project must be clearly explained. A user manual should be also written. • Testing: At the end , the behavior of the program for possible inputs must be examined they are important design principles and design patterns, which helps us developing high-quality software. The unified Modeling Language(UML)
  • 16. is useful to express the model. The Unified(software Development) Process –Up A software development process describes an approach to building, deploying and possibly maintaining software. The unified process is a popular iterative software development process for building object- oriented systems. It promotes several best practices. • Iterative : development is organized into a series of short, fixed-length(for e.g. three -weeks)
  • 17. • Mini- projects called iterations ; the outcome of each is a requirement analysis, design, implementation, and testing activities • Incremental, evolutionary • Risk-driven
  • 19. Procedural programming Technique • Pascal , C, BASIC, Fortran, and similar traditional programming languages are procedural languages. That is , each statement in the language tells the computer to do something • In a procedural language, the emphasis is on doing things(function). • A program is divided into functions and –ideally, at least-each function has a clearly defined purpose and a clearly defined interface to the other functions in the program
  • 20. SHARED (GLOBAL) DATA Main program Functions
  • 21. Problems with procedural programming • Data is undervalued • Data is , after all, the reason for a program’s existence. The important part of a program about a school for example, are not functions that display the data or functions that checks for correct input; they are student, teacher data. • Procedural programs( functions and data structures) don’t model the real world very well. The real world does not consist of functions • Global data can be corrupted by functions that have no business changing it
  • 22. Cont.. • To add new data items, all the functions that access the data must be modified so that they can also access these new items. • Creating new data types is difficult. • It is also possible to write good programs by using procedural programming(C programs). But object- oriented programming offers programmers many advantages, to enable them to write high-quality programs
  • 23. The Object Oriented Approach The fundamental idea behind object oriented programming is: • The real world consist of objects. Computer programs may contain computer world representations of the things (objects) that constitute the solutions of real world problems • Real world object have two parts: 1.Attributes (property or state: characteristics that can change) 2. Behavior (or abilities: things they can do, or responsibilities)
  • 24. to solve a programming problem in an object-oriented language , the programmer no longer asks how the problem will be divided into functions , but how it will be divided into objects. the emphasis is on data. What kinds of things become objects in object-oriented programs? • Human entities: Employees, customers, sales people, worker, manager • Graphics program: point, line, square, circle… • Mathematics: Complex numbers, matrix
  • 25. • Computer user environment: Windows, menus, buttons • Data-storage constructs: Customized arrays, stacks linked lists
  • 26. The Object- Oriented Approach cont.. Thinking interms of objects rather than functions has a helpful effect on design process of programs. This results from the close match between objects in the programming sense and objects in the real world. To create software models of real world objects both data and the functions that operate on that data are combined into a single program entity. Data represent the attributes (state) , and functions represent the behavior of an object. Data and its function are said to be encapsulated into a single entity
  • 27. An object’s functions, called member functions in c++ typically provide the only way to access its data. The data is hidden , so it is safe from accidental alteration Encapsulation and data hiding are key terms in the description of object- oriented language If you want to modify the data in an object, you know exactly what functions interact with it: the member functions in the object. No other functions can access the data. This simplifies writing, debugging and maintaining the program
  • 28. Example for an object: a point in a graphics program A point on a plane has two attributes; x-y coordinates. Abilities (behavior, responsibilities) of a point are, moving on the plane, appearing on the screen and disappearing. We can create a module for 2 dimensional points with the following parts: Two integer variables (x, y ) to represent x and y coordinates A function to move the point: move A function to print the point on the screen: print A function to hide the point: hide
  • 29. Once the module has been built and tested, it is possible to create many objects of this model, in main program. point point1, point2 , point3 ; . . Point1.move(50,30); Point1.print();
  • 30. The model of an Object A c++ program typically consists of a number of objects that communicate with each other by calling one another’s member functions. y x print hide move Data (attributes) Functions (abilities, behavior, responsibilities)
  • 31. Structure of an object – oriented program: message message message message message Main program Objects
  • 32. Procedural Programming vs OO Approach Procedural programming: • Procedural languages still requires one to think in terms of the structure of the computer rather than the structure of the problem you are trying to solve. • The programmer must establish the association between the machine model and the model of the problem that is actually being solved. • The effort required to perform this mapping produces programs that are difficult to write and expensive to maintain. Because the real world thing and their models on the computer are quite different.
  • 33. Con’d • Example: real world thing : student • Computer model: char *, int, float,… it is said that the C language is closer to the computer than the problem Object – Oriented Programming; • The object – oriented approach provides tools for the programmer to represent elements in the problem space. • We refer to the elements in the problem space and their representations in the solution space as “objects”
  • 34. • The idea is that the program is allowed to adapt itself to the problem by adding new types of objects ., so when you read the code describing the solution, you are reading words that also express the problem. • OOP allows you to describe the problem in terms of the problem, rather than in terms of the computer where the solution will run • Benefits of the oop: - readability - understandability - low probability of errors - maintenance -reusability , …. teamwork
  • 35. C++: As a better c • C++ was devloped from the C programmming language. By adding some features to it . These features can be collected in three groups: 1. Non-object-oriented features .which can be used in coding phase. These are not involved with the programing technique. 2. Features which suport object-oriented programming 35
  • 36. 3. features which support generic programming. With minor exceptions. C++ is a superset of c. C++ Non object-oriented extensions Object-oriented extensions Generic programming extension C Minor exceptions: C code that is not C++
  • 37. C++’s Enhancement to C(Non- object-oriented) • Caution: the better one knows c, the harder it seems to be to avoid writing c++ in c style, thereby losing some of the potential benefits of c++ . 1. always keep object-oriented and generic programming techniques in mind. 2. always use c++ style coding technique which has many advantages over c style. On object-oreinted features of a c++ compiler can be also in writing procedural programs
  • 38. single line comments: C++ allows you to begin a comment with // and use the remainder of the line for comment text. a + b = c; // this is a comment declarations and definitions in c++ Remember; there is a difference between a declaration and a definition.
  • 39. declaration introduces a name – an identifier- to the compile. It tells the compiler “ this function or this variable exists somewhere, and here is what it should look like. A definition, says.” make this variable here” or “ make this function here” it allocates storage for the name.
  • 40. example; Extern int i; // declaration Int i; // definition Struct complexT{ // declaration float re,im; }; complexTc1,c2; //definition Void fuuc(int,int); //declaration (its body is a definition
  • 41. • In c, declarations and definitions must occur at the beginning of a block. • In c++ declarations and definitions can be placed any where an executable statement can appear, except that they must appear prior to the point at which they are first used. This improves the readability of the program. • A variable lives only in the block, in which it was defined. This is the scope of this variable
  • 42. int a = 0; for (inti=0;i<100;i++){ // I is dfined at the beginning of the for loop a++; int p=12; // definition of p …… // scope of p } // end of scope for I and p
  • 43. • Scope Operator (::) a definition in a block (local name) can hide a definition in an enclosing block or a global name. it is possible to use a hidden global name by using the scope resolution operator:: int y=o; //Global y intx =1; // Global x void f(){ // Function is a new block
  • 44. intx=5; // Local x=5, it hide global x :: x++; // Global x=2 X++; //Local x=6 y++; // Global y =1,scope operator is not necessary } Caution: it is not recommended to give identical names to global and local data, if it is not mandatory.
  • 45. • Like in c . In C++ the same operator may have more than one meaning. The scope operator has also many different tasks, which are presented in the next chapters.
  • 46. Namespaces When a program reaches a certain size it’s typically broken up into pieces, each of which is built and maintained by a different person or group. Since c effectively has a single arena where all the identifier and function names lives, this means that all the developers must be careful not to accidentally use the same names in situations where they can conflict.
  • 47. the same problem comes out if a programmer try to use the same names as the names of library functions. Standard c++ has a mechanism to prevent this collision: the namespace keyword. Each set of C++ definitions in a library or programs is “ wrapped” in a namespace, and if some other definition has an identical name, but is in a different namespace, then there is no collision.
  • 48. example: namespace programmer1{ //programmer1’s namespace int iflag; // programmer1’s iflag void g(int); // programmer1’s g function : // other variables } // end of namespace namespace programmer2{ // programmer2’s namespace int iflag; //programmer2’s iflag : } // end of namespace
  • 49. Accessing the variable: Programmer1::iflag =3; // programmer1’s iflag Programmer2::iflag = -345; // programmer2’s iflag Programmer1::g(6); // programmer1’s g function If a variable or function does not belong to any namespace, then it is defined in the global namespace. It can be accessed without a namespace name and scope operator.
  • 50. • Using declaration: This declaration makes it easier to access variable and functions ,which are defined in a namespace Using programmer1::flag; // apples to a single item in the namespace Iflag =3; //programmer1::iflag=3 Programmer2::iflag = -345; Programmer1::g(6); OR
  • 51. Using namespace programmer1; //applies to all elements in the namespace Iflag = 3 ; // proggrammer1:: flag = 3; g(6); //programmer1’s function g Programmer2::flag = -345;

Editor's Notes

  • #2: Object-Oriented programming lecture notes 2009
  • #3: Object-Oriented programming lecture notes 2009
  • #4: Object-Oriented programming lecture notes 2009
  • #5: Object-Oriented programming lecture notes 2009
  • #6: Object-Oriented programming lecture notes 2009
  • #7: Object-Oriented programming lecture notes 2009
  • #8: Object-Oriented programming lecture notes 2009
  • #9: Object-Oriented programming lecture notes 2009
  • #10: Object-Oriented programming lecture notes 2009
  • #11: Object-Oriented programming lecture notes 2009
  • #12: Object-Oriented programming lecture notes 2009
  • #13: Object-Oriented programming lecture notes 2009
  • #14: Object-Oriented programming lecture notes 2009
  • #15: Object-Oriented programming lecture notes 2009
  • #16: Object-Oriented programming lecture notes 2009
  • #17: Object-Oriented programming lecture notes 2009
  • #18: Object-Oriented programming lecture notes 2009
  • #19: Object-Oriented programming lecture notes 2009
  • #20: Object-Oriented programming lecture notes
  • #21: Object-Oriented programming lecture notes 2009
  • #22: Object-Oriented programming lecture notes 2009
  • #23: Object-Oriented programming lecture notes 2009
  • #24: Object-Oriented programming lecture notes 2009
  • #25: Object-Oriented programming lecture notes 2009
  • #26: Object-Oriented programming lecture notes
  • #27: Object-Oriented programming lecture notes 2009
  • #29: Object-Oriented programming lecture notes 2009
  • #30: Object-Oriented programming lecture notes 2009
  • #31: Object-Oriented programming lecture notes 2009
  • #32: Object-Oriented programming lecture notes 2009
  • #33: Object-Oriented programming lecture notes 2009
  • #34: Object-Oriented programming lecture notes 2009