SlideShare a Scribd company logo
1
CSC241: Object Oriented Programming
Lecture No 01
2
Aim of the course
• This course provides
– motivation of object oriented programming
language
– in depth knowledge of the various concepts of
object oriented programming and its
implementation in C++
3
Course book
• Text book
– C++ How to program by Deitel and Deitel
• Reference books
– Waite Group’s Object oriented programming in
C++, Robert Lafore
4
Course outline
Classes, Objects, Member functions, Objects as data types, Constructors and
destructors, Overloaded constructor
The default copy constructor, Returning objects from functions, objects and
memory, Static class data, Constant member functions, Constant objects
Base classes and derived classes, Derived class constructors, Overloading
member functions, Scope resolution, Abstract classes, Public and private
inheritance, Levels of inheritance, Multiple inheritance, Aggregation and
composition
New and delete operators, Pointers to objects, Virtual functions and late
binding, Abstract classes and pure virtual functions, Virtual destructors, Virtual
base classes, Friend functions and friend classes, Static functions, this pointer,
Dynamic type information
Motivation for exception handling, Try-catch block, Throwing an exception,
Catching multiple exceptions
Streams and files, Templates
5
Marks distribution
• Assignments: 10%
• Quizzes: 15%
• Sessional exam 01: 10%
• Sessional exam 02: 15%
• Terminal Exam: 50%
6
Introduction
• Five concepts in object oriented programming
are:
– Object
– Classes
– Encapsulation
– Inheritance
– Polymorphism
7
Simple analogy
• You are driving a car
• You can pressing accelerator pedal
• Someone has design it and built it
• Engineering drawings  car
• Drawings also includes design for accelerator
pedal to make car go faster
• We can say, pedal “hides” complex
mechanism that make the car go faster
8
Cont.
• Brake pedal “hides” the mechanism that slow
the car
• Steering wheel “hides” the mechanism that
turn the car and so on
• Simple “interfaces” like accelerator and brake
pedal, steering wheel, transmission shift and
etc. allow driver to interact car’s complex
internal mechanisms
9
Points to be noted
• You cannot drive the engineering design of a
car
• Before you can drive a car, it must be built
according to engineering design
• The car will not accelerator on its own, a
driver must press the accelerator pedal
10
Object oriented programming concepts
• Function hides from user the complex task it
performs
• Same as accelerator pedal hides complex
mechanism of making the car go faster
• C++ makes a program unit called class that
houses various functions
• Same as car engineering design houses the
mechanism of accelerator pedal
11
Cont.
• In C++, a class can have various functions that
are design to perform a class tasks
• For example, a class representing bank
account might contain functions
– Deposit money
– Withdraw money
– Current balance
12
Car example
Real world
• Engineering drawing
cannot be drive
• A car is build from that
drawing
• Pressing accelerator
pedal sends a message
to car to perform task
(go faster)
C++ programming
• An object of a class must
be create to get a
program to perform the
tasks the class describes
• Message can be sent to
object by calling a
member functions
13
Cont.
• Car analogy is used to introduce
– Class
– Objects
– Member functions
• In addition to capabilities of car, it has many
attributes
• Color, No. of doors, amount of gas in tank, total
miles driven and etc
• Attributes are part of car engineering drawing
14
Cont.
• These attribute are always associated with the
car
• Every car maintains its own attribute
• Example 1: each car knows how much gas in its
own tank but do not know how much is in the
tanks of other cars
• Example 2: a bank account object has a balance
attribute. Each bank account object knows the
balance in its account not the others
15
Object
• Look around right now and you'll find many
examples of real-world objects:
• your dog, your desk, your television set, your
bicycle.
• Real-world objects share two characteristics:
They all have
– State and
– Behavior
16
Object example
• A dog x has state (name, color, breed, hungry)
and behavior (barking, fetching, wagging tail).
• Your bicycle also have state (current gear,
current pedal cadence, current speed) and
behavior (changing gear, changing pedal
cadence, applying brakes).
17
Cont.
• For each object that you see, ask yourself two
questions:
– "What possible states can this object be in?" and
– "What possible behavior can this object perform?"
18
Real world objects
• Real-world objects vary in complexity
– your desktop lamp may have only two possible
states (on and off) and two possible behaviors
(turn on, turn off),
– but your desktop radio might have additional
states (on, off, current volume, current station)
and behavior (turn on, turn off, increase volume,
decrease volume, seek, scan, and tune).
19
Cont..
• You may also notice that some objects, in
turn, will also contain other objects.
• These real-world observations all translate
into the world of object-oriented
programming
20
Class
• In the real world, you'll often find many individual
objects all of the same kind
• There may be thousands of other bicycles in
existence, all of the same make and model.
• Each bicycle was built from the same engineering
design and contains the same components.
• In object-oriented terms, we say that your bicycle
is an instance of the class of objects known as
bicycles.
21
Software Object
• Software objects are conceptually similar to
real-world objects: they too consist of state
and related behavior. An object stores its
state in
– fields (variables in some programming languages)
and exposes its behavior through
– methods (functions in some programming
languages). A Software Object
22
Cont.
• Methods operate on an object's internal state
and serve as the primary mechanism for
object-to-object communication.
23
Class vs. Object
• Class is a blue print of an object, which is non-
live entity.
• Object is instance of class, which is a live
entity.
• Example:
– Employee is a class
– Fruit is a class
– I am an object
– apple is an object
24
Points to remember
• A class is not a living entity, it is just a
engineering design that how an object of this
class look like
• Object are living entities
25
Defining a class with member function
26
Cont.
• Class definition
• Access specifier – Public
• Class’s body is enclosed in a pair of { }
• Class definition ends at semi colon
• Member function
• Class object
• Dot operator
27
Member function with parameter
Write a program
28
#include <iostream.h>
#include <string.h>
class book{
private:
char name[25];
int pages;
float price;
public:
void changeName(char *n){
strcpy(name, n);
}
void changePages(int p){
pages = p;
}
void changePrice(float p){
price = p;
}
void display(){
cout<<"name = "<<name<<" pages = "<<pages<<" price = "<<price<<endl;
}
};
Book Class
Simple program
29
Class data
• The class book contain three data items
– char name[15];
– int pages;
– float price;
• There can be any number of data members in
a class just as in structure
• There data member lie under keyword private,
so they can be accessed from within the class,
but not outside
30
Member function
• These functions are included in a class
• There are four member functions in class book
– changeName(char *n)
– changePages(int p)
– changePrice(float p)
– display()
• There functions are followed by a keyword
public, so they can be accessed outside the
class
31
Class data and member function
• Access specifier label public and private
• Function are public and data is private
• Data is hidden so that it can be safe from
accidental manipulation
• Functions operates on data are public so they
can be accessed from outside the class
32
Defining Objects
void main()
{
book b1;
b1.changeName("Operating System");
b1.changePages(500);
b1.changePrice(150.56);
b1.display();
}
Name
Pages
Price
b1
Operating system
500
150.56
33
Cont.
• Defining an object is similar to defining a
variable of any data type: Space is set aside for
it in memory e.g. int x;
• Defining objects in this way (book b1;) means
creating them, also called instantiating them
• An object is an instance (that is, a specific
example) of a class. Objects are sometimes
called instance variables.
34
Calling Member Functions
• The next four statements in main() call the
member function
– b1.changeName("Operating System");
– b1.changePages(500);
– b1.changePrice(150.56);
– b1.display();
• don’t look like normal function calls
• This syntax is used to call a member function that
is associated with a specific object
• It doesn’t make sense to say
– changeName("Operating System");
because a member function is always called to act on
a specific object, not on the class in general
35
Cont.
• To use a member function, the dot operator
(the period) connects the object name and
the member function.
• The syntax is similar to the way we refer to
structure members, but the parentheses
signal that we’re executing a member function
rather than referring to a data item.
• The dot operator is also called the class
member access operator.
36
Data members, set and get functions
37
Example program – Distance class
• Data members
– Feet
– Inches
• Member functions
– void setdist(int ft, float in);
– void getdist();
– void initialize();
– void showdist();
Go to program
38
Constructors
• The Distance example shows two ways that member
functions can be used to give values to the data items
in an object
• It is convenient if an object can initialize itself when it’s
first created, without requiring a separate call to a
member function
• Automatic initialization is carried out using a special
member function called a constructor.
• A constructor is a member function that is executed
automatically whenever an object is created.
39
A counter example
• Data member
– Count
• Member function
– Constructor
– void inc_count()
– int get_count()
Go to program
Ad

