SlideShare uma empresa Scribd logo
1 de 40
Baixar para ler offline
C++ Introduction
Unit-1
Presented by
Er. Jasleen Kaur
Assistant Professor
Applied Science(CSE)
Chandigarh University
Gharuan (Mohali).
1
C vs C++
• C- Structured programming became very popular and
was the main technique of the1980.
• Structured programming enable programmers to write
moderately complex programs fairly easily. However as
the programs grew larger, even the structured approach
failed to show the desired results in terms of bug-free,
easy-to-maintain and reusable programs.
C vs C++
• -Object-Oriented Programming (OOP) is an approach
to program organization and development that
attempts to eliminate some of the pitfalls of
conventional programming methods by incorporating
the best of structured programming features with
several powerful new concepts.
Procedure-Oriented Programming
• Conventional programming using high level language
such as COBOL, FORTRAN and C is commonly known
as Procedure oriented programming.
• In the Procedure oriented approach the problem is
viewed as a sequence of things to be done such as
reading, calculating and printing.
• The primary focus is on functions.
5
• It means “a set of procedures” which is a “set of
subroutines” or a “set of functions“.
• Functions are called repeatedly in a program to
execute tasks performed by them.
• For example, a program may involve-
1. collecting data from user (reading),
2. performing some kind of calculations on the
collected data (calculation), and
3. finally displaying the result to the user when
requested (printing).
• All the 3 tasks of reading, calculating and printing
can be written in a program with the help of 3
different functions which performs these 3
different tasks.
Structure of Procedure-oriented
Procedure-Oriented Programming
• Procedure-Oriented Programming
• Procedure oriented programming basically consists
of writing a list of instructions for the computer to
follow and organizing these instructions into groups
known as functions.
• We normally use a flow chart to organize these
actions and represent the flow of control from one
action to another.
• More importance to functions very little attention to
data that are being used by the functions.
Structure of Procedure-oriented
(Problem)
Procedure-Oriented Programming
• In multi-function program many important data
items are placed as global so that they may be
accessed by all the functions. Each function may
have its own local data.
• In large program it is very difficult to identify what
data is used by which function. In case we need to
revise an external data structure we also need to
revise all function that access it.
Object-Oriented Programming
• OOP treats data as a critical element in the program
development and does not allow it to flow freely
around the system.
• protects data from accidental modification from
outside functions
• OOP allows decomposition of a problem into a
number of entities called objects
Organization of data & function OOP
Striking features of OOP
• Emphasis is on data rather than procedure.
• Programs are divided into what are known as
objects
• 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
Difference between Procedure oriented Programming and
Object Oriented Programming
Procedure-Oriented
Programming
Object Oriented Programming
Divided Into In POP, program is divided into
small parts called functions.
In OOP, program is divided into
parts called objects.
Importance In POP,Importance is not given
to data but to functions as well
as sequence of actions to be
done.
In OOP, Importance is given to
the data rather than
procedures or functions
because it works as a real
world.
Approach POP follows Top Down approach. OOP follows Bottom Up
approach.
Access
Specifiers
POP does not have any access
specifier.
OOP has access specifiers
named Public, Private,
Protected, etc.
Data Moving In POP, Data can move
freely from function to
function in the system.
In OOP, objects can move
and communicate with
each other through
member functions.
Expansion To add new data and
function in POP is not so
easy.
OOP provides an easy way
to add new data and
function.
Data Access In POP, Most function
uses Global data for
sharing that can be
accessed freely from
function to function in
the system.
In OOP, data can not move
easily from function to
function. it can be kept
public or private so we can
control the access of data.
Data Hiding POP does not have any
proper way for hiding
data so it is less secure.
OOP provides Data
Hiding so provides more
security.
Overloading In POP, Overloading is
not possible.
In OOP, overloading is
possible in the form of
Function Overloading
and Operator
Overloading.
Examples Example of POP are : C,
VB, FORTRAN, Pascal.
Example of OOP are :
C++, JAVA, VB.NET,
C#.NET.
• Let's say that you are working for a vehicle parts
manufacturer that needs to update it's online inventory
system.
• Your boss tells you to program two similar but separate
forms for a website, one form that processes information
about cars and one that does the same for trucks.
• For cars, we will need to record the following
information:
Color, Engine Size, Transmission Type, Number of doors
• For trucks, the information will be similar, but slightly
different. We need:
Color, Engine Size, Transmission Type, Cab Size, Towing
Capacity
Real World example for difference
Scenario 1
(addition of bus form)
• Suppose that we suddenly need to add a bus form,
that records the following information:
Color, Engine Size, Transmission Type
Number of passengers
• Procedural: We need to recreate the entire form,
repeating the code for Color, Engine Size, and
Transmission Type.
• OOP: We simply extend the vehicle class with a bus
class and add the method:
numberOfPassengers.
Scenario 2
(sending email instead of storing
database)
Instead of storing color in a database like we previously
did, for some strange reason our client wants the color
emailed to him.
• Procedural: We change three different forms: cars,
trucks, and buses to email the color to the client rather
than storing it in the database.
• OOP: We change the color method in the vehicle class
and because the car, truck, and bus classes all extend
(or inherit from, to put it another way) the vehicle
class, they are automatically updated.
Scenario 3 (moving from generic car
to specific cars)
• We want to move from a generic car to specific makes,
for example: Nissan and Mazda.
• Procedural: We create a new form for each make,
repeating all of the code for generic car information
and adding the code specific to each make.
• OOP: We extend the car class with a Nissan class and a
Mazda class and add methods for each set of unique
information for that car make.
Scenario 4
(bug removal)
• We found a bug in the ‘transmission type area’ of our
form and need to fix it.
• Procedural: We open and update each form.
• OOP: We fix the transmission Type method in the
vehicle class and the change perpetuates in every class
that inherits from it.
Basic Object oriented concepts:
• Class –The entire set of data and code of an object
can be made a user-defined data type with the help
of a class.
• Objects are variable of type class.
• Once a class has been defined we can create any
number of objects belonging to that class.
• A class is thus a collection of objects of similar type.
• Classes are user-defined data types and behave like
the built-in types of a programming language.
Class v/s Structure
• Class usually used for
large programs.
• Can be inherited.
• Can be null or empty.
• Declared methods in
class are automatically
locked (private by
default).
• Class can have
constructor as well as
destructor.
• Structures usually used
for small programs.
• Cannot be inherited.
• Cannot be NULL.
• Methods can’t be
locked (public by
default).
• Structure couldn’t have
constructor and
destructor. 22
Object
• Objects are the basic run-time entities in an object-
oriented system. Object- is an instance(Property) of a
class. Each object has a class which defines its data
and behaviour.
• They may represent a person, a place, a bank
account ,a table of data or any item that the program
must handle.
• Program objects should be chosen such that they
match closely with the real-world objects.
• Objects take up space in the memory and have an
associated address like structure in C.
• When a program is executed the objects interact by
sending messages to one another.
24
Object has a life cycle. They can be created and destroyed
25
• Hence, every object has 3 important features
– 1. Identity (e.g. Name)
– 2. State (e.g. drive bus, fly plane etc.) – these are
assigned on the basis of the object’s characteristics – A
manager object would have different responsibilities
than a developer, since their job descriptions (a
characteristic) would be different:
– 3. Behaviour (Relationships with other objects)– in order
to send requests/messages to each other, objects need
to have some relationship/connection. E.g. A bus driver
needs to have access/connection to a bus in order to
drive it.
26
Structure of a Class in C++
class name {
declarations
constructor definition(s)
method definitions
}
attributes and
symbolic constants
how to create and
initialize objects
how to manipulate
the state of objects
These parts of a class can
actually be in any order
Sample class
#include<iostream.h>
class Pencil
{
public String color = “red”;
public int length;
public float diameter;
setcolor(string);
public void setColor (String newColor)
{
color = yellow;
}
}
Concepts of OOP
• Objects
• Classes
• Abstraction and Encapsulation(Information
Hiding)
• Polymorphism
• Inheritance
• Dynamic Binding
• Message Passing
28
• Data Abstraction-Data Abstraction refers to the act of
re- presenting essential features without including
the back-ground details. It is concerned with
separating the behaviour of a data object from its re-
presentation.
• E.g. Executable file of a program.
• Encapsulation- The process of binding data members
and functions in a class is known as, encapsulation.
Encapsulation is the powerful feature (concept) of
object-oriented programming.
With the help of this concept, data is not accessible to
the outside world and only those functions which are
declared in the class, can access it.
 Displayed code is known using "public" modifier
