Академический Документы
Профессиональный Документы
Культура Документы
INTRODUCTION
Structured programming was most common
PROCEDURAL PROGRAMMING
Lays more emphasis on procedure than data
Separates the function and data manipulated
by them
Whenever the definition of a type changes,
the functions referring to this type must also
be changed to reflect the change
PROCEDURAL PROGRAMMING
The change in the design must also be
programming
it localizes the changes and hide
implementation details from user
It support user defined types
Implement information hiding and abstraction
an abstraction
An object is a distinct instance of a class
Software code in OOPs is written to define
classes, objects and manipulate these object
Implementing objects
Real World objects have physical characteristics
Mapping
Real
world
an Abstraction
into
software
Abstraction
software
attributes
{data,data}
entity
{method,method}
behaviour
Implementing
Encapsulation
Anything that an object does not know or
cannot do is excluded from the object
Encapsulation is used to hide unimportant
implementation details from the objects
Packing an objects variables within the
protective custody of its methods is
encapsulation and this task is accomplished
through classes
General structure of a
class
{data,data,.}
Private
{method,method,}
Protected
Public
A Class is define as
Class <class name>
{
private:
// hidden members/methods
protected:
//unimportant implementation details
public :
// exposed important details
};
Implementing
Inheritance
Inheritance is implement in C++ specifying the
name of the (base) class from which the class being
defined (the derived class) has to inherit from it.
Class <derived class name>:<base class name>
{
derived class own features
}
Concrete class
Recantagle class
Concrete class
Triangle class
Implementing
polymorphism
Polymorphism is the attribute that allows one
Function Overloading
A function with same name having several
Function
Overloading
Function overloading not only implement
polymorphism but also reduce number of
comparison in a program
Push(int)
Push(float)
Pop(int)
Pop(float)
Declaration and
Definition
A function argument list is known as
functions signature
Example
void squar (int a, float b); //function 1
Void squar (int x, float y);// same signature
as
function 1
Declaration and
Definition
Different signatures
void
void
void
void
prnsqr
prnsqr
prnsqr
prnsqr
(
(
(
(
int i);
char c);
float f);
double d);
Declaration and
Definition
Declaration and
Definition
Function with same name and same signature but
different return type are not allowed in C++
You can have different return types, but only if the
signature are also different:
float square (float f);// different signature
double square (double d); // allowed
If the signature of the function differ in either the
number or type of their arguments, the two
function are considered to be overloaded
Questions OOP
Q1 write briefly about different programming
paradigms ?
Q2 Discuss major OOP concepts briefly?
Q3 what is the signifance of private, protected
public specifiers in a class?
Q4 Discuss the relation between abstract and
concrete classes ?
Q5 How polymorphism implemented in c++ ?
Q6 How does the complier interpret more than
one definitions having same name ? What steps
does it follow to distinguish these ?
Questions OOP
Q7 what will be the output of following program?
#include<iostream.h>
Int area (int s)
{
Return (s*s);
}
Float area (int b,int h)
{
Return (o.5 * b* h);
}
Int main ( )
{
Cout <<area(5)<<endl;
Cout<<area(4,3)<<endl;
Cout<<area(6,area(3))<<endl;
Return 0;
}
object
data
data
function
function
data
function
Function
Function
Function
function
Function
Function
Function
Function
Calling overloaded
functions
A function call first matches the prototypes
available with number and type of arguments
provided with the function call and then call
the appropriate function for execution
call
Ambiguous match: More than one defined
match for the function call
Advantages of OOP
Re-use of code : linking of code to objects and explicit
specification of relations between objects allows related
objects to share code
Ease of comprehension: the classes can be set up to closely
represent the generic application concepts and process
Ease of fabrication and maintenance : the concepts such as
encapsulation, data abstraction allow for very clear designs
when an object is going into disallowed states, which are not
permitted only its methods needs to investigated
Easy redesign and extension : the same concepts facilitate
easy redesign and extension