More Related Content

Similar to lecture_for programming and computing basics (20)

CPP13 - Object Orientation
CPP13 - Object OrientationCPP13 - Object Orientation
CPP13 - Object Orientation
Michael Heron
 
Introducing object oriented programming (oop)
Introducing object oriented programming (oop)Introducing object oriented programming (oop)
Introducing object oriented programming (oop)
Hemlathadhevi Annadhurai
 
Oo aand d-overview
Oo aand d-overviewOo aand d-overview
Oo aand d-overview
Saravana Suresh Saravanamuthu
 
Object orinted programming lecture| Overlaoded Functions
Object orinted programming lecture| Overlaoded FunctionsObject orinted programming lecture| Overlaoded Functions
Object orinted programming lecture| Overlaoded Functions
cenaj3443
 
02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt
Yonas D. Ebren
 
Intro To C++ - Class #19: Functions
Intro To C++ - Class #19: FunctionsIntro To C++ - Class #19: Functions
Intro To C++ - Class #19: Functions
Blue Elephant Consulting
 
OOP02-27022023-090456am.pptx
OOP02-27022023-090456am.pptxOOP02-27022023-090456am.pptx
OOP02-27022023-090456am.pptx
uzairrrfr
 
Chapter10_Data_Abstraction_and_Object_Orientation_4e.ppt
Chapter10_Data_Abstraction_and_Object_Orientation_4e.pptChapter10_Data_Abstraction_and_Object_Orientation_4e.ppt
Chapter10_Data_Abstraction_and_Object_Orientation_4e.ppt
techtrainer11
 