is known as Abstraction.
 Hiding complex code using "private" modifier is
known as Encapsulation.
31
Encapsulation hides the complexity of code whereas abstraction is
thinking in terms of design way to increase efficiency.
• Information hiding/Data Hiding-
 Data Hiding is similar to encapsulation. Basically,
encapsulating data members and functions in a
class promotes data hiding.
 This concept will help us to provide the essential
features to the users and hide the details. In short,
encapsulating through private access modifier
(label) is known as data hiding.
• Inheritance-
 Inheritance is a process by which objects of new
class acquire the properties of objects of existing
(base) class. It is in hierarchical order.
 The concept of inheritance provides the idea of
reusability.
 This means that we can add additional features to
an existing class without modifying it
• Polymorphism
 Polymorphism is an important object-oriented
programming concept.
 This is a greek term, means the ability to take
more than one form.
 The process of making an operator/method to
show different behaviours in different instances is
known as operator-overloading.
 Using a single function name to perform different
types of tasks is known as function-overloading.
35
• Dynamic Binding
 means code is linked with associated procedural call
at run time (execution time). It is also called as Late
Binding.
 Binding refers to the process that is used to convert
identifiers (such as variable and function names)
into machine language addresses. Although binding
is used for both variables and functions.
 Late binding is slightly less efficient since it involves
