session 9
session 9
CODEX
HUB
CODE ACADEMY
What IS Object Oriented Programming ?
Object-oriented programming(OOP) is aprogramming paradigmbased on
construction.
Procedural Programming
Procedural programming (PP), also known as inline programming takes a top-down
approach. It is about writing a list of instructions to tell the computer what to do
step by step. It relies on procedures or routines.
Procedural Programming Example : Program to Calculate Average of Array Items
CalcAverage ( ) CalcSum ( )
Call To function To Calculate Average
CalcSum ( )
Object-oriented programming(OOP ) is a programming paradigm based
on the concept of "objects"
College Environment
Loyalty
Cart Ba ger
Card
Objects in College Management Program
College Environment
Object
Data
Operations ( )
Object Is comprised Of ?
Product
Data
1-Product _name ,
2-Product _code
3-Price
4- Producer
5-Discount
Operations ( )
1-Modify Price () 2-Set
Discount () 3-Get
Product Name () 4-Get
Product Price ()
Object Is comprised Of ?
Student
Data
1- Student_name ,
2-University_Id
3-Birth_Date
4- Address
5-GPA
6- Study_Level
Operations ( )
1-Modify GPA()
2-Change Study level ()
3-Get Student Name ()
4-Get Student Address ()
Object Is comprised Of ?
Car
Data
1-Factory,
2- Model
3- Fuel_Capacity
4- No_of_doors
5-Color
6-Shape
Operations ( )
1-Set Factory Name()
2-Change Color ()
3-Get Car Info ()
4- ………..
What is Class ? Why we need It ?
Student 1 Student 2 Student 3
Data: Data:
Data: 1- Student_name ,
1- Student_name , 1- Student_name , 2- University_Id
2- University_Id 2- University_Id 5-GPA
3- Birth_Date 3- Birth_Date 6- Study_Level
4- Address
5-GPA
4- Address Operations ( )
6- Study_Level
6- Study_Level 1-Modify GPA()
Operations ( ) 2-Change Study level ()
Operations ( ) 1-Modify GPA() 3-Get Student Name ()
1-Modify GPA() 2-Change Study level () 4-Get Student Address ()
2-Change Study level () 4-Get Student Address ()
3-Get Student Name ()
4-Get Student Address ()
What is Class ? Why we need It ?
Class Student
Student 1 Student 2 Student 3
Data: Data: Data:
Data: 1- Student_name 1- Student_name
2- University_Id 1- Student_name
1- Student_name , 2- University_Id
3- Birth_Date 2- University_Id
3- Birth_Date
2- University_Id 4- Address 3- Birth_Date
4- Address
3- Birth_Date 5-GPA 4- Address
5-GPA
4- Address 6- Study_Level 5-GPA
6- Study_Level
6- Study_Level
5-GPA Operations ( ) Operations ( )
6- Study_Level Operations ( )
1-Modify GPA() 1-Modify GPA()
1-Modify GPA()
Operations ( ) 2-Change Study level () 2-Change Study level ()
2-Change Study level ()
3-Get Student Name () 3-Get Student Name ()
1-Modify GPA() 3-Get Student Name ()
4-Get Student Address () 4-Get Student Address ()
2-Change Study level () 4-Get Student Address ()
3-Get Student Name ()
4-Get Student Address ()
What is Class ? Why we need It ?
Student 1 Student 3
Data: Data:
Class Student 1- Student_name
2- University_Id 1- Student_name
3- Birth_Date 2- University_Id
Data: 4- Address
5-GPA
3- Birth_Date
4- Address
6- Study_Level 5-GPA
1- Student_name , 6- Study_Level
7- Email
2- University_Id 7- Email
Operations ( ) Operations ( )
3- Birth_Date 1-Modify GPA()
1-Modify GPA()
4- Address 2-Change Study level ()
2-Change Study level ()
3-Get Student Name ()
3-Get Student Name ()
5-GPA 4-Get Student Address ()
4-Get Student Address ()
5-Print Student Info ()
6- Study_Level 5-Print Student Info ()
7- Email Student 2
Operations ( ) Data:
1- Student_name
2- University_Id
1-Modify GPA() 3- Birth_Date
4- Address
2-Change Study level () 5-GPA
3-Get Student Name () 6- Study_Level
7- Email
4-Get Student Address ()
5-Print Student Info () Operations ( )
1-Modify GPA()
2-Change Study level ()
3-Get Student Name ()
4-Get Student Address ()
5-Print Student Info ()
What is Class ? Why we need It ?
Rectangle
length
width
setLength()
setWidth()
getLength()
getWidth()
getArea()
Writing the Code
Rectangle
length
public class Rectangle width
{ setLength()
private: setWidth()
getLength()
float length; getWidth()
getArea()
float width;
}
Data Hiding
Access Modifiers
• An access modifier is a C++ keyword that indicates how a field or method
can be accessed.
• public
When the public access modifier is applied to a class member, the
member can be accessed by code inside the class or outside.
• private
When the private access modifier is applied to a class member, the member
cannot be accessed by code outside the class. The member can be accessed
only by methods that are members of the same class.
Data Hiding
An object hides its private data from external code.
Only the class’s own methods can directly access and modify
its private data.
External code must use public methods to interact with private
data.
This improves security, data integrity, and maintainability,
especially in large projects with multiple developers.
Return
Type Rectangle
Access Method
specifier Name -width : float
-length : float
A Rectangle object
The box
variable holds length: 0.0
the address of address
the Rectangle width: 0.0
object.
Thank you