CSE 205
Object Oriented Programming Language
Lec Tasfia Sara
tasfiasara1000@gmail.com1
Lec Tasfia Sara
Course Teacher Introduction
Lec Tasfia Sara Lec Khaled Hasan Irfan
MIST CSE-20 MIST CSE-20
VNSC NDC, ISC
Lec Tasfia Sara
Lec Tasfia Sara
Content
Lec Tasfia Sara
Reference
Books
1. Teach Yourself C++ - Herbert Schildt
2. Object Oriented Programming with C++ - E Balagurusamy
3. Programming with C++ - Schaum’s Outline Series
4. Complete Reference C++ - Herbert Schildt
Online
1. [Link]
2. [Link]
3. [Link]
5
Lec Tasfia Sara
Google Classroom Code:
lrt4mjr5
Lec Tasfia Sara
Assessment Strategy
Components Grading
Class Test 20%
Continuous Assessment Class Participation and Attendance 10%
(40%)
Mid Term 10%
Final Examination 60%
Total Marks 100%
Lec Tasfia Sara
Introduction
Lec Tasfia Sara
Introduce yourself
1. Name
2. School, College
3. Home district
4. One superpower you wish you had!
5. What did you do during your semester break?
Lec Tasfia Sara
What is OOP?
Lec Tasfia Sara
OOP
● Object-Oriented Programming (OOP) is a programming
paradigm, a way of organizing and writing code, where
everything revolves around “objects”.
● Object-oriented programming (OOP) languages use objects to
structure code, which are instances of classes that contain
data and methods.
● Popular OOP languages include C++, Java, Python, C#, Ruby,
JavaScript, and PHP.
- We are going to learn C++ in this course.
Lec Tasfia Sara
Object Oriented Programming: Advantages
❏ It is possible to map objects in the problem domain to those objects in
the program.
🔁Real-world objects = Program objects
You can think of real things, like a student, a car, or a book- and turn them directly into code objects. This makes
programs easier to understand and design.
❏ Data hiding helps the programmer to build secure programs that cannot
be invaded by code in other parts of the program.
🔒 Data hiding = Security
You can hide the sensitive parts of your code (like passwords or internal calculations) so that no other part of the
program can mess with it accidentally.
❏ Through inheritance, we can eliminate the redundant code and extend
the use of existing code.
🧬 Inheritance = Less Rewriting
You can reuse code from existing classes instead of writing everything from scratch. 12
Lec Tasfia Sara
Object Oriented Programming: Advantages
❏ It is possible to have multiple instances of an objects to co-exist without
any interference.
🔄 Multiple objects = No conflict
You can create many objects (like many students or many cars) and they all work independently.
❏ Easy to partition the work in a project based on objects.
🧱 Easy teamwork = Better project management
You can divide your whole program into objects, and assign different objects to different people in a team.
❏ New data and functions can be easily added whenever necessary.
13
Lec Tasfia Sara
C++
Lec Tasfia Sara
15
Reference: Difference between C and C++
Lec Tasfia Sara
16
Lec Tasfia Sara
History
❏ The C++ programming language has a history going back to 1979,
when Bjarne Stroustrup was doing work for his Ph.D. thesis.
❏ He began to work on "C with Classes", which as the name implies
was meant to be a superset of the C language. C++ programming
language was evolved from “C with Classes” in 1983 at bell
laboratories of AT&T (American Telephone & Telegraph), located in
U.S.A.
❏ It was developed for adding a feature of OOP (Object Oriented
Programming) in C without significantly changing the C component.
Reference: History 17
Lec Tasfia Sara
What is C++?
“C makes it easy to shoot yourself in the foot;
C++ makes it harder, but when you do it blows your whole leg off.”
― Bjarne Stroustrup
❏ C++ is a high-level Object Oriented Programming
language with sufficient lower level functionality (in-line
assembly code, access to memory locations, etc)
❏ C++ is (almost exactly) a superset of C
❏ At a high level: C++ ≈ (C + OOP)
18
Lec Tasfia Sara
What was C?
❏ Procedural Language
❏ Good for general purpose programming
❏ Supports standard Data Types, Operators and Control
Flow
❏ Little problematic to handle large programs.
19
Lec Tasfia Sara
Procedural Programming: C
Procedural Programs:
● Split a program into tasks and subtasks
● Write functions to carry out the tasks
● Instruct computer to execute the functions in a sequence
Problems
● Large amount of data and intricate flow of tasks: complex and
un-maintainable
● More importance to algorithms & functions than data being used by the
functions
● Multi-function programs- shared data items are placed as global
● Changes in data structure affects functions and involves re-writing code
20
Lec Tasfia Sara
21
Lec Tasfia Sara
Object-Oriented Programming: C++
❏ It is C and some more.
❏ Concise
❏ Maintainable (Cause its Object Oriented)
❏ Portable (supports nearly any processor)
❏ OOP treats data as a critical element in the program
development.
❏ Does not allow data to flow freely around the system.
❏ Package data and code as objects
❏ Programs model the problem using abstract objects and
interactions between them. Eg : Complex numbers (x+ yi)
22
Lec Tasfia Sara
Why learn C++ over C?
❏ C++ supports OOP features.
❏ There is Stronger Type Checking in C++
❏ All the OOP features in C++ like Abstraction, Encapsulation,
Inheritance etc makes it more worthy and useful for programmers.
❏ C++ supports and allows user-defined operators (i.e Operator
Overloading) and function overloading is also supported in it.
❏ Exception Handling
❏ The concept of Virtual functions and also Constructors and
Destructors for Objects.
❏ If a function return type is mentioned it must return a value in
C++. In C it is optional. 23
Lec Tasfia Sara
When to use C++
● Large projects
● System applications
● Graphics
● Data Structures
● Speed is an issue
● Changes in functionality required
● Need exceptions and error handling
● Want to speed up your scripts
24
Lec Tasfia Sara
When not to use C++
● Small system programs (use C)
● Fast prototyping (use Visual Basic/Cold Fusion)
● Web-based applications (use PHP/Perl/Python)
25
Lec Tasfia Sara
Homework
● Differences of C and C++
● Advantages of OOP
● Difference between procedural language and object
oriented language
● Why C over C++?!?
26
Lec Tasfia Sara
Features of OOP ***
● Data Abstraction
● Encapsulation
● Inheritance
● Polymorphism
● Messaging
27
Lec Tasfia Sara
Before proceeding, let’s see an example!
28
Lec Tasfia Sara
Structure in C
29
Lec Tasfia Sara
Structure in C++
30
Lec Tasfia Sara
Class in C++
31
Lec Tasfia Sara
Concept: Class
32
Lec Tasfia Sara
Concept: Class
33
Lec Tasfia Sara
Concept: Class
● A class is nothing but a way to represent a group of
logically related data members and member functions.
● They may or may not be of similar data types.
● With the addition to data types, classes give you the
provision to keep your data secure and add functions
within the class, unlike what we saw in structures in C.
34
Lec Tasfia Sara
Concept: Class
35
Lec Tasfia Sara
Concept: Class
36
Lec Tasfia Sara
Significance of Class in C++
● It helps you keep your data safe and secure from the outside world.
● If we wish to grant access to certain data, it can be achieved with
the help of access specifiers available in classes.
● Classes support the concept of inheritance that reduces code
redundancy and makes things easier for the programmer by
allowing a derived class to directly inherit all the properties of the
base class and enhances the readability of the code.
● It allows you to club both data elements and the various functions
associated with it under one unit.
37
Lec Tasfia Sara
Concept: Object
38
Lec Tasfia Sara
Concept: Object
● An object is basically a variable of a user-defined data type, that is, a class.
In simple words, a class acts as a data type, and an object acts as its
variable.
● Unless you create an object, you cannot access the members of a class.
Thus, it is of utmost importance to create objects.
39
Lec Tasfia Sara
Concept: Object
● An object is basically a variable of a user-defined data type, that is, a class.
In simple words, a class acts as a data type, and an object acts as its
variable.
● Unless you create an object, you cannot access the members of a class.
Thus, it is of utmost importance to create objects.
● My name is Sara, and I am an instance/object of class Female.
● When we say, HumanBeing, Male or Female, we just mean a type/kind.
● You, your friend, me - we are the forms of these classes. We have a
physical existence while a class is just a logical definition. We are the
objects/instances.
● When a class is defined, no memory is allocated but when it is
instantiated (i.e. an object is created) memory is allocated.
40
Lec Tasfia Sara
Class and Object
41
Lec Tasfia Sara
So far, we learned class and object;
now we can understand about the
features!
42
Lec Tasfia Sara
Abstraction
43
Lec Tasfia Sara
Abstraction
● Abstraction refers to the act of representing essential features without
including the background details or explanations.
● Since the classes use the concept of data abstraction, they are known as
Abstract Data Types.
● Classes use the concept of abstraction and are defined as a list of abstract
attributes such as size, weight and cost. Functions operate on these
attributes.
● Continuing our example, Human Being's can talk, walk, hear, eat, but the
details are hidden from the outside world.
● We can take our skin as the Abstraction factor in our case, hiding the
inside mechanism.
44
Lec Tasfia Sara
Data Abstraction
45
Lec Tasfia Sara
Encapsulation
46
Lec Tasfia Sara
Encapsulation
● It is the mechanism that binds together code and the data it manipulates,
and
keeps safe from outside interference and misuse. when code and data are
bind together in this fashion, an object is created.
● The wrapping up of data and functions into a single unit.
● The data is not accessible to the outside world and only those functions
which
are wrapped in the class can access it.
● This insulation of the data from direct access by the program is called data
hiding or information hiding.
47
Lec Tasfia Sara
Inheritance
48
Lec Tasfia Sara
Inheritance
● Consider the HumanBeing class, which has properties like hands, legs,
eyes
etc, and functions like walk, talk, eat, see etc.
● Male and Female are also classes, but most of the properties and
functions
are included in HumanBeing, hence they can inherit everything from class
HumanBeing using the concept of Inheritance.
● Concept of inheritance provides the idea of reusability.
● Objects of one class acquire the properties of objects of another class.
● Each derived class shares common characteristics with the parent class.
● Possible to add additional features to an existing class without modifying
it.
49
Lec Tasfia Sara
Inheritance
CSE_Student EECE_Student
CSE23_Student CSE24_Student
50
Lec Tasfia Sara
Types of Inheritance
● Single Level Inheritance
● Multilevel Inheritance
● Multiple Inheritance
● Hybrid Inheritance
51
Lec Tasfia Sara
Types of Inheritance
52
Lec Tasfia Sara
Thank you!
Special Thanks To:
Raiyan Sir
Muhaimin Sir
For some of their valuable resources & teaching materials! 54
Lec Tasfia Sara