Software Engineering Lec5 oop-uml-i
Software Engineering Lec5 oop-uml-iSoftware Engineering Lec5 oop-uml-i
Software Engineering Lec5 oop-uml-i
Taymoor Nazmy
 
SE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPTSE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPT
nikshaikh786
 
c++.pptxwjwjsijsnsksomammaoansnksooskskk
c++.pptxwjwjsijsnsksomammaoansnksooskskkc++.pptxwjwjsijsnsksomammaoansnksooskskk
c++.pptxwjwjsijsnsksomammaoansnksooskskk
mitivete
 
Angular
AngularAngular
Angular
Lilia Sfaxi
 
AngularJS
AngularJSAngularJS
AngularJS
Yogesh L
 
1_Object Oriented Programming.pptx
1_Object Oriented Programming.pptx1_Object Oriented Programming.pptx
1_Object Oriented Programming.pptx
umarAnjum6
 
01-introductionto Object ooriented Programming in JAVA CS.ppt
01-introductionto Object ooriented Programming in JAVA CS.ppt01-introductionto Object ooriented Programming in JAVA CS.ppt
01-introductionto Object ooriented Programming in JAVA CS.ppt
GESISLAMIAPATTOKI
 
2CPP03 - Object Orientation Fundamentals
2CPP03 - Object Orientation Fundamentals2CPP03 - Object Orientation Fundamentals
2CPP03 - Object Orientation Fundamentals
Michael Heron
 
JS Essence
JS EssenceJS Essence
JS Essence
Uladzimir Piatryka
 
