Professional Documents
Culture Documents
Object
Oriented
Programming What is Object Oriented Programming
Dr. Munesh
Singh
What is
Object
Oriented
Programming
Dr. Munesh
Singh
Object Oriented Programming is a guideline for the
programmer to program in an efficient and more
manageable way
OOP principle leads to less error in the code, increase
collaboration among the developers and ease of
maintenance
OOPs is a programming approach which resolves around
the concept of ”Object”
Traditional C stlye Vs OOP style
What is
Object
Oriented
Programming
Dr. Munesh
Singh
running();
Traditional C stlye Vs OOP style
What is
Object
Oriented
Programming
Dr. Munesh
Singh
running();
ramesh.running();
What is an Object
What is
Object
Oriented
Programming
Dr. Munesh
Singh
What is
Object
Oriented
Programming
Dr. Munesh
Singh
Class is a blueprint of an Object.
Class is a description of Objects property set and set of
operations
Creating class is as good as defining a new data type
Class is a means to achieve encapsulation
Object is a run time entity
Object is an instance(example) of a class
CLass vs Object
What is
Object class box
Oriented
Programming
{
Dr. Munesh
Singh int l,b,h;
void setDimension(intx, int y, int z)
{.....}
void showDimension()
{....}
};
box b1;
box b2;
Software Development in C++
What is
Object
Oriented
Programming
Dr. Munesh
Singh
Principle of OOPS
What is
Object
Oriented
Programming
Dr. Munesh
Singh Encapsulation(binding the properties with function)
Data Hiding (encapsulation also leads to data hiding)
Abstraction (hiding the details from the outer side of
world)
Inheritance (deriving the properties from your ancestors)
Polymorphism
Overriding (define the normal walking and redefine with
different walking)
Overloading (change the part to function e.g hand to walk)
Identifiers
What is
Object
Oriented
Programming
Dr. Munesh
Objective
Singh
Constants
Any information is constant
Data=information=constant
Types of constant primary and secondary
primary int, real, constant
Secondary constant Array, String, Pointer, Union,
Structure, Enumerator, and class
Secondary constant derived from the primary constant
Variables
Keywords
In Memory
What is
Object Variables
Oriented
Programming
Dr. Munesh
Singh
What is
Object
Oriented
Programming
Dr. Munesh
Singh
Datatypes
What is
Object
Oriented
Programming
Dr. Munesh
Singh
What is
Object
Oriented
Programming
Dr. Munesh
Singh
Objective
Output Instruction
Input Instruction
About iostream.h
Sample program
Output Instruction
What is
Object
Oriented
Programming
What is
Object
Oriented
Programming
What is
Object
Oriented
Programming
Dr. Munesh
Singh
What is
Object
Oriented
Programming
Dr. Munesh
Singh
What is
Object
Oriented
Programming
Dr. Munesh
Singh
What is
Object
Oriented
Programming
Dr. Munesh
Singh
Reference Varaibles in C++
What is
Object Types of Varaibles
Oriented
Programming
Dr. Munesh
Singh
Reference Varaibles in C++
What is
Object
Oriented
Programming
Dr. Munesh
Singh Types of Varaibles
Reference means address
Reference Variable is an internal pointer
Declaration of Reference Variable is preceded with ’&’
symbol (but do not read it as ’address of’)
Reference variables must be initialized during declaration.
It can be initialized with already declared variables only.
Reference variables can not be updated
Function in C++
What is
Object
Oriented
Programming
Dr. Munesh
Singh
What is function?
Function is block of code performing a unit task.
Function has a name, return type and arguments.
Function is a way to achieve modularization
Functions are predefined and user-defined
Predefined functions are declaration in header file ans
defined in library files.
Definition, Declaration and Call
What is
Object
Oriented
Programming
Dr. Munesh
Singh
Declaration
What is
Object
Oriented
Programming
Dr. Munesh
Singh
What is
Object
Oriented
Programming
Dr. Munesh
Singh
What is
Object
Oriented
Programming
Dr. Munesh
Singh
Types of Formal Arguments
What is
Object
Oriented
Programming
Dr. Munesh
Singh
What is
Object
Oriented
Programming
Dr. Munesh
Singh
Call by Address
What is
Object
Oriented
Programming
Dr. Munesh
Singh
Call by Reference
What is
Object
Oriented
Programming
Dr. Munesh
Singh
Benefit of Function
What is
Object
Oriented
Programming
Dr. Munesh
Singh
Easy to read
Easy to Modify
Avoids rewriting of same code
Easy to debug
Better memory utilization
Function saves memory
What is
Object Function Memory
Oriented
Programming Function in a program is to save memory space which
Dr. Munesh becomes appreciable when a function is likely to be called
Singh
many times.
So...
So when function is small it is worthless to spend so much
extra time in such tasks in cost of saving comparatively
small space.
Inline Function
What is
Object
Oriented
Programming
Dr. Munesh
Singh
Benefit of Inline
To eliminate the cost of calls to small functions, C++
proposes a new feature called inline function
An inline function is a function that is expanded in line
when it is invoked
Compiler replaces the function call with the corresponding
function code.
What is
Object
Oriented
Programming
Dr. Munesh
Singh
Inline is request
inline is a request not a command.
The benefit of speed of inline functions reduces as the
function grows in size.
So the compiler may ignore the request in some situations.
Few of them:
Function containing loops, switch, goto.
Functions with recursion
Containing static variable.
Example
What is
Object
Oriented
Programming
Dr. Munesh
Singh
Default Argument in C++
What is
Object Function argument
Oriented
Programming
Dr. Munesh
Singh
Function Overloading
What is
Object
Oriented
Programming
Dr. Munesh
Singh
How Function Overloading is Resolved?
What is
Object
Oriented
Programming
Dr. Munesh
Singh First, C++ tries to find an exact match. This is the case
where the actual argument exactly matches the parameter
type of one of the overloaded functions.
If no exact match is found, C++ tries to find a match
through promotion
Char, unsigned char, and short is promoted to an int.
float is promoted to double
If no promotion is found, C++ tries to find a match
through standard conversion
Strucure in C++
What is
Object Three important points
Oriented
Programming Structure is collection of dissimilar elements
Dr. Munesh
Singh Structure is a way to group variables
Structure is used to create data type
struct book
{
int bookid;
char title[20];
float price;
};
void main()
{
book b1;
Strucure in C++
What is
Object Function define
Oriented
Programming void main()
Dr. Munesh
Singh {
book b1;
b1=input();
};
book input()
{
book b;
cout<<”Enter bookid, title and price”;
cin>>b.bookid>>b.title>>b.price;
return b;
}
Strucure in C++
What is
Object
Oriented Function define
Programming
struct book
Dr. Munesh
Singh {
int bookid;
char title[20];
float price;
void input()
{
cout<<”Enter bookid, title and price”;
cin>>bookid>>title>>price;
}
};
Main() function
What is
Object
Oriented
Programming
Dr. Munesh
Singh
void main()
{
book b1;
b1.input();
}
Strucure in C++
What is
Object Function define
Oriented
Programming struct book
Dr. Munesh
Singh
{
private:
int bookid;
char title[20];
float price;
public:
void input()
{
cout<<”Enter bookid, title and price”;
cin>>bookid>>title>>price;
}
Main() function
What is
Object
Oriented
Programming
Dr. Munesh
Singh
void main()
{
book b1;
b1.bookid–x(Private)
b1.input();–(Public)
}