SlideShare uma empresa Scribd logo
1 de 127
 
Chapter 11 Friends, Overloaded Operators, and Arrays in Classes
Overview ,[object Object],[object Object],[object Object],[object Object],Slide 11-
11.1 Friend Functions
Friend Function ,[object Object],[object Object],Slide 11-
Program Example: An Equality Function ,[object Object],[object Object],[object Object],Slide 11-
Declaration of  The equality Function ,[object Object],[object Object],[object Object],[object Object],Slide 11-
Defining Function equal ,[object Object],[object Object],[object Object],Slide 11-
Using The Function equal ,[object Object],[object Object],Slide 11-  Display 11.1 (1) Display 11.1 (2) Display 11.1 (3)
Is equal Efficient? ,[object Object],[object Object],[object Object],Slide 11-
A More Efficient equal ,[object Object],[object Object],[object Object],Slide 11-
Friend Functions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Slide 11-
Declaring A Friend ,[object Object],Slide 11-
Using A Friend Function ,[object Object],[object Object],[object Object],Slide 11-  Display 11.2
Friend Declaration Syntax ,[object Object],Slide 11-
Are Friends Needed? ,[object Object],[object Object],Slide 11-
Choosing Friends ,[object Object],[object Object],[object Object],[object Object],Slide 11-
Program Example: The Money Class (version 1) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Slide 11-  Display 11.3 (1 – 5)
Characters to Integers ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Slide 11-
digit_to_int  (optional) ,[object Object],[object Object],[object Object],[object Object],[object Object],Slide 11-
int( c) – int ('0')? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Slide 11-
Leading Zeros ,[object Object],[object Object],[object Object],[object Object],[object Object],Slide 11-
Parameter Passing Efficiency ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Slide 11-
Class Parameters ,[object Object],[object Object],[object Object],Slide 11-
const Parameter Modifier ,[object Object],[object Object],[object Object],[object Object],Slide 11-
const Parameter Example ,[object Object],[object Object],[object Object],[object Object],[object Object],Slide 11-
const Considerations ,[object Object],[object Object],[object Object],Slide 11-
const  And Accessor Functions ,[object Object],[object Object],[object Object],Slide 11-
const Modifies Functions ,[object Object],[object Object],[object Object],[object Object],Slide 11-
Function Declarations With const ,[object Object],[object Object],Slide 11-
Function Definitions  With const ,[object Object],[object Object],Slide 11-
const Problem Solved ,[object Object],[object Object],Slide 11-
const Wrapup ,[object Object],[object Object],[object Object],[object Object],Slide 11-  Display 11.4
Use const Consistently ,[object Object],[object Object],[object Object],Slide 11-
Section 11.1 Conclusion ,[object Object],[object Object],[object Object],Slide 11-
11.2 Overloading Operators
Overloading Operators ,[object Object],[object Object],Slide 11-
Operators As Functions ,[object Object],[object Object],[object Object],Slide 11-
Operator Overloading ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Slide 11-
Operator Overloading Rules ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Slide 11-
Program Example: Overloading Operators ,[object Object],Slide 11-  Display 11.5 (1) Display 11.5 (2)
Automatic Type Conversion ,[object Object],[object Object],[object Object],[object Object],Slide 11-
Type Conversion Event 1 ,[object Object],[object Object],Slide 11-
Type Conversion Event 2 ,[object Object],[object Object],[object Object],Slide 11-
Type Conversion Again ,[object Object],[object Object],Slide 11-
A Constructor For double ,[object Object],Slide 11-
Overloading Unary Operators ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Slide 11-
Overloading - ,[object Object],[object Object],Slide 11-  Display 11.6
Overloading << and >> ,[object Object],[object Object],[object Object],Slide 11-  Operand 1 Operator Operand 2
Replacing Function output ,[object Object],[object Object],[object Object],[object Object],Slide 11-
What Does << Return? ,[object Object],[object Object],Slide 11-  Display 11.7
Overloaded << Declaration ,[object Object],[object Object],Slide 11-
Overloaded << Definition ,[object Object],[object Object],Slide 11-
Return ostream& ? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Slide 11-
Overloading >> ,[object Object],[object Object],Slide 11-  Display 11.8 (1-4)
Section 11.2 Conclusion ,[object Object],[object Object],[object Object],[object Object],Slide 11-
11.3 Arrays and Classes
Arrays and Classes ,[object Object],[object Object],Slide 11-
Accessing Members ,[object Object],[object Object],[object Object],Slide 11-
An Array of Money ,[object Object],[object Object],[object Object],[object Object],Slide 11-  Display 11.9 (1-3)
Arrays as Structure Members ,[object Object],[object Object],[object Object],Slide 11-
Accessing Array Elements ,[object Object],[object Object],[object Object],[object Object],Slide 11-
Arrays as Class Members ,[object Object],[object Object],[object Object],[object Object],Slide 11-
Overview of TemperatureList ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Slide 11-  Display 11.10 (1-2)
Section 11.3 Conclusion ,[object Object],[object Object],[object Object],[object Object],[object Object],Slide 11-
11.4 Classes and Dynamic Arrays
Classes and Dynamic Arrays  ,[object Object],[object Object],[object Object],Slide 11-
Program Example: A String Variable Class ,[object Object],[object Object],[object Object],[object Object],Slide 11-
The StringVar Constructors ,[object Object],[object Object],[object Object],[object Object],[object Object],Slide 11-
The StringVar Interface ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Slide 11-  Display 11.11 (1) Display 11.11 (2)
A StringVar Sample Program ,[object Object],[object Object],[object Object],[object Object],[object Object],Slide 11-  Display 11.11 (3)
The StringVar Implementation ,[object Object],[object Object],[object Object],[object Object],[object Object],Slide 11-  Display 11.12 (1) Display 11.12 (2)
Dynamic Variables ,[object Object],[object Object],[object Object],Slide 11-
Destructors ,[object Object],[object Object],[object Object],[object Object],[object Object],Slide 11-
~StringVar ,[object Object],[object Object],Slide 11-
Pointers as  Call-by-Value Parameters ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Slide 11-  Display 11.13 Display 11.14
Copy Constructors ,[object Object],[object Object],[object Object],[object Object],[object Object],Slide 11-
StringVar Copy Constructor ,[object Object],[object Object],[object Object],[object Object],Slide 11-
Calling a Copy Constructor ,[object Object],[object Object],[object Object],[object Object],[object Object],Slide 11-
The Need For  a Copy Constructor ,[object Object],[object Object],[object Object],[object Object],Slide 11-
The Need For  a Copy Constructor (cont.) ,[object Object],Slide 11-  greeting.value the_string.value &quot;Hello&quot;
The Need For  a Copy Constructor (cont.) ,[object Object],[object Object],Slide 11-  greeting.value the_string.value Undefined
The Need For  a Copy Constructor (cont.) ,[object Object],[object Object],[object Object],[object Object],[object Object],Slide 11-
Copy Constructor Demonstration ,[object Object],[object Object],Slide 11-  greeting.value the_string.value &quot;Hello&quot; &quot;Hello&quot;
Copy Constructor Demonstration (cont.) ,[object Object],[object Object],Slide 11-  greeting.value the_string.value &quot;Hello&quot; undefined
When To Include a  Copy Constructor ,[object Object],[object Object],Slide 11-
The Big Three ,[object Object],[object Object],[object Object],[object Object],[object Object],Slide 11-
The Assignment Operator ,[object Object],[object Object],Slide 11-
Overloading = ,[object Object],[object Object],[object Object],[object Object],Slide 11-
Definition of = ,[object Object],Slide 11-
= Details ,[object Object],[object Object],[object Object],[object Object],Slide 11-
Problems with = ,[object Object],[object Object],[object Object],[object Object],Slide 11-
Another Attempt at = ,[object Object],Slide 11-
A New Problem With = ,[object Object],[object Object],[object Object],[object Object],Slide 11-
A Better = Operator ,[object Object],Slide 11-
Section 11.4 Conclusion ,[object Object],[object Object],[object Object],[object Object],Slide 11-
Chapter 11 -- End Slide 11-
Display 11.1 (1/3) Slide 11-  Back Next
Display 11.1 (2/3) Slide 11-  Back Next
Display 11.1 (3/3) Slide 11-  Back Next
Display 11.2 Slide 11-  Back Next
Display 11.3 (1/5) Slide 11-  Back Next
Display 11.3 (2/5) Slide 11-  Back Next
Display 11.3 (3/5) Slide 11-  Back Next
Display 11.3 (4/5) Slide 11-  Back Next
Display 11.3 (5/5) Slide 11-  Back Next
Display 11.4 Slide 11-  Back Next
Display 11.5 (1/2) Slide 11-  Back Next
Display 11.5  (2/2) Slide 11-  Back Next
Display 11.6 Slide 11-  Back Next
Display 11.7 Slide 11-  Back Next
Display 11.8 (1/4) Slide 11-  Back Next
Display 11.8(2/4) Slide 11-  Next Back
Display 11.8 (3/4) Slide 11-  Back Next
Display 11.8 (4/4) Slide 11-  Back Next
Display 11.9 (1/3) Slide 11-  Back Next
Display 11.9 (2/3) Slide 11-  Back Next
Display 11.9 (3/3) Slide 11-  Back Next
Display 11.10 (1/2) Slide 11-  Back Next
Display 11.10 (2/2) Slide 11-  Back Next
Display 11.11 (1/3) Slide 11-  Back Next
Display 11.11 (2/3) Slide 11-  Back Next
Display 11.11 (3/3) Slide 11-  Back Next
Display 11.12 (1/2) Slide 11-  Back Next
Display 11.12 (2/2) Slide 11-  Back Next
Display 11.13 Slide 11-  Back Next
Display 11.14 Slide 11-  Back Next