Object Oriented Programming Constructors & Destructors
Object Oriented Programming  Constructors &  DestructorsObject Oriented Programming  Constructors &  Destructors
Object Oriented Programming Constructors & Destructors
anitashinde33
 
ER diagram slides for datanase stujdy-1.pdf
ER diagram slides for datanase stujdy-1.pdfER diagram slides for datanase stujdy-1.pdf
ER diagram slides for datanase stujdy-1.pdf
SadiaSharmin40
 
Analysis
AnalysisAnalysis
Analysis
Preeti Mishra
 
CPP13 - Object Orientation
CPP13 - Object OrientationCPP13 - Object Orientation
CPP13 - Object Orientation
Michael Heron
 
Introducing object oriented programming (oop)
Introducing object oriented programming (oop)Introducing object oriented programming (oop)
Introducing object oriented programming (oop)
Hemlathadhevi Annadhurai
 
Object orinted programming lecture| Overlaoded Functions
Object orinted programming lecture| Overlaoded FunctionsObject orinted programming lecture| Overlaoded Functions
Object orinted programming lecture| Overlaoded Functions
cenaj3443
 
02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt
Yonas D. Ebren
 
OOP02-27022023-090456am.pptx
OOP02-27022023-090456am.pptxOOP02-27022023-090456am.pptx
OOP02-27022023-090456am.pptx
uzairrrfr
 
Chapter10_Data_Abstraction_and_Object_Orientation_4e.ppt
Chapter10_Data_Abstraction_and_Object_Orientation_4e.pptChapter10_Data_Abstraction_and_Object_Orientation_4e.ppt
Chapter10_Data_Abstraction_and_Object_Orientation_4e.ppt
techtrainer11
 
Software Engineering Lec5 oop-uml-i
Software Engineering Lec5 oop-uml-iSoftware Engineering Lec5 oop-uml-i
Software Engineering Lec5 oop-uml-i
Taymoor Nazmy
 
SE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPTSE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPT
nikshaikh786
 
c++.pptxwjwjsijsnsksomammaoansnksooskskk
c++.pptxwjwjsijsnsksomammaoansnksooskskkc++.pptxwjwjsijsnsksomammaoansnksooskskk
c++.pptxwjwjsijsnsksomammaoansnksooskskk
mitivete
 
1_Object Oriented Programming.pptx
1_Object Oriented Programming.pptx1_Object Oriented Programming.pptx
1_Object Oriented Programming.pptx
umarAnjum6
 
01-introductionto Object ooriented Programming in JAVA CS.ppt
01-introductionto Object ooriented Programming in JAVA CS.ppt01-introductionto Object ooriented Programming in JAVA CS.ppt
01-introductionto Object ooriented Programming in JAVA CS.ppt
GESISLAMIAPATTOKI
 
2CPP03 - Object Orientation Fundamentals
2CPP03 - Object Orientation Fundamentals2CPP03 - Object Orientation Fundamentals
2CPP03 - Object Orientation Fundamentals
Michael Heron
 
Object Oriented Programming Constructors & Destructors
Object Oriented Programming  Constructors &  DestructorsObject Oriented Programming  Constructors &  Destructors
Object Oriented Programming Constructors & Destructors
anitashinde33
 
ER diagram slides for datanase stujdy-1.pdf
ER diagram slides for datanase stujdy-1.pdfER diagram slides for datanase stujdy-1.pdf
ER diagram slides for datanase stujdy-1.pdf
SadiaSharmin40
 

More from JavedKhan524377 (8)

Deep learning intro and examples and types
Deep learning intro and examples and typesDeep learning intro and examples and types
Deep learning intro and examples and types
JavedKhan524377
 
Linear Search for design and analysis of algorithm
Linear Search for design and analysis of algorithmLinear Search for design and analysis of algorithm
Linear Search for design and analysis of algorithm
JavedKhan524377
 
Greedy algorithm for design and analysis
Greedy algorithm for design and analysisGreedy algorithm for design and analysis
Greedy algorithm for design and analysis
JavedKhan524377
 
