0% found this document useful (0 votes)
14 views35 pages

Lec 01-03

The document outlines the fundamentals of Object-Oriented Programming (OOP) in C++, covering programming language concepts, types, and the need for OOP. It discusses the evolution of programming languages, their classifications, and the characteristics of OOP such as encapsulation, inheritance, and polymorphism. Recommended textbooks and references for further reading are also provided.

Uploaded by

hijabmemon03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views35 pages

Lec 01-03

The document outlines the fundamentals of Object-Oriented Programming (OOP) in C++, covering programming language concepts, types, and the need for OOP. It discusses the evolution of programming languages, their classifications, and the characteristics of OOP such as encapsulation, inheritance, and polymorphism. Recommended textbooks and references for further reading are also provided.

Uploaded by

hijabmemon03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 35

Object Oriented Programming:

C++
Lecture – 01 and 02

Subject Teacher:
Dr. Shamshad Lakho

Quaid-e-Awam University of Engineering, Science, and Technology,


Nawabshah
Lecture Outline
• Programming languages concepts
1. What is a programming language?
2. Why do we need programming languages?
3. What are the types of programming languages?

• Categories of programming languages


– Procedural and Object-Oriented Programming
languages
Recommended Books
• TEXT BOOKS:
1. “Object Oriented Programming in TURBO C++, Latest Edition”, By Robert
Lafore
2. “C++ Programming Language, Latest Edition”, By Bjarne Stroustrup
3. “How to Program C++, Latest Edition”, By H.M. Dietel

• REFERENCE BOOKS:
1. “C/C++: The Complete Reference, Latest Edition”, By Herbert Schildt
2. “Understanding Pointers in C, Latest Edition”, By Yashvant Kanetkar
3. “Programming with C++, Latest Edition”, By John R Hubbard
Programming Languages Concepts
1. What is a programming language?
– A "programming language" is a means of communication
between a human being (programmer) and a computer. A
programmer uses this means of communication in order to
give the computer instructions. These instructions are
called "programs".
– A programming language is a set of rules that provides a
way of telling a computer what operations to perform.
– A programming language can be used to write programs
that control the hardware e.g.: Embedded processor in
Refrigerator, Air conditioner, Microwave oven etc.
Programming Languages Concepts
1. What is a programming language?

– The description of a programming language is usually


split into the two components of syntax (form) and
semantics (meaning).

– A program can execute only if it is both syntactically


and semantically correct.
Programming Languages Concepts
2. Why do we need programming languages?

A computer cannot understand our language that we use in our day to day conversations,
and likewise, we cannot understand the binary language that the computer uses to do it’s
tasks.

Programming languages have been developed for the purpose of communicating with
computers.

1. Facilitate users in performing tasks which are:


1. Faster,
2. Correct, and
3. Economically cheaper
Programming Languages Concepts
3. What are the types of programming language?

– Programming languages may be divided into three (03)


general types:
1. Machine languages
2. Assembly languages
3. High-level languages
Programming Languages Concepts
• Machine languages
– Machine language is the only language that a computer understands
– Strings of 0’s and 1’s telling computers to perform basic operations
one at a time; e.g.:
01001110
00111001
01101010
– Machine language is a low-level programming language. It is easily
understood by computers but difficult to read by people.
– Machine dependent i.e., a code written for one machine may not
run on the other.
– Programming in machine languages is too slow, tedious, and error-
prone.
Programming Languages Concepts
• Assembly languages
– Assembly language is a representation of machine language
– Symbolic operation codes replaced binary operation codes; e.g.:
LOAD R1, sessional
LOAD R2, final
ADD R1, R2
STORE total_marks
– The advantage of assembly language is that its instructions are readable. For
example, assembly language statements like LOAD and ADD are more
recognizable than sequences of 0s and 1s.
– Assembly language programs needed to be “assembled” for execution by the
computer. Each assembly language instruction is translated into one machine
language instruction.
– Very efficient code and easier to write.
– Another disadvantage of assembly language is that it is not portable. In other
words, assembly language programs are specific to a particular hardware.
Programming Languages Concepts
• High-level languages
– Closer to English but included simple mathematical
notation; e.g.:
total_marks = sessional + final
– Programs written in source code which must be
translated into machine language programs called
object code.
– The translation of source code to object code is
accomplished by a machine language system program
called a compiler.
Generation of Programming
Languages
• All computer languages can be classified in the following
five generations:

– Machine Language (1st Generation Language – 1945)


– Assembly Language(2nd Generation Language – 1950s)
– High Level Language (3rd Generation Language – 1960s)
– Very High Level Language (4th Generation Language – 1970s-
1990)
– Natural Language (5th Generation Language – 1980)
Generation of Programming
Languages
• Machine Language

– The set of instruction codes, in binary, which can be


directly understood by the CPU without translating the
program.
Generation of Programming
Languages
• Assembly Language