Mais conteúdo relacionado

Mais procurados

Complete reference to_abap_basics
Complete reference to_abap_basicsComplete reference to_abap_basics
Complete reference to_abap_basics
Abhishek Dixit
 
C programming language working with functions 1
C programming language working with functions 1C programming language working with functions 1
C programming language working with functions 1
Jeevan Raj
 

Mais procurados (18)

Functions in C - Programming
Functions in C - Programming Functions in C - Programming
Functions in C - Programming
 
C language for Semester Exams for Engineers
C language for Semester Exams for Engineers C language for Semester Exams for Engineers
C language for Semester Exams for Engineers
 
c.p function
c.p functionc.p function
c.p function
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Savitch ch 05
Savitch ch 05Savitch ch 05
Savitch ch 05
 
Function
Function Function
Function
 
user defined function
user defined functionuser defined function
user defined function
 
Function in C
Function in CFunction in C
Function in C
 
Ch10 Program Organization
Ch10 Program OrganizationCh10 Program Organization
Ch10 Program Organization
 
Savitch Ch 05
Savitch Ch 05Savitch Ch 05
Savitch Ch 05
 
Functions
FunctionsFunctions
Functions
 
4. function
4. function4. function
4. function
 
Complete reference to_abap_basics
Complete reference to_abap_basicsComplete reference to_abap_basics
Complete reference to_abap_basics
 
