Object Oriented Programming
Object Oriented Programming
Oriented Programming
Object Oriented Programming
� Software Evolution
� OOPS Concepts
2
Software Evolution
1,0 Binary
Machine Language
Assembly Language
Programming
4
Characteristics of Procedure Oriented
Programming
function to function.
another.
design.
5
Characteristics of Object Oriented
Programming
6
Characteristics of Object Oriented
Programming
functions.
through functions.
whenever necessary.
7
� Follows bottom up approach in program
OOPs Concepts
� Object :-
1. Objects are the basic run time entities in an object
oriented system.
2. They may represent a person, a place, a table, a bank
account, a table of data or any item that the program
has to handle.
3. For ex:- If “Customer” & “Account” are two objects
in a program, then the customer object may send a
msg to the acct object requesting for the bank
balance.
Dalcomp Technologies 8
� Class :-
1. We just mentioned that objects contain data, & code to
manipulate that data, the entire set of data & code of an
object can be made a user defined data type with the help of
a Class.
2. For Ex.
Mango, Apple & Orange are the members of class fruit.
3. If the fruit has been defined as a class , then the
statement
fruit mango;
will create an object mango belonging to the class fruit.
9
�Data Abstraction :-
details.
10
Example Of Data Abstraction
4. For Ex. A car dealer might view a car from the standpoint
of its selling features. Relevant properties include price,
color, optional equipment, and length of warranty.
13
�Polymorphism:-
1. Polymorphism means “many forms and one interface”.
2. It allows us to have many function with the same name inside
a class.
Polymorphism
Virtual
Operator Function Functions
Overloading Overloading
e.g. cin>>n; e.g. int add(int, int);
C = a>>2; Float add(float, int);
Inheritance(Extending class)
Marks
Sub 1, Sub 2 Derived Class Data Members
get() , put() Derived Class Methods
15
� Dynamic Binding:-
Shape
Draw
()
4. For Ex. In the given figure, for draw() method ,at run
time, the code matching the object under current
16
reference will be called.
� Message Passing:-
For Ex:-
Employee.Salary(name);
Object Information
Message
17
Benefits Or Advantages of OOPS
1.Through inheritance, we can eliminate redundant code &
19
1.C++ is an Object Oriented Programming
Language.
22
Difference Between C & C++
6. C++ supports function overloading while C
does not
7. We can use functions inside structures in C++
but not in C.
8. C++ allows the use of reference variables while C
does not
9. C contains 32 Keywords,C++ extends it to 52
Keywords
10. C++ is a superset of C while C is a superset of B.
23
First program of c++
24
Scope Resolution Operator
This Operator is used for:-
void test :: getdata()
1.To unhide the global
{
variable that might have
bought hidden by local x=10;y=20;
variables. }
2.To access members void main()
declared in class scope. {
test s;
For Ex:- class test s.getdata();
{ s.disp();
int x,y; getch();
public: }
void getdata();
void disp() Output:-
{
cout<<x<<“\t”<<y; 10 20
} 25
Example of Scope Resolution Operator to access global
variables:-
#include<iostream.h>
void main()
{
int m =20; // m local to main Output:-
{ We are in inner block
int k = m; k = 20
int m = 30; // m declared again m= 30
::m = 10
We are in outer block
cout<<“We are in inner block\n”;
m = 20
cout<<“k=“<<k<<“\n”; ::m = 10
cout<<“m=”<<m<<“\n”;
cout<<“::m=” << ::m << “\n”;
}
cout<<“n We are in outer block \n”;
cout<<“m=”<<m<<“\n”;
cout<<“::m=“ << ::m<<“\n”;
getch();
Dalcomp Technologies 26
}
Memory Management Operator
C++ Provides two operators for dynamic memory
allocation & deallocation:-
27
2)delete operator :- When the memory allocated
28
Difference between memory management in c & c++
Memory management in C Memory management in C++
1. Dynamic memory 1. Dynamic memory
management is done using management is done using
function like
operators new & delete.
malloc(),calloc,realloc & free.
2. Operators execute faster.
2. Fuctions require additional
3. No need of any header file.
time.
4. The allocated memory can
3. We have to include header
be initialize to any value.
file to use this function.
5. The operators can be
4. The allocated memory can
only be initialize to 0. overloaded in c++.
existing variable.
existing variable.
30
Reference
Variables
�No memory is allocated to the reference
variable.
31
Example of reference variable
#include<iostream.h>
void main()
{
int x= 10;
clrscr();
cout<<“Value of x:”<<x;
int &rx = x; // reference variable
cout<<“Value of x:”<<rx;
Value of x:
rx = rx + 5;
10
cout<<“Value of x:”<<x; of x: 15
getch();
} Value of x: 10
Value
32
Functions in C++
• There are two types of functions in C programming:
1. Library Functions: are the functions which are
declared in the C++ header files such as ceil(x),
cos(x), exp(x), etc.
double x = 10.3;
int y;
y = int (x); // functional notation
1 2 3 4 5
x
❑Memory Requirement
Total no of bytes required for any array
can be calculated as follows,
bytes = size of given data type *
dim1*dim2*….*dimn.
e.g. int x[5] => bytes = 2*5=10
int y[5][3] => bytes = 2*5*3=30
There are mainly two types of the array:
• One – Dimentional array
• Two – Dimentional array
❑One – Dimentional Array:
A list of items can be given one variable
name using only one dimension and such a
variable is called a one dimensional array.
Syntax:
datatype array-name[size];
Ex: int a[5];
• To access particular slot
syntax: arrayname[logical slotno]
e.g. a[0]- content of 0th slot(logical)
If & is placed before the array name with slot
no then it indicates the address of
corresponding slot.
Initialization of one – dimentional arrays:
⮚ After an array is declared, its element must
be initialized. Otherwise, they will contain
“garbage”. An array can be initialized at
either of the following stages:
1. At compile time
2. At run time
1. Compile time initialization:
Syntax:
Type array-name[size] = {list of values};
The value in the list are separed by commas.
Ex: int a[3] = {0,0,0} ;
int a[3] = {10, 20, 30, 40} ; will not
work. It is illegal in C.
[0][0]
310 275 [0][1]36 [0][2]
Row 0 5
[1][0] [1][1] [1][2]
10 190 325
Row 1
[2][0] [2][1] [2][2]
405 235 240
Row 2
[3][0]
310
[3][1] [3][2]
275 365
Row 3
Initializing two dimentional array:
Ex: int table[2][3] = {0,0,0,1,1,1};
int table[2][3] = {
{0,0,0},
{1,1,1}
};
Initializing two dimentional array:
When the array is completely initialized
with all values, we need not specify the
size of the first dimension. That is, the
statement is permitted.
int table[][3] = {
{0,0,0} ,
{1,1,1)
};
If the value is missing in an initializes, they
are automatically set to zero.
Ex: int table[2][3] ={
{1,1} ,
{2}
};
int m[3][5] = { 0, 0 };
or
int m[3][5] = { {0} , { 0} };
Thank You