Object
oriented
programming
in C++
Lecture 1
Amna Hussain
Object oriented
programming in
c++
Robert lafore
Introduction
Programmers write instructions in various programming
languages to perform their computation tasks such as:
(i) Machine level Language
(ii) Assembly level Language
(iii) High level Language
Machine level Language :
Machine code or machine language is a set of instructions executed directly
by a computer's central processing unit (CPU). Each instruction performs a
very specific task, such as a load, a jump, or an ALU operation on a unit of
data in a CPU register or memory. Every program directly executed by a CPU
is made up of a series of such instructions
Assembly level Language :
An assembly language (or assembler language) is a low-level programming
language for a computer, or other programmable device, in which there is a
very strong (generally one-to-one) correspondence between the language
and the architecture's machine code instructions. Assembly language is
converted into executable machine code by a utility program referred to as
an assembler; the conversion process is referred to as assembly, or
assembling the code.
High level Language :
High-level language is any programming language that enables development
of a program in much simpler programming context and is generally
independent of the computer's hardware architecture. High-level language
has a higher level of abstraction from the computer, and focuses more on the
programming logic rather than the underlying hardware components such as
memory addressing and register utilization.
continue…
The first high-level programming languages were designed in the 1950s. Now there
are dozens of different languages, including Ada , Algol, BASIC, COBOL, C, C++, JAVA,
FORTRAN, LISP, Pascal, and Prolog. Such languages are considered high-level because
they are closer to human languages and farther from machine languages. In contrast,
assembly languages are considered lowlevel because they are very close to machine
languages.
The high-level programming languages are broadly categorized in to two categories:
(iv) Procedure oriented programming(POP) language.
(v) Object oriented programming(OOP) language.
Procedure Oriented Programming Language
Procedure-Oriented Programming (POP) is a programming paradigm
centered around the concept of procedures or functions. In POP, the main
focus is on writing sequences of instructions that operate on data. The
program is typically divided into small functions, each performing a specific
task.
Object Oriented Programing
Object-Oriented Programming (OOP) is a programming paradigm that
organizes software design around data, or objects, rather than functions and
logic. An object in OOP is a self-contained entity that consists of both data
(attributes or properties) and procedures (methods or functions) that operate
on the data.
Procedural Oriented Programming Object-Oriented Programming
In procedural programming, the program is divided into
small parts called functions.
In object-oriented programming, the program is
divided into small parts called objects.
Procedural programming follows a top-down approach.
Object-oriented programming follows a bottom-up
approach.
There is no access specifier in procedural programming.
Object-oriented programming has access specifiers like
private, public, protected, etc.
Adding new data and functions is not easy. Adding new data and function is easy.
Procedural programming does not have any proper way
of hiding data so it is less secure.
Object-oriented programming provides data hiding so
it is more secure.
In procedural programming, overloading is not possible.
Overloading is possible in object-oriented
programming.
In procedural programming, there is no concept of data
hiding and inheritance.
In object-oriented programming, the concept of data
hiding and inheritance is used.
In procedural programming, the function is more
important than the data.
In object-oriented programming, data is more
important than function.
Procedural programming is based on the unreal world.
Object-oriented programming is based on the real
world.
Procedural programming is used for designing medium-
sized programs.
Object-oriented programming is used for designing
large and complex programs.
Procedural programming uses the concept of procedure
abstraction.
Object-oriented programming uses the concept of data
abstraction.
Code reusability absent in procedural programming,
Code reusability present in object-oriented
programming.
Examples: C, FORTRAN, Pascal, Basic, etc. Examples: C++, Java, Python, C#, etc.
BASIC CONCEPTS OF OBJECTS ORIENTED PROGRAMMING
Objects
Classes
Data abstraction and encapsulation
Inheritance
Polymorphism
Dynamic binding
Message passing
Object
Definition: Objects are instances of classes. They represent real-world entities and
have attributes (data) and behaviors (methods/functions).
Example: Think of a Car object that has attributes like color and model, and a
behavior like drive().
Class
A class is a blueprint for creating objects. It defines attributes and
methods.
class Car {
public:
string color;
string model;
void drive() {
cout << "Driving a " << color << " " << model << endl; }};
int main() {
Car myCar; // Creating an object of Car
myCar.color = "red";
myCar.model = "Toyota";
myCar.drive(); // Output: Driving a red Toyota
return 0;}
Data Abstraction and Encapsulation
Data Abstraction: Hiding complex implementation details and exposing only
necessary parts.
Encapsulation: The wrapping up of data and function into a single unit (called
class) is known as encapsulation. The data is not accessible to the outside world
and only those functions which are wrapped in the class can access it. These
functions provide the interface between the objects data and the program.
Inheritance
Inheritance is the process by which objects of one class acquire the properties of
another class. In the concept of inheritance provides the idea of reusablity. This
mean that we can add additional features to an existing class with out modifying it.
This is possible by desining a new class will have the combined features of both
the classes.
Polymorphism
Polymorphism means the ability to take more than one form. An operation may
exhibit different instance. The behaviour depends upon the type of data used in
the operation.
You can use a single operator, like ‘+’, to represent addition for different types of
values, such as integers, floats, and complex numbers. For example, the
expression x + y means the sum of x and y, no matter what type they are. You can
even use the + operator to combine two strings, which means joining them
together.