C programming language working with functions 1
C programming language working with functions 1C programming language working with functions 1
C programming language working with functions 1
 
Chapter 3(1)
Chapter 3(1)Chapter 3(1)
Chapter 3(1)
 
Chapter 2(1)
Chapter 2(1)Chapter 2(1)
Chapter 2(1)
 

Destaque (12)

Oop concepts
Oop conceptsOop concepts
Oop concepts
 
Savitch Ch 04
Savitch Ch 04Savitch Ch 04
Savitch Ch 04
 
Savitch ch 08
Savitch ch 08Savitch ch 08
Savitch ch 08
 
Savitch ch 04
Savitch ch 04Savitch ch 04
Savitch ch 04
 
Savitch ch 12
Savitch ch 12Savitch ch 12
Savitch ch 12
 
Savitch Ch 03
Savitch Ch 03Savitch Ch 03
Savitch Ch 03
 
Savitch ch 13
Savitch ch 13Savitch ch 13
Savitch ch 13
 
Savitch ch 01
Savitch ch 01Savitch ch 01
Savitch ch 01
 
Savitch Ch 05
Savitch Ch 05Savitch Ch 05
Savitch Ch 05
 
Savitch ch 01
Savitch ch 01Savitch ch 01
Savitch ch 01
 
Savitch ch 07
Savitch ch 07Savitch ch 07
Savitch ch 07
 
The Build Trap
The Build TrapThe Build Trap
The Build Trap
 

Semelhante a Savitch ch 11

Semelhante a Savitch ch 11 (20)

Unit-III.pptx
Unit-III.pptxUnit-III.pptx
Unit-III.pptx
 
Visual Basic Review - ICA
Visual Basic Review - ICAVisual Basic Review - ICA
Visual Basic Review - ICA
 