• A low-level language.
• Allows the programmer to use abbreviations or words
instead of binary numbers, known as mnemonics.
• A program called an assembler transforms assembly
language into machine code.
Generation of Programming
Languages
• High-Level Language
• Also known as Procedure/Problem Oriented Language.
• Machine independent.
Examples of HLLs
FORTRAN Formula Translation Language
COBOL Common Business Oriented Language
BASIC Beginners All Purpose Symbolic Instruction Code
PL/I Programming Language I
PASCAL Named after Blaise Pascal, a French Philosopher
C General Purpose Programming Language
C++ Object Oriented Programming Language
JAVA Object Oriented Programming Language
Generation of Programming
Languages
• Very High Level Language

• Also known as 4GL or non-procedural language.


• Machine independent.
• Easier to learn and use.
• Easier to maintain.
• The tools are:
– DBMS
– Report Generators
– Query Languages
– Application Generators.
• Examples: SQL and ORACLE
Generation of Programming
Languages
• Natural Languages
• Natural languages are of two types:
• Ordinary Human Language: English, German, Spanish etc.
• Programming Languages: that use human language to give people
more natural connection with computers with 4GLs. Using AI
(Artificial Intelligence), the attempt to make computers which will
have human like qualities such as learning, reasoning,
communicating, seeing and hearing etc.
• Prolog, Lisp, OPS5 and Mercury are the best known 5th generation
languages.
Broad Categories of Programming
Languages
• Programming languages may be divided into two
(02) broad categories:

– Traditional/Procedural programming languages

– Object-oriented programming languages


Why Do We Need OOP?

Object-oriented programming was developed because


limitations were discovered in earlier approaches to
programming.
Why Do We Need OOP?

• Traditional/Procedural languages
– A program in a procedural language is a list of
instructions.
– There are two related problems with procedural
languages:
1. Functions have unrestricted access to global data
2. Unrelated functions and data
Why Do We Need OOP?

• Procedural languages: Unrestricted access


– Procedural languages involve two types of data: local
and global
Why Do We Need OOP?
• Procedural languages: Unrestricted access
– In large programs, there are many functions and many global data. This
large number of connections causes problems in several ways:
1. Program structure is difficult to conceptualize
2. Program is difficult to modify e.g., changing global data from short to long. A change made
in a global data item may necessitate rewriting all the functions that access that item.
Why Do We Need OOP?
• Procedural languages: Unrelated functions and data
– The second – and more important – problem with the
procedural paradigm is that its arrangement of separate data
and functions does a poor job of modelling things (objects) in
the real world e.g., people and cars.
– Real world objects have both attributes (data) and behaviour
(functions)
• The Object-oriented approach:
– The fundamental idea behind object-oriented language is to
combine into a single unit both data and functions that operate
on that data.
• Such a unit is called an Object.
OOP Approach
OOP Approach
• An object’s functions (called member functions in C++)
typically provide the only way to access its data

• Object’s data and member functions are said to be


encapsulated. They can’t be accessed directly without
the permission of the object and are thus safe from
accidental modifications

• Example:
– Objects as departments – such as I.T, finance, examination, and
so on - in a University
OOP Approach: University Paradigm
BCS Dept.

Dept. Data

Dead of
Dept.

Clerks

Finance Dept. Examine Dept.


Financial Examine
Data Data

Director Controller Of
Finance Examination

Financial
Clerks
Assistant
Characteristics of OO Languages
• Objects
• Classes
• Inheritance
• Reusability
• Polymorphism and Overloading
Characteristics of OO Languages: Objects

• In OOP program is divided into object rather


than functions.
• Object can be anything:
– Physical objects
• Automobiles in a traffic-flow simulation
• Countries in an economics model
– Human entities
• Employees
• Customers
• Departments
– Components in computer games
• Cars in auto race
Characteristics of OO Languages: Objects

• An Object is a collection of data members and


associated member functions also known as
methods.
Characteristics of OO Languages:
Classes
• A class serves as a plan, template or specification for
a number of similar objects.

• A class specifies what data and what functions will be


included in objects of that class

• Examples: Vehicle, Animal, and Students classes


Characteristics of OO Languages:
Classes
Characteristics of OO Languages:
Inheritance

• Inheritance is the process of creating a new classes


(derived classes) from existing classes (based classes).
– Example: Cars, Trucks, and Buses are class types derived from
Vehicle class
Characteristics of OO Languages:
Inheritance
Characteristics of OO Languages:
Reusability
• Once a class is written, created, and debugged, it can
be distributed to other programmers for use in their
own program. This is called reusability.

• It is similar to the way a library of functions in a


procedural language can be incorporated into different
programs.

• Reusability reduces implementation time and the cost.


Characteristics of OO Languages:
Polymorphism and Operator overloading
• Using operators or functions in different ways, depending on
what they are operating on, is called polymorphism (one thing
with several distinct forms).
Characteristics of OO Languages:
Polymorphism and Operator overloading

• When an existing operator, such as + or =, is given the


capability to operate on a new data type, it is said to be
overloaded.

You might also like