Unit 1 (Topic 1)
Unit 1 (Topic 1)
Unit 1 (Topic 1)
Unit – 1 (Topic – 1)
Principles of object oriented programming
Tokens, expressions and control statements
Prepared By
Prof. Shah Brijesh
Procedure Oriented Programming
• In Procedure Oriented Programming(POP), the problem is
viewed as a sequence of things to be done such as reading,
calculating and printing (Just Like an Algorithm).
• It is accomplish with functions.
• A typical program structure for POP is shown in below fig.
Main Program
Function1 Function3
Function2
• Large Programs are divided into smaller programs known as
functions.
• Most of the functions share global data.
Procedure Oriented Programming
• Data move openly around the system from function to
function.
• Functions Transform data from one form to another.
• Follows Top – Down Approach in program design.
• It means it starts execution From the top means opening
brace of main() and ends it at corresponding closing brace.
Object Oriented Programming
• OOP allows decomposition of a problem into a number of
entities called objects and then builds data and functions
around theses objects.
• The data of an object can be accessed only by the functions
associated with that objects.
Object1 Object2
Data Data
Communication
Functions Functions
Object3
Data
Functions
Object Oriented Programming
• Emphasis Is on data rather than procedure.
• Programs are divided into objects.
• Data structures are designed such that they characterize the
object.
• Functions that operate on the data of an object are tied
together in the data structure.
• Data is hidden and can not be accessed by external functions.
• Objects may communicate with each other through functions.
• New data and functions can be easily added whenever
necessary.
• Follows Bottom – Up approach in program design.
Basic Concepts Of OOP
• Following are the basic concepts of OOP.
1. Objects
2. Classes
3. Data Abstraction
4. Encapsulation
5. Inheritance
6. Polymorphism
7. Dynamic Binding
8. Message Passing
Basic Concepts Of OOP
1. Objects:
We can define object in following three different methods.
a. Objects are basic run time entities in an object oriented
system. It can be any thing place, person, an account on
which we can create programs.
#include<iostream.h>
int main ()
{
int a;
cin>>a;
a = a+1;
return 0;
}
#include<iostream>
int main ()
{
int a;
cin>>a;
a=a+1;
cout<<a;
return 0;
}
int a = 0;
a==0?cout<<“Zero”:a%2==0?cout<<“Even”:cout<<“Odd”;
TOKENS OF C++ (Operators)
Bitwise Operators:
-> Bitwise operator works on bits
-> It perform bit-by-bit operation.
-> Generally it works only with integers.
-> How bitwise operators works:
=> First it convert given decimal value into binary
=> Then find the result
=> Again convert binary result into decimal and return it.
Operator Meaning Example
[a=22, b=13]
& Bitwise And a&b => 22&13
=> 10110 & 01101
=> 00100 (4)
Note : Binary value of 22 is 10110 and 13 is 1101
TOKENS OF C++ (Operators)
Bitwise Operators:
Operator Meaning Example
| Bitwise Or a|b => 22|13
=> 10110 | 01101
=> 11111 (31)
^ Bitwise XOR a^b => 22^13
=> 10110 ^ 01101
=> 11011 (27)
>> Shift Right a>>2 => 22 >> 2
=> 10110 >> 2
=> 101 (5)
<< Shift Left a<<2 => 22 << 2
=> 10110 << 2
=> 1011000 (88)
~ 1’s Complement ~a => ~22 => ~10110
[It Convert all 0 into 1 => 1111111111101001
and all 1 into 0] (65513)
TOKENS OF C++ (Operators)
More On Operator:
-> There are some special operators in c++.
=> Scope Resolution Operator
=> Member Dereferencing Operator
=> Memory Management Operator
=> Manipulators
=> Type Cast Operator