Functions-Computer programming
Functions-Computer programmingFunctions-Computer programming
Functions-Computer programming
 
Fundamentals of c language
Fundamentals of c languageFundamentals of c language
Fundamentals of c language
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Functions in c language
Functions in c languageFunctions in c language
Functions in c language
 
How to build a react native app with the help of react native hooks
How to build a react native app with the help of react native hooksHow to build a react native app with the help of react native hooks
How to build a react native app with the help of react native hooks
 
Chapter 1.ppt
Chapter 1.pptChapter 1.ppt
Chapter 1.ppt
 
Book management system
Book management systemBook management system
Book management system
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
OOP Assignment 03.pdf
OOP Assignment 03.pdfOOP Assignment 03.pdf
OOP Assignment 03.pdf
 
Functions in C++.pdf
Functions in C++.pdfFunctions in C++.pdf
Functions in C++.pdf
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfUSER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
 
Presentation 2 (1).pdf
Presentation 2 (1).pdfPresentation 2 (1).pdf
Presentation 2 (1).pdf
 
C functions
C functionsC functions
C functions
 
Lecture 11 - Functions
Lecture 11 - FunctionsLecture 11 - Functions
Lecture 11 - Functions
 
[ITP - Lecture 12] Functions in C/C++
[ITP - Lecture 12] Functions in C/C++[ITP - Lecture 12] Functions in C/C++
[ITP - Lecture 12] Functions in C/C++
 
unit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdfunit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdf
 
PSPC-UNIT-4.pdf
PSPC-UNIT-4.pdfPSPC-UNIT-4.pdf
PSPC-UNIT-4.pdf
 

Mais de Terry Yoast

Mais de Terry Yoast (20)

9781305078444 ppt ch12
9781305078444 ppt ch129781305078444 ppt ch12
9781305078444 ppt ch12
 
9781305078444 ppt ch11
9781305078444 ppt ch119781305078444 ppt ch11
9781305078444 ppt ch11
 
9781305078444 ppt ch10
9781305078444 ppt ch109781305078444 ppt ch10
9781305078444 ppt ch10
 
9781305078444 ppt ch09
9781305078444 ppt ch099781305078444 ppt ch09
9781305078444 ppt ch09
 
9781305078444 ppt ch08
9781305078444 ppt ch089781305078444 ppt ch08
9781305078444 ppt ch08
 
9781305078444 ppt ch07
9781305078444 ppt ch079781305078444 ppt ch07
9781305078444 ppt ch07
 
9781305078444 ppt ch06
9781305078444 ppt ch069781305078444 ppt ch06
9781305078444 ppt ch06
 
9781305078444 ppt ch05
9781305078444 ppt ch059781305078444 ppt ch05
9781305078444 ppt ch05
 
9781305078444 ppt ch04
9781305078444 ppt ch049781305078444 ppt ch04
9781305078444 ppt ch04
 
9781305078444 ppt ch03
9781305078444 ppt ch039781305078444 ppt ch03
9781305078444 ppt ch03
 
9781305078444 ppt ch02
9781305078444 ppt ch029781305078444 ppt ch02
9781305078444 ppt ch02
 
9781305078444 ppt ch01
9781305078444 ppt ch019781305078444 ppt ch01
9781305078444 ppt ch01
 
9781337102087 ppt ch13
9781337102087 ppt ch139781337102087 ppt ch13
9781337102087 ppt ch13
 
9781337102087 ppt ch18
9781337102087 ppt ch189781337102087 ppt ch18
9781337102087 ppt ch18
 
9781337102087 ppt ch17
9781337102087 ppt ch179781337102087 ppt ch17
9781337102087 ppt ch17
 
9781337102087 ppt ch16
9781337102087 ppt ch169781337102087 ppt ch16
9781337102087 ppt ch16
 
9781337102087 ppt ch15
9781337102087 ppt ch159781337102087 ppt ch15
9781337102087 ppt ch15
 
9781337102087 ppt ch14
9781337102087 ppt ch149781337102087 ppt ch14
9781337102087 ppt ch14
 
9781337102087 ppt ch12
9781337102087 ppt ch129781337102087 ppt ch12
9781337102087 ppt ch12
 
9781337102087 ppt ch11
9781337102087 ppt ch119781337102087 ppt ch11
9781337102087 ppt ch11
 

Último

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Último (20)

Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 

Savitch ch 11