an extra level of indirection.
 With early binding, the compiler can tell the CPU to
jump directly to the function’s address.
36
• Message Passing
Message Passing is nothing but sending and receiving
of information by the objects same as people
exchange information. So this helps in building
systems that simulate real life. Following are the basic
steps in message passing.
• Creating classes that define objects and its behavior.
• Creating objects from class definitions
• Establishing communication among objects
• In OOPs, Message Passing involves specifying the
name of objects, the name of the function, and the
information to be sent.
37
For example,
 if “customer” and “account” are to object in a
program, then the customer object may send
a message to the account object requesting
for the bank balance.
 Each object contain data, and code to
manipulate data.
 Objects can interact without having to know
details of each other’s data or code.
 It is sufficient to know the type of message
accepted, and the type of response returned
by the objects. 38
Benefits of OOP
• Through inheritance we can elimate the redundant
code and extend the use of existing code
• Data hiding helps the programmer to build secure
programs that can not be invaded by code in other
parts of the program
• It is possible to have multiple instances of an objects to
co-exist with out any interference (using arrays).
example you want to shoot multiple bullets at same
time in a game.
• It is possible to map objects in the problem domain to
those objects in the program.
• Easy to partition the work in a project based on objects
Data-centred design approach enables us to
capture more details of a model in
implementable form
• Object-oriented systems can be easily
upgraded from small to large systems
• Software complexity can be easily managed.

Mais conteúdo relacionado

Mais procurados

INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++Vraj Patel
 
Method Overloading In Java
Method Overloading In JavaMethod Overloading In Java
Method Overloading In JavaCharthaGaglani
 
Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Sanjit Shaw
 
Operator overloading
Operator overloadingOperator overloading
Operator overloadingBurhan Ahmed
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member FunctionsMOHIT AGARWAL
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator OverloadingNilesh Dalvi
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in clavanya marichamy
 
object oriented Programming ppt
object oriented Programming pptobject oriented Programming ppt
object oriented Programming pptNitesh Dubey
 
Basic concepts of object oriented programming
Basic concepts of object oriented programmingBasic concepts of object oriented programming
Basic concepts of object oriented programmingSachin Sharma
 
Operator overloading C++
Operator overloading C++Operator overloading C++
Operator overloading C++Lahiru Dilshan
 
Pointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cppPointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cpprajshreemuthiah
 
sSCOPE RESOLUTION OPERATOR.pptx
sSCOPE RESOLUTION OPERATOR.pptxsSCOPE RESOLUTION OPERATOR.pptx
sSCOPE RESOLUTION OPERATOR.pptxNidhi Mehra
 

Mais procurados (20)

INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
 
Overloading vs Overriding.pptx
Overloading vs Overriding.pptxOverloading vs Overriding.pptx
Overloading vs Overriding.pptx
 
Method Overloading In Java
Method Overloading In JavaMethod Overloading In Java
Method Overloading In Java
 
Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
 
Getters_And_Setters.pptx
Getters_And_Setters.pptxGetters_And_Setters.pptx
Getters_And_Setters.pptx
 
Unary operator overloading
Unary operator overloadingUnary operator overloading
Unary operator overloading
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
Function overloading ppt
Function overloading pptFunction overloading ppt
Function overloading ppt
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
 
object oriented Programming ppt
object oriented Programming pptobject oriented Programming ppt
object oriented Programming ppt
 
Basic concepts of object oriented programming
Basic concepts of object oriented programmingBasic concepts of object oriented programming
Basic concepts of object oriented programming
 
Class 10
Class 10Class 10
Class 10
 
Operator overloading C++
Operator overloading C++Operator overloading C++
Operator overloading C++
 
Pointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cppPointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cpp
 
Function in C
Function in CFunction in C
Function in C
 
sSCOPE RESOLUTION OPERATOR.pptx
sSCOPE RESOLUTION OPERATOR.pptxsSCOPE RESOLUTION OPERATOR.pptx
sSCOPE RESOLUTION OPERATOR.pptx
 

Semelhante a Chapter 1

SE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPTSE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPTnikshaikh786
 
Oop in c++ lecture 1
Oop in c++  lecture 1Oop in c++  lecture 1
Oop in c++ lecture 1zk75977
 
CPP-Unit 1.pptx
CPP-Unit 1.pptxCPP-Unit 1.pptx
CPP-Unit 1.pptxYashKoli22
 
DOC-20210303-WA0017..pptx,coding stuff in c
DOC-20210303-WA0017..pptx,coding stuff in cDOC-20210303-WA0017..pptx,coding stuff in c
DOC-20210303-WA0017..pptx,coding stuff in cfloraaluoch3
 
Programming using C++ - slides.pptx
Programming using C++ - slides.pptxProgramming using C++ - slides.pptx
Programming using C++ - slides.pptxHeadoftheDepartment
 
2nd PUC computer science chapter 6 oop concept
2nd PUC computer science chapter 6   oop concept2nd PUC computer science chapter 6   oop concept
2nd PUC computer science chapter 6 oop conceptAahwini Esware gowda
 
Object Oriented programming - Introduction
Object Oriented programming - IntroductionObject Oriented programming - Introduction
Object Oriented programming - IntroductionMadishetty Prathibha
 
1. OBJECT ORIENTED PROGRAMMING USING JAVA - OOps Concepts.ppt
1. OBJECT ORIENTED PROGRAMMING USING JAVA - OOps Concepts.ppt1. OBJECT ORIENTED PROGRAMMING USING JAVA - OOps Concepts.ppt
1. OBJECT ORIENTED PROGRAMMING USING JAVA - OOps Concepts.pptsagarjsicg
 
Object Oriented Program Class 12 Computer Science
Object Oriented Program Class 12 Computer ScienceObject Oriented Program Class 12 Computer Science
Object Oriented Program Class 12 Computer ScienceShailendraPandey96
 
Programming In C++
Programming In C++ Programming In C++
Programming In C++ shammi mehra
 
Object oriented programming 1 introduction to oop
Object oriented programming 1 introduction to oopObject oriented programming 1 introduction to oop
Object oriented programming 1 introduction to oopVaibhav Khanna
 
Object Oriented Programming Lecture Notes
Object Oriented Programming Lecture NotesObject Oriented Programming Lecture Notes
Object Oriented Programming Lecture NotesFellowBuddy.com
 