Binary Search Tree for design and analysis
Binary Search Tree for design and analysisBinary Search Tree for design and analysis
Binary Search Tree for design and analysis
JavedKhan524377
 
Software Engineering Book for beginnerss
Software Engineering Book for beginnerssSoftware Engineering Book for beginnerss
Software Engineering Book for beginnerss
JavedKhan524377
 
Software tetsing paper related to industry
Software tetsing paper related to industrySoftware tetsing paper related to industry
Software tetsing paper related to industry
JavedKhan524377
 
Week 1 Lecture 1 LAB Weka lecture for machine learning
Week 1 Lecture 1 LAB Weka lecture for machine learningWeek 1 Lecture 1 LAB Weka lecture for machine learning
Week 1 Lecture 1 LAB Weka lecture for machine learning
JavedKhan524377
 
chapter_3_8 of software requirements engineering
chapter_3_8 of software requirements engineeringchapter_3_8 of software requirements engineering
chapter_3_8 of software requirements engineering
JavedKhan524377
 
Deep learning intro and examples and types
Deep learning intro and examples and typesDeep learning intro and examples and types
Deep learning intro and examples and types
JavedKhan524377
 
Linear Search for design and analysis of algorithm
Linear Search for design and analysis of algorithmLinear Search for design and analysis of algorithm
Linear Search for design and analysis of algorithm
JavedKhan524377
 
Greedy algorithm for design and analysis
Greedy algorithm for design and analysisGreedy algorithm for design and analysis
Greedy algorithm for design and analysis
JavedKhan524377
 
Binary Search Tree for design and analysis
Binary Search Tree for design and analysisBinary Search Tree for design and analysis
Binary Search Tree for design and analysis
JavedKhan524377
 
Software Engineering Book for beginnerss
Software Engineering Book for beginnerssSoftware Engineering Book for beginnerss
Software Engineering Book for beginnerss
JavedKhan524377
 
Software tetsing paper related to industry
Software tetsing paper related to industrySoftware tetsing paper related to industry
Software tetsing paper related to industry
JavedKhan524377
 
Week 1 Lecture 1 LAB Weka lecture for machine learning
Week 1 Lecture 1 LAB Weka lecture for machine learningWeek 1 Lecture 1 LAB Weka lecture for machine learning
Week 1 Lecture 1 LAB Weka lecture for machine learning
JavedKhan524377
 
chapter_3_8 of software requirements engineering
chapter_3_8 of software requirements engineeringchapter_3_8 of software requirements engineering
chapter_3_8 of software requirements engineering
JavedKhan524377
 
Ad

Recently uploaded (20)

Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
Herbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptxHerbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptx
RAJU THENGE
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
Link your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRMLink your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRM
Celine George
 
Contact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: OptometryContact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: Optometry
MushahidRaza8
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
dynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south Indiadynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south India
PrachiSontakke5
 
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdfBiophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
Political History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptxPolitical History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Engage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdfEngage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdf
TechSoup
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
Herbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptxHerbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptx
RAJU THENGE
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
Link your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRMLink your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRM
Celine George
 
Contact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: OptometryContact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: Optometry
MushahidRaza8
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
dynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south Indiadynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south India
PrachiSontakke5
 
Engage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdfEngage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdf
TechSoup
 
Ad

