Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 12

Class 1

OBJECT ORIENTED
PROGRAMMING
(OOP) WITH CPP

Categories of Computer Languages


CHAPTER 1

OVERVIEW OF OBJECT
ORIENTED
PROGRAMMING
(OOP)
(Earlier OOPS)
• Software Evolution

Machine language

Assembly language

Procedure-oriented

Object-oriented programming
• Structured Programming
– C follows structured programming approach
– Two confusing terms:
• Procedural programming (Imperative
programming)
• Structured programming
– Structured programming is a subset of
imperative programming, one of the major
programming paradigms
– SP specifies the steps the program must take
to reach the desired state
• Structured/procedure-oriented Programming
features

– Emphasis is on doing things (algorithms)


– Large programs into small functions
– Functions share global data
– Data move openly from function to function
– Functions transform data
– Employs top-down approach
• Object Oriented Paradigm
– Paradigm means a model, an approach, a
standard
– In real world, anything can be represented as
an object
– We have categories/groups for similar types
of data/things
– “Object oriented” is not a language, its an
approach.
– Everything has multiple instances (occurrences)
• E.g., Student, employee, computer, vehicle, table,
chair, software, hardware, galaxy, planets, stars,
etc.
• Object Oriented Programming features:

– Emphasis is on data, not procedure


– Programs are divided into classes & objects
– Data structures characterize the objects
– Data and functions are tied together
– Data is hidden from other functions
– Objects communicate through functions
– New data and functions can be easily added
– Follows bottom-up approach
• Thus we can say that the three paradigms
follow the following hierarchy:
– Procedural programming (focus is to achieve
the result with stepwise programming)
– Structured programming (stepwise
programming +uses functions and
structures to manipulate data)
– Object oriented programming (focus is to
achieve the result with data/object
orientation)
Examples
Procedural
- All algorithms, pseudo code and flowcharts
- C programs with no functions
- main()
- {
- int a=10, b=20;
- printf(“******************************************);
- printf(“Sum is: %d”, a+b);
- printf(“******************************************);
}
Structured:
main()
{
int a=10, b=20;
print();
printf(“Sum is %d”, sum(a, b);
printf();
}
void print()
{
printf(“***************************************”);
}
int sum(int a, int b)
{
return(a+b);
}
Object oriented:
Here the orientation is data in object. Example:
class sum
{
int a, b;
public:
showline()
{
cout<<“*****************************”;
}
get()
{
cin>>a>>b;
}
dosum()
{
a=a+b;
}
showsum()
{
cout<<“The sum is “<<a;
}
};

void main()
{
sum s1;
s1.showline();
s1.get();
s1.dosum();
s1.showsum();
}

You might also like