Semelhante a Chapter 1 (20)

[OOP - Lec 02] Why do we need OOP
[OOP - Lec 02] Why do we need OOP[OOP - Lec 02] Why do we need OOP
[OOP - Lec 02] Why do we need OOP
 
SE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPTSE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPT
 
OOP-1.pptx
OOP-1.pptxOOP-1.pptx
OOP-1.pptx
 
Lecture 1.pptx
Lecture 1.pptxLecture 1.pptx
Lecture 1.pptx
 
Unit 2.pptx
Unit 2.pptxUnit 2.pptx
Unit 2.pptx
 
Unit 2.pptx
Unit 2.pptxUnit 2.pptx
Unit 2.pptx
 
Oop in c++ lecture 1
Oop in c++  lecture 1Oop in c++  lecture 1
Oop in c++ lecture 1
 
CPP-Unit 1.pptx
CPP-Unit 1.pptxCPP-Unit 1.pptx
CPP-Unit 1.pptx
 
OOPS_Unit_1
OOPS_Unit_1OOPS_Unit_1
OOPS_Unit_1
 
C++ notes.pdf
C++ notes.pdfC++ notes.pdf
C++ notes.pdf
 
DOC-20210303-WA0017..pptx,coding stuff in c
DOC-20210303-WA0017..pptx,coding stuff in cDOC-20210303-WA0017..pptx,coding stuff in c
DOC-20210303-WA0017..pptx,coding stuff in c
 
Programming using C++ - slides.pptx
Programming using C++ - slides.pptxProgramming using C++ - slides.pptx
Programming using C++ - slides.pptx
 
2nd PUC computer science chapter 6 oop concept
2nd PUC computer science chapter 6   oop concept2nd PUC computer science chapter 6   oop concept
2nd PUC computer science chapter 6 oop concept
 
Object Oriented programming - Introduction
Object Oriented programming - IntroductionObject Oriented programming - Introduction
Object Oriented programming - Introduction
 
1. OBJECT ORIENTED PROGRAMMING USING JAVA - OOps Concepts.ppt
1. OBJECT ORIENTED PROGRAMMING USING JAVA - OOps Concepts.ppt1. OBJECT ORIENTED PROGRAMMING USING JAVA - OOps Concepts.ppt
1. OBJECT ORIENTED PROGRAMMING USING JAVA - OOps Concepts.ppt
 
Object Oriented Program Class 12 Computer Science
Object Oriented Program Class 12 Computer ScienceObject Oriented Program Class 12 Computer Science
Object Oriented Program Class 12 Computer Science
 
Programming In C++
Programming In C++ Programming In C++
Programming In C++
 
Object oriented programming 1 introduction to oop
Object oriented programming 1 introduction to oopObject oriented programming 1 introduction to oop
Object oriented programming 1 introduction to oop
 
Presentation c
Presentation cPresentation c
Presentation c
 
Object Oriented Programming Lecture Notes
Object Oriented Programming Lecture NotesObject Oriented Programming Lecture Notes
Object Oriented Programming Lecture Notes
 

Mais de Jasleen Kaur (Chandigarh University)

Priority Based Congestion Avoidance Hybrid Scheme published in IEEE
Priority Based Congestion Avoidance Hybrid Scheme published in IEEE Priority Based Congestion Avoidance Hybrid Scheme published in IEEE
Priority Based Congestion Avoidance Hybrid Scheme published in IEEE Jasleen Kaur (Chandigarh University)
 

Mais de Jasleen Kaur (Chandigarh University) (19)

Graphs data structures
Graphs data structuresGraphs data structures
Graphs data structures
 
B+ trees and height balance tree
B+ trees and height balance treeB+ trees and height balance tree
B+ trees and height balance tree
 
Basics of c++
Basics of c++Basics of c++
Basics of c++
 
Static variables
Static variablesStatic variables
Static variables
 
Operating system notes pdf
Operating system notes pdfOperating system notes pdf
Operating system notes pdf
 