lecture_for programming and computing basics

  • 1. 1 CSC241: Object Oriented Programming Lecture No 01
  • 2. 2 Aim of the course • This course provides – motivation of object oriented programming language – in depth knowledge of the various concepts of object oriented programming and its implementation in C++
  • 3. 3 Course book • Text book – C++ How to program by Deitel and Deitel • Reference books – Waite Group’s Object oriented programming in C++, Robert Lafore
  • 4. 4 Course outline Classes, Objects, Member functions, Objects as data types, Constructors and destructors, Overloaded constructor The default copy constructor, Returning objects from functions, objects and memory, Static class data, Constant member functions, Constant objects Base classes and derived classes, Derived class constructors, Overloading member functions, Scope resolution, Abstract classes, Public and private inheritance, Levels of inheritance, Multiple inheritance, Aggregation and composition New and delete operators, Pointers to objects, Virtual functions and late binding, Abstract classes and pure virtual functions, Virtual destructors, Virtual base classes, Friend functions and friend classes, Static functions, this pointer, Dynamic type information Motivation for exception handling, Try-catch block, Throwing an exception, Catching multiple exceptions Streams and files, Templates
  • 5. 5 Marks distribution • Assignments: 10% • Quizzes: 15% • Sessional exam 01: 10% • Sessional exam 02: 15% • Terminal Exam: 50%
  • 6. 6 Introduction • Five concepts in object oriented programming are: – Object – Classes – Encapsulation – Inheritance – Polymorphism
  • 7. 7 Simple analogy • You are driving a car • You can pressing accelerator pedal • Someone has design it and built it • Engineering drawings  car • Drawings also includes design for accelerator pedal to make car go faster • We can say, pedal “hides” complex mechanism that make the car go faster
  • 8. 8 Cont. • Brake pedal “hides” the mechanism that slow the car • Steering wheel “hides” the mechanism that turn the car and so on • Simple “interfaces” like accelerator and brake pedal, steering wheel, transmission shift and etc. allow driver to interact car’s complex internal mechanisms
  • 9. 9 Points to be noted • You cannot drive the engineering design of a car • Before you can drive a car, it must be built according to engineering design • The car will not accelerator on its own, a driver must press the accelerator pedal
  • 10. 10 Object oriented programming concepts • Function hides from user the complex task it performs • Same as accelerator pedal hides complex mechanism of making the car go faster • C++ makes a program unit called class that houses various functions • Same as car engineering design houses the mechanism of accelerator pedal
  • 11. 11 Cont. • In C++, a class can have various functions that are design to perform a class tasks • For example, a class representing bank account might contain functions – Deposit money – Withdraw money – Current balance
  • 12. 12 Car example Real world • Engineering drawing cannot be drive • A car is build from that drawing • Pressing accelerator pedal sends a message to car to perform task (go faster) C++ programming • An object of a class must be create to get a program to perform the tasks the class describes • Message can be sent to object by calling a member functions
  • 13. 13 Cont. • Car analogy is used to introduce – Class – Objects – Member functions • In addition to capabilities of car, it has many attributes • Color, No. of doors, amount of gas in tank, total miles driven and etc • Attributes are part of car engineering drawing
  • 14. 14 Cont. • These attribute are always associated with the car • Every car maintains its own attribute • Example 1: each car knows how much gas in its own tank but do not know how much is in the tanks of other cars • Example 2: a bank account object has a balance attribute. Each bank account object knows the balance in its account not the others
  • 15. 15 Object • Look around right now and you'll find many examples of real-world objects: • your dog, your desk, your television set, your bicycle. • Real-world objects share two characteristics: They all have – State and – Behavior
  • 16. 16 Object example • A dog x has state (name, color, breed, hungry) and behavior (barking, fetching, wagging tail). • Your bicycle also have state (current gear, current pedal cadence, current speed) and behavior (changing gear, changing pedal cadence, applying brakes).
  • 17. 17 Cont. • For each object that you see, ask yourself two questions: – "What possible states can this object be in?" and – "What possible behavior can this object perform?"
  • 18. 18 Real world objects • Real-world objects vary in complexity – your desktop lamp may have only two possible states (on and off) and two possible behaviors (turn on, turn off), – but your desktop radio might have additional states (on, off, current volume, current station) and behavior (turn on, turn off, increase volume, decrease volume, seek, scan, and tune).
  • 19. 19 Cont.. • You may also notice that some objects, in turn, will also contain other objects. • These real-world observations all translate into the world of object-oriented programming
  • 20. 20 Class • In the real world, you'll often find many individual objects all of the same kind • There may be thousands of other bicycles in existence, all of the same make and model. • Each bicycle was built from the same engineering design and contains the same components. • In object-oriented terms, we say that your bicycle is an instance of the class of objects known as bicycles.
  • 21. 21 Software Object • Software objects are conceptually similar to real-world objects: they too consist of state and related behavior. An object stores its state in – fields (variables in some programming languages) and exposes its behavior through – methods (functions in some programming languages). A Software Object
  • 22. 22 Cont. • Methods operate on an object's internal state and serve as the primary mechanism for object-to-object communication.
  • 23. 23 Class vs. Object • Class is a blue print of an object, which is non- live entity. • Object is instance of class, which is a live entity. • Example: – Employee is a class – Fruit is a class – I am an object – apple is an object
  • 24. 24 Points to remember • A class is not a living entity, it is just a engineering design that how an object of this class look like • Object are living entities
  • 25. 25 Defining a class with member function
  • 26. 26 Cont. • Class definition • Access specifier – Public • Class’s body is enclosed in a pair of { } • Class definition ends at semi colon • Member function • Class object • Dot operator
  • 27. 27 Member function with parameter Write a program
  • 28. 28 #include <iostream.h> #include <string.h> class book{ private: char name[25]; int pages; float price; public: void changeName(char *n){ strcpy(name, n); } void changePages(int p){ pages = p; } void changePrice(float p){ price = p; } void display(){ cout<<"name = "<<name<<" pages = "<<pages<<" price = "<<price<<endl; } }; Book Class Simple program
  • 29. 29 Class data • The class book contain three data items – char name[15]; – int pages; – float price; • There can be any number of data members in a class just as in structure • There data member lie under keyword private, so they can be accessed from within the class, but not outside
  • 30. 30 Member function • These functions are included in a class • There are four member functions in class book – changeName(char *n) – changePages(int p) – changePrice(float p) – display() • There functions are followed by a keyword public, so they can be accessed outside the class
  • 31. 31 Class data and member function • Access specifier label public and private • Function are public and data is private • Data is hidden so that it can be safe from accidental manipulation • Functions operates on data are public so they can be accessed from outside the class
  • 32. 32 Defining Objects void main() { book b1; b1.changeName("Operating System"); b1.changePages(500); b1.changePrice(150.56); b1.display(); } Name Pages Price b1 Operating system 500 150.56
  • 33. 33 Cont. • Defining an object is similar to defining a variable of any data type: Space is set aside for it in memory e.g. int x; • Defining objects in this way (book b1;) means creating them, also called instantiating them • An object is an instance (that is, a specific example) of a class. Objects are sometimes called instance variables.
  • 34. 34 Calling Member Functions • The next four statements in main() call the member function – b1.changeName("Operating System"); – b1.changePages(500); – b1.changePrice(150.56); – b1.display(); • don’t look like normal function calls • This syntax is used to call a member function that is associated with a specific object • It doesn’t make sense to say – changeName("Operating System"); because a member function is always called to act on a specific object, not on the class in general
  • 35. 35 Cont. • To use a member function, the dot operator (the period) connects the object name and the member function. • The syntax is similar to the way we refer to structure members, but the parentheses signal that we’re executing a member function rather than referring to a data item. • The dot operator is also called the class member access operator.
  • 36. 36 Data members, set and get functions
  • 37. 37 Example program – Distance class • Data members – Feet – Inches • Member functions – void setdist(int ft, float in); – void getdist(); – void initialize(); – void showdist(); Go to program
  • 38. 38 Constructors • The Distance example shows two ways that member functions can be used to give values to the data items in an object • It is convenient if an object can initialize itself when it’s first created, without requiring a separate call to a member function • Automatic initialization is carried out using a special member function called a constructor. • A constructor is a member function that is executed automatically whenever an object is created.
  • 39. 39 A counter example • Data member – Count • Member function – Constructor – void inc_count() – int get_count() Go to program