object oriented programming in c++ introduction lecture 1.pptx

  • 1.
  • 2.
  • 3.
    Introduction Programmers write instructionsin various programming languages to perform their computation tasks such as: (i) Machine level Language (ii) Assembly level Language (iii) High level Language
  • 4.
    Machine level Language: Machine code or machine language is a set of instructions executed directly by a computer's central processing unit (CPU). Each instruction performs a very specific task, such as a load, a jump, or an ALU operation on a unit of data in a CPU register or memory. Every program directly executed by a CPU is made up of a series of such instructions
  • 5.
    Assembly level Language: An assembly language (or assembler language) is a low-level programming language for a computer, or other programmable device, in which there is a very strong (generally one-to-one) correspondence between the language and the architecture's machine code instructions. Assembly language is converted into executable machine code by a utility program referred to as an assembler; the conversion process is referred to as assembly, or assembling the code.
  • 6.
    High level Language: High-level language is any programming language that enables development of a program in much simpler programming context and is generally independent of the computer's hardware architecture. High-level language has a higher level of abstraction from the computer, and focuses more on the programming logic rather than the underlying hardware components such as memory addressing and register utilization.
  • 8.
    continue… The first high-levelprogramming languages were designed in the 1950s. Now there are dozens of different languages, including Ada , Algol, BASIC, COBOL, C, C++, JAVA, FORTRAN, LISP, Pascal, and Prolog. Such languages are considered high-level because they are closer to human languages and farther from machine languages. In contrast, assembly languages are considered lowlevel because they are very close to machine languages. The high-level programming languages are broadly categorized in to two categories: (iv) Procedure oriented programming(POP) language. (v) Object oriented programming(OOP) language.
  • 9.
    Procedure Oriented ProgrammingLanguage Procedure-Oriented Programming (POP) is a programming paradigm centered around the concept of procedures or functions. In POP, the main focus is on writing sequences of instructions that operate on data. The program is typically divided into small functions, each performing a specific task.
  • 11.
    Object Oriented Programing Object-OrientedProgramming (OOP) is a programming paradigm that organizes software design around data, or objects, rather than functions and logic. An object in OOP is a self-contained entity that consists of both data (attributes or properties) and procedures (methods or functions) that operate on the data.
  • 13.
    Procedural Oriented ProgrammingObject-Oriented Programming In procedural programming, the program is divided into small parts called functions. In object-oriented programming, the program is divided into small parts called objects. Procedural programming follows a top-down approach. Object-oriented programming follows a bottom-up approach. There is no access specifier in procedural programming. Object-oriented programming has access specifiers like private, public, protected, etc. Adding new data and functions is not easy. Adding new data and function is easy. Procedural programming does not have any proper way of hiding data so it is less secure. Object-oriented programming provides data hiding so it is more secure. In procedural programming, overloading is not possible. Overloading is possible in object-oriented programming.
  • 14.
    In procedural programming,there is no concept of data hiding and inheritance. In object-oriented programming, the concept of data hiding and inheritance is used. In procedural programming, the function is more important than the data. In object-oriented programming, data is more important than function. Procedural programming is based on the unreal world. Object-oriented programming is based on the real world. Procedural programming is used for designing medium- sized programs. Object-oriented programming is used for designing large and complex programs. Procedural programming uses the concept of procedure abstraction. Object-oriented programming uses the concept of data abstraction. Code reusability absent in procedural programming, Code reusability present in object-oriented programming. Examples: C, FORTRAN, Pascal, Basic, etc. Examples: C++, Java, Python, C#, etc.
  • 15.
    BASIC CONCEPTS OFOBJECTS ORIENTED PROGRAMMING Objects Classes Data abstraction and encapsulation Inheritance Polymorphism Dynamic binding Message passing
  • 16.
    Object Definition: Objects areinstances of classes. They represent real-world entities and have attributes (data) and behaviors (methods/functions). Example: Think of a Car object that has attributes like color and model, and a behavior like drive().
  • 17.
    Class A class isa blueprint for creating objects. It defines attributes and methods.
  • 18.
    class Car { public: stringcolor; string model; void drive() { cout << "Driving a " << color << " " << model << endl; }}; int main() { Car myCar; // Creating an object of Car myCar.color = "red"; myCar.model = "Toyota"; myCar.drive(); // Output: Driving a red Toyota return 0;}
  • 19.
    Data Abstraction andEncapsulation Data Abstraction: Hiding complex implementation details and exposing only necessary parts. Encapsulation: The wrapping up of data and function into a single unit (called class) is known as encapsulation. The data is not accessible to the outside world and only those functions which are wrapped in the class can access it. These functions provide the interface between the objects data and the program.
  • 20.
    Inheritance Inheritance is theprocess by which objects of one class acquire the properties of another class. In the concept of inheritance provides the idea of reusablity. This mean that we can add additional features to an existing class with out modifying it. This is possible by desining a new class will have the combined features of both the classes.
  • 21.
    Polymorphism Polymorphism means theability to take more than one form. An operation may exhibit different instance. The behaviour depends upon the type of data used in the operation. You can use a single operator, like ‘+’, to represent addition for different types of values, such as integers, floats, and complex numbers. For example, the expression x + y means the sum of x and y, no matter what type they are. You can even use the + operator to combine two strings, which means joining them together.