Priority Based Congestion Avoidance Hybrid Scheme published in IEEE
Priority Based Congestion Avoidance Hybrid Scheme published in IEEE Priority Based Congestion Avoidance Hybrid Scheme published in IEEE
Priority Based Congestion Avoidance Hybrid Scheme published in IEEE
 
03 function overloading
03 function overloading03 function overloading
03 function overloading
 
Chapter 2.datatypes and operators
Chapter 2.datatypes and operatorsChapter 2.datatypes and operators
Chapter 2.datatypes and operators
 
Remote desktop connection
Remote desktop connectionRemote desktop connection
Remote desktop connection
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
 
Calculating garbage value in case of overflow
Calculating garbage value in case of overflowCalculating garbage value in case of overflow
Calculating garbage value in case of overflow
 
Final jasleen ppt
Final jasleen pptFinal jasleen ppt
Final jasleen ppt
 
License Plate recognition
License Plate recognitionLicense Plate recognition
License Plate recognition
 
The solar system
The solar system The solar system
The solar system
 
The solar system
The solar systemThe solar system
The solar system
 
Afforestation environmental issue
Afforestation environmental issueAfforestation environmental issue
Afforestation environmental issue
 
Data aggregation in wireless sensor networks
Data aggregation in wireless sensor networksData aggregation in wireless sensor networks
Data aggregation in wireless sensor networks
 
Network security
Network securityNetwork security
Network security
 

Último

Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 

Último (20)

Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 

Chapter 1

  • 1. C++ Introduction Unit-1 Presented by Er. Jasleen Kaur Assistant Professor Applied Science(CSE) Chandigarh University Gharuan (Mohali). 1
  • 2. C vs C++ • C- Structured programming became very popular and was the main technique of the1980. • Structured programming enable programmers to write moderately complex programs fairly easily. However as the programs grew larger, even the structured approach failed to show the desired results in terms of bug-free, easy-to-maintain and reusable programs.
  • 3. C vs C++ • -Object-Oriented Programming (OOP) is an approach to program organization and development that attempts to eliminate some of the pitfalls of conventional programming methods by incorporating the best of structured programming features with several powerful new concepts.
  • 4. Procedure-Oriented Programming • Conventional programming using high level language such as COBOL, FORTRAN and C is commonly known as Procedure oriented programming. • In the Procedure oriented approach the problem is viewed as a sequence of things to be done such as reading, calculating and printing. • The primary focus is on functions.
  • 5. 5 • It means “a set of procedures” which is a “set of subroutines” or a “set of functions“. • Functions are called repeatedly in a program to execute tasks performed by them. • For example, a program may involve- 1. collecting data from user (reading), 2. performing some kind of calculations on the collected data (calculation), and 3. finally displaying the result to the user when requested (printing). • All the 3 tasks of reading, calculating and printing can be written in a program with the help of 3 different functions which performs these 3 different tasks.
  • 7. Procedure-Oriented Programming • Procedure-Oriented Programming • Procedure oriented programming basically consists of writing a list of instructions for the computer to follow and organizing these instructions into groups known as functions. • We normally use a flow chart to organize these actions and represent the flow of control from one action to another. • More importance to functions very little attention to data that are being used by the functions.
  • 9. Procedure-Oriented Programming • In multi-function program many important data items are placed as global so that they may be accessed by all the functions. Each function may have its own local data. • In large program it is very difficult to identify what data is used by which function. In case we need to revise an external data structure we also need to revise all function that access it.
  • 10. Object-Oriented Programming • OOP treats data as a critical element in the program development and does not allow it to flow freely around the system. • protects data from accidental modification from outside functions • OOP allows decomposition of a problem into a number of entities called objects
  • 11. Organization of data & function OOP
  • 12. Striking features of OOP • Emphasis is on data rather than procedure. • Programs are divided into what are known as objects • 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
  • 13. Difference between Procedure oriented Programming and Object Oriented Programming Procedure-Oriented Programming Object Oriented Programming Divided Into In POP, program is divided into small parts called functions. In OOP, program is divided into parts called objects. Importance In POP,Importance is not given to data but to functions as well as sequence of actions to be done. In OOP, Importance is given to the data rather than procedures or functions because it works as a real world. Approach POP follows Top Down approach. OOP follows Bottom Up approach. Access Specifiers POP does not have any access specifier. OOP has access specifiers named Public, Private, Protected, etc.
  • 14. Data Moving In POP, Data can move freely from function to function in the system. In OOP, objects can move and communicate with each other through member functions. Expansion To add new data and function in POP is not so easy. OOP provides an easy way to add new data and function. Data Access In POP, Most function uses Global data for sharing that can be accessed freely from function to function in the system. In OOP, data can not move easily from function to function. it can be kept public or private so we can control the access of data.
  • 15. Data Hiding POP does not have any proper way for hiding data so it is less secure. OOP provides Data Hiding so provides more security. Overloading In POP, Overloading is not possible. In OOP, overloading is possible in the form of Function Overloading and Operator Overloading. Examples Example of POP are : C, VB, FORTRAN, Pascal. Example of OOP are : C++, JAVA, VB.NET, C#.NET.
  • 16. • Let's say that you are working for a vehicle parts manufacturer that needs to update it's online inventory system. • Your boss tells you to program two similar but separate forms for a website, one form that processes information about cars and one that does the same for trucks. • For cars, we will need to record the following information: Color, Engine Size, Transmission Type, Number of doors • For trucks, the information will be similar, but slightly different. We need: Color, Engine Size, Transmission Type, Cab Size, Towing Capacity Real World example for difference
  • 17. Scenario 1 (addition of bus form) • Suppose that we suddenly need to add a bus form, that records the following information: Color, Engine Size, Transmission Type Number of passengers • Procedural: We need to recreate the entire form, repeating the code for Color, Engine Size, and Transmission Type. • OOP: We simply extend the vehicle class with a bus class and add the method: numberOfPassengers.
  • 18. Scenario 2 (sending email instead of storing database) Instead of storing color in a database like we previously did, for some strange reason our client wants the color emailed to him. • Procedural: We change three different forms: cars, trucks, and buses to email the color to the client rather than storing it in the database. • OOP: We change the color method in the vehicle class and because the car, truck, and bus classes all extend (or inherit from, to put it another way) the vehicle class, they are automatically updated.
  • 19. Scenario 3 (moving from generic car to specific cars) • We want to move from a generic car to specific makes, for example: Nissan and Mazda. • Procedural: We create a new form for each make, repeating all of the code for generic car information and adding the code specific to each make. • OOP: We extend the car class with a Nissan class and a Mazda class and add methods for each set of unique information for that car make.
  • 20. Scenario 4 (bug removal) • We found a bug in the ‘transmission type area’ of our form and need to fix it. • Procedural: We open and update each form. • OOP: We fix the transmission Type method in the vehicle class and the change perpetuates in every class that inherits from it.
  • 21. Basic Object oriented concepts: • Class –The entire set of data and code of an object can be made a user-defined data type with the help of a class. • Objects are variable of type class. • Once a class has been defined we can create any number of objects belonging to that class. • A class is thus a collection of objects of similar type. • Classes are user-defined data types and behave like the built-in types of a programming language.
  • 22. Class v/s Structure • Class usually used for large programs. • Can be inherited. • Can be null or empty. • Declared methods in class are automatically locked (private by default). • Class can have constructor as well as destructor. • Structures usually used for small programs. • Cannot be inherited. • Cannot be NULL. • Methods can’t be locked (public by default). • Structure couldn’t have constructor and destructor. 22
  • 23. Object • Objects are the basic run-time entities in an object- oriented system. Object- is an instance(Property) of a class. Each object has a class which defines its data and behaviour. • They may represent a person, a place, a bank account ,a table of data or any item that the program must handle. • Program objects should be chosen such that they match closely with the real-world objects. • Objects take up space in the memory and have an associated address like structure in C. • When a program is executed the objects interact by sending messages to one another.
  • 24. 24 Object has a life cycle. They can be created and destroyed
  • 25. 25 • Hence, every object has 3 important features – 1. Identity (e.g. Name) – 2. State (e.g. drive bus, fly plane etc.) – these are assigned on the basis of the object’s characteristics – A manager object would have different responsibilities than a developer, since their job descriptions (a characteristic) would be different: – 3. Behaviour (Relationships with other objects)– in order to send requests/messages to each other, objects need to have some relationship/connection. E.g. A bus driver needs to have access/connection to a bus in order to drive it.
  • 26. 26 Structure of a Class in C++ class name { declarations constructor definition(s) method definitions } attributes and symbolic constants how to create and initialize objects how to manipulate the state of objects These parts of a class can actually be in any order
  • 27. Sample class #include<iostream.h> class Pencil { public String color = “red”; public int length; public float diameter; setcolor(string); public void setColor (String newColor) { color = yellow; } }
  • 28. Concepts of OOP • Objects • Classes • Abstraction and Encapsulation(Information Hiding) • Polymorphism • Inheritance • Dynamic Binding • Message Passing 28
  • 29. • Data Abstraction-Data Abstraction refers to the act of re- presenting essential features without including the back-ground details. It is concerned with separating the behaviour of a data object from its re- presentation. • E.g. Executable file of a program.
  • 30. • Encapsulation- The process of binding data members and functions in a class is known as, encapsulation. Encapsulation is the powerful feature (concept) of object-oriented programming. With the help of this concept, data is not accessible to the outside world and only those functions which are declared in the class, can access it.  Displayed code is known using "public" modifier is known as Abstraction.  Hiding complex code using "private" modifier is known as Encapsulation.
  • 31. 31 Encapsulation hides the complexity of code whereas abstraction is thinking in terms of design way to increase efficiency.
  • 32. • Information hiding/Data Hiding-  Data Hiding is similar to encapsulation. Basically, encapsulating data members and functions in a class promotes data hiding.  This concept will help us to provide the essential features to the users and hide the details. In short, encapsulating through private access modifier (label) is known as data hiding.
  • 33. • Inheritance-  Inheritance is a process by which objects of new class acquire the properties of objects of existing (base) class. It is in hierarchical order.  The concept of inheritance provides the idea of reusability.  This means that we can add additional features to an existing class without modifying it
  • 34. • Polymorphism  Polymorphism is an important object-oriented programming concept.  This is a greek term, means the ability to take more than one form.  The process of making an operator/method to show different behaviours in different instances is known as operator-overloading.  Using a single function name to perform different types of tasks is known as function-overloading.
  • 35. 35
  • 36. • Dynamic Binding  means code is linked with associated procedural call at run time (execution time). It is also called as Late Binding.  Binding refers to the process that is used to convert identifiers (such as variable and function names) into machine language addresses. Although binding is used for both variables and functions.  Late binding is slightly less efficient since it involves an extra level of indirection.  With early binding, the compiler can tell the CPU to jump directly to the function’s address. 36
  • 37. • Message Passing Message Passing is nothing but sending and receiving of information by the objects same as people exchange information. So this helps in building systems that simulate real life. Following are the basic steps in message passing. • Creating classes that define objects and its behavior. • Creating objects from class definitions • Establishing communication among objects • In OOPs, Message Passing involves specifying the name of objects, the name of the function, and the information to be sent. 37
  • 38. For example,  if “customer” and “account” are to object in a program, then the customer object may send a message to the account object requesting for the bank balance.  Each object contain data, and code to manipulate data.  Objects can interact without having to know details of each other’s data or code.  It is sufficient to know the type of message accepted, and the type of response returned by the objects. 38
  • 39. Benefits of OOP • Through inheritance we can elimate the redundant code and extend the use of existing code • Data hiding helps the programmer to build secure programs that can not be invaded by code in other parts of the program • It is possible to have multiple instances of an objects to co-exist with out any interference (using arrays). example you want to shoot multiple bullets at same time in a game. • It is possible to map objects in the problem domain to those objects in the program. • Easy to partition the work in a project based on objects
  • 40. Data-centred design approach enables us to capture more details of a model in implementable form • Object-oriented systems can be easily upgraded from small to large systems • Software complexity can be easily managed.