Submit Search
Upload
9781337102087 ppt ch06
•
Download as PPTX, PDF
•
0 likes
•
206 views
T
Terry Yoast
Follow
ch 6
Read less
Read more
Education
Slideshow view
Report
Share
Slideshow view
Report
Share
1 of 50
Download now
Recommended
9781337102087 ppt ch09
9781337102087 ppt ch09
Terry Yoast
Â
9781337102087 ppt ch12
9781337102087 ppt ch12
Terry Yoast
Â
9781337102087 ppt ch05
9781337102087 ppt ch05
Terry Yoast
Â
9781337102087 ppt ch08
9781337102087 ppt ch08
Terry Yoast
Â
9781337102087 ppt ch10
9781337102087 ppt ch10
Terry Yoast
Â
9781337102087 ppt ch04
9781337102087 ppt ch04
Terry Yoast
Â
9781337102087 ppt ch18
9781337102087 ppt ch18
Terry Yoast
Â
9781337102087 ppt ch13
9781337102087 ppt ch13
Terry Yoast
Â
Recommended
9781337102087 ppt ch09
9781337102087 ppt ch09
Terry Yoast
Â
9781337102087 ppt ch12
9781337102087 ppt ch12
Terry Yoast
Â
9781337102087 ppt ch05
9781337102087 ppt ch05
Terry Yoast
Â
9781337102087 ppt ch08
9781337102087 ppt ch08
Terry Yoast
Â
9781337102087 ppt ch10
9781337102087 ppt ch10
Terry Yoast
Â
9781337102087 ppt ch04
9781337102087 ppt ch04
Terry Yoast
Â
9781337102087 ppt ch18
9781337102087 ppt ch18
Terry Yoast
Â
9781337102087 ppt ch13
9781337102087 ppt ch13
Terry Yoast
Â
9781337102087 ppt ch14
9781337102087 ppt ch14
Terry Yoast
Â
9781337102087 ppt ch11
9781337102087 ppt ch11
Terry Yoast
Â
9781337102087 ppt ch17
9781337102087 ppt ch17
Terry Yoast
Â
Spring AOP
Spring AOP
AnushaNaidu
Â
.Net Classes and Objects | UiPath Community
.Net Classes and Objects | UiPath Community
Rohit Radhakrishnan
Â
Certification preparation - Net classses and functions.pptx
Certification preparation - Net classses and functions.pptx
Rohit Radhakrishnan
Â
Certification preparation - Error Handling and Troubleshooting recap.pptx
Certification preparation - Error Handling and Troubleshooting recap.pptx
Rohit Radhakrishnan
Â
9781337102087 ppt ch16
9781337102087 ppt ch16
Terry Yoast
Â
Functional Programming With Lambdas and Streams in JDK8
Functional Programming With Lambdas and Streams in JDK8
IndicThreads
Â
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
JAXLondon2014
Â
Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8
Simon Ritter
Â
Chap4java5th
Chap4java5th
Asfand Hassan
Â
Aspect Oriented Programming Through C#.NET
Aspect Oriented Programming Through C#.NET
Waqas Tariq
Â
Defaultification Refactoring: A Tool for Automatically Converting Java Method...
Defaultification Refactoring: A Tool for Automatically Converting Java Method...
Raffi Khatchadourian
Â
Java8 training - class 2
Java8 training - class 2
Marut Singh
Â
Chap2java5th
Chap2java5th
Asfand Hassan
Â
Defaultification Refactoring: A Tool for Automatically Converting Java Method...
Defaultification Refactoring: A Tool for Automatically Converting Java Method...
Raffi Khatchadourian
Â
Testware Hierarchy for Test Automation
Testware Hierarchy for Test Automation
Gregory Solovey
Â
Cso gaddis java_chapter5
Cso gaddis java_chapter5
mlrbrown
Â
Software Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural Patterns
Sergey Aganezov
Â
Software Development, Data Types, and Expressions
Software Development, Data Types, and Expressions
pullaravikumar
Â
9781337102087 ppt ch15
9781337102087 ppt ch15
Terry Yoast
Â
More Related Content
What's hot
9781337102087 ppt ch14
9781337102087 ppt ch14
Terry Yoast
Â
9781337102087 ppt ch11
9781337102087 ppt ch11
Terry Yoast
Â
9781337102087 ppt ch17
9781337102087 ppt ch17
Terry Yoast
Â
Spring AOP
Spring AOP
AnushaNaidu
Â
.Net Classes and Objects | UiPath Community
.Net Classes and Objects | UiPath Community
Rohit Radhakrishnan
Â
Certification preparation - Net classses and functions.pptx
Certification preparation - Net classses and functions.pptx
Rohit Radhakrishnan
Â
Certification preparation - Error Handling and Troubleshooting recap.pptx
Certification preparation - Error Handling and Troubleshooting recap.pptx
Rohit Radhakrishnan
Â
9781337102087 ppt ch16
9781337102087 ppt ch16
Terry Yoast
Â
Functional Programming With Lambdas and Streams in JDK8
Functional Programming With Lambdas and Streams in JDK8
IndicThreads
Â
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
JAXLondon2014
Â
Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8
Simon Ritter
Â
Chap4java5th
Chap4java5th
Asfand Hassan
Â
Aspect Oriented Programming Through C#.NET
Aspect Oriented Programming Through C#.NET
Waqas Tariq
Â
Defaultification Refactoring: A Tool for Automatically Converting Java Method...
Defaultification Refactoring: A Tool for Automatically Converting Java Method...
Raffi Khatchadourian
Â
Java8 training - class 2
Java8 training - class 2
Marut Singh
Â
Chap2java5th
Chap2java5th
Asfand Hassan
Â
Defaultification Refactoring: A Tool for Automatically Converting Java Method...
Defaultification Refactoring: A Tool for Automatically Converting Java Method...
Raffi Khatchadourian
Â
Testware Hierarchy for Test Automation
Testware Hierarchy for Test Automation
Gregory Solovey
Â
Cso gaddis java_chapter5
Cso gaddis java_chapter5
mlrbrown
Â
Software Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural Patterns
Sergey Aganezov
Â
What's hot
(20)
9781337102087 ppt ch14
9781337102087 ppt ch14
Â
9781337102087 ppt ch11
9781337102087 ppt ch11
Â
9781337102087 ppt ch17
9781337102087 ppt ch17
Â
Spring AOP
Spring AOP
Â
.Net Classes and Objects | UiPath Community
.Net Classes and Objects | UiPath Community
Â
Certification preparation - Net classses and functions.pptx
Certification preparation - Net classses and functions.pptx
Â
Certification preparation - Error Handling and Troubleshooting recap.pptx
Certification preparation - Error Handling and Troubleshooting recap.pptx
Â
9781337102087 ppt ch16
9781337102087 ppt ch16
Â
Functional Programming With Lambdas and Streams in JDK8
Functional Programming With Lambdas and Streams in JDK8
Â
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Â
Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8
Â
Chap4java5th
Chap4java5th
Â
Aspect Oriented Programming Through C#.NET
Aspect Oriented Programming Through C#.NET
Â
Defaultification Refactoring: A Tool for Automatically Converting Java Method...
Defaultification Refactoring: A Tool for Automatically Converting Java Method...
Â
Java8 training - class 2
Java8 training - class 2
Â
Chap2java5th
Chap2java5th
Â
Defaultification Refactoring: A Tool for Automatically Converting Java Method...
Defaultification Refactoring: A Tool for Automatically Converting Java Method...
Â
Testware Hierarchy for Test Automation
Testware Hierarchy for Test Automation
Â
Cso gaddis java_chapter5
Cso gaddis java_chapter5
Â
Software Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural Patterns
Â
Similar to 9781337102087 ppt ch06
Software Development, Data Types, and Expressions
Software Development, Data Types, and Expressions
pullaravikumar
Â
9781337102087 ppt ch15
9781337102087 ppt ch15
Terry Yoast
Â
Sql9e ppt ch08
Sql9e ppt ch08
Dr. Ahmed Al Zaidy
Â
Python Fundamentals
Python Fundamentals
pullaravikumar
Â
Guidelines and Best Practices for Sencha Projects
Guidelines and Best Practices for Sencha Projects
AmitaSuri
Â
Oracle APEX Application Features
Oracle APEX Application Features
Christina Cho
Â
APEX Office Hours Interactive Grid Deep Dive
APEX Office Hours Interactive Grid Deep Dive
JohnSnyders
Â
Advanced angular
Advanced angular
Sumit Kumar Rakshit
Â
Excel module 2 ppt presentation
Excel module 2 ppt presentation
dgdotson
Â
Access 2016 module 4 ppt presentation
Access 2016 module 4 ppt presentation
dgdotson
Â
GraphQL Advanced
GraphQL Advanced
LeanIX GmbH
Â
Chapter 14 Business Continuity
Chapter 14 Business Continuity
Dr. Ahmed Al Zaidy
Â
Excel module 1 ppt presentation
Excel module 1 ppt presentation
dgdotson
Â
Automation in Jira for beginners
Automation in Jira for beginners
Elad Ben-Noam
Â
Open mp
Open mp
Gopi Saiteja
Â
Chapter 4 - Completing the Problem-Solving Process
Chapter 4 - Completing the Problem-Solving Process
mshellman
Â
Talentica - JS Meetup - Angular Schematics
Talentica - JS Meetup - Angular Schematics
Krishnan Mudaliar
Â
Integrating Existing C++ Libraries into PySpark with Esther Kundin
Integrating Existing C++ Libraries into PySpark with Esther Kundin
Databricks
Â
Intro To C++ - Class #19: Functions
Intro To C++ - Class #19: Functions
Blue Elephant Consulting
Â
Sql9e ppt ch02
Sql9e ppt ch02
Dr. Ahmed Al Zaidy
Â
Similar to 9781337102087 ppt ch06
(20)
Software Development, Data Types, and Expressions
Software Development, Data Types, and Expressions
Â
9781337102087 ppt ch15
9781337102087 ppt ch15
Â
Sql9e ppt ch08
Sql9e ppt ch08
Â
Python Fundamentals
Python Fundamentals
Â
Guidelines and Best Practices for Sencha Projects
Guidelines and Best Practices for Sencha Projects
Â
Oracle APEX Application Features
Oracle APEX Application Features
Â
APEX Office Hours Interactive Grid Deep Dive
APEX Office Hours Interactive Grid Deep Dive
Â
Advanced angular
Advanced angular
Â
Excel module 2 ppt presentation
Excel module 2 ppt presentation
Â
Access 2016 module 4 ppt presentation
Access 2016 module 4 ppt presentation
Â
GraphQL Advanced
GraphQL Advanced
Â
Chapter 14 Business Continuity
Chapter 14 Business Continuity
Â
Excel module 1 ppt presentation
Excel module 1 ppt presentation
Â
Automation in Jira for beginners
Automation in Jira for beginners
Â
Open mp
Open mp
Â
Chapter 4 - Completing the Problem-Solving Process
Chapter 4 - Completing the Problem-Solving Process
Â
Talentica - JS Meetup - Angular Schematics
Talentica - JS Meetup - Angular Schematics
Â
Integrating Existing C++ Libraries into PySpark with Esther Kundin
Integrating Existing C++ Libraries into PySpark with Esther Kundin
Â
Intro To C++ - Class #19: Functions
Intro To C++ - Class #19: Functions
Â
Sql9e ppt ch02
Sql9e ppt ch02
Â
More from Terry Yoast
9781305078444 ppt ch12
9781305078444 ppt ch12
Terry Yoast
Â
9781305078444 ppt ch11
9781305078444 ppt ch11
Terry Yoast
Â
9781305078444 ppt ch10
9781305078444 ppt ch10
Terry Yoast
Â
9781305078444 ppt ch09
9781305078444 ppt ch09
Terry Yoast
Â
9781305078444 ppt ch08
9781305078444 ppt ch08
Terry Yoast
Â
9781305078444 ppt ch07
9781305078444 ppt ch07
Terry Yoast
Â
9781305078444 ppt ch06
9781305078444 ppt ch06
Terry Yoast
Â
9781305078444 ppt ch05
9781305078444 ppt ch05
Terry Yoast
Â
9781305078444 ppt ch04
9781305078444 ppt ch04
Terry Yoast
Â
9781305078444 ppt ch03
9781305078444 ppt ch03
Terry Yoast
Â
9781305078444 ppt ch02
9781305078444 ppt ch02
Terry Yoast
Â
9781305078444 ppt ch01
9781305078444 ppt ch01
Terry Yoast
Â
9780538745840 ppt ch10
9780538745840 ppt ch10
Terry Yoast
Â
9780538745840 ppt ch09
9780538745840 ppt ch09
Terry Yoast
Â
9780538745840 ppt ch08
9780538745840 ppt ch08
Terry Yoast
Â
9780538745840 ppt ch07
9780538745840 ppt ch07
Terry Yoast
Â
9780538745840 ppt ch06
9780538745840 ppt ch06
Terry Yoast
Â
More from Terry Yoast
(17)
9781305078444 ppt ch12
9781305078444 ppt ch12
Â
9781305078444 ppt ch11
9781305078444 ppt ch11
Â
9781305078444 ppt ch10
9781305078444 ppt ch10
Â
9781305078444 ppt ch09
9781305078444 ppt ch09
Â
9781305078444 ppt ch08
9781305078444 ppt ch08
Â
9781305078444 ppt ch07
9781305078444 ppt ch07
Â
9781305078444 ppt ch06
9781305078444 ppt ch06
Â
9781305078444 ppt ch05
9781305078444 ppt ch05
Â
9781305078444 ppt ch04
9781305078444 ppt ch04
Â
9781305078444 ppt ch03
9781305078444 ppt ch03
Â
9781305078444 ppt ch02
9781305078444 ppt ch02
Â
9781305078444 ppt ch01
9781305078444 ppt ch01
Â
9780538745840 ppt ch10
9780538745840 ppt ch10
Â
9780538745840 ppt ch09
9780538745840 ppt ch09
Â
9780538745840 ppt ch08
9780538745840 ppt ch08
Â
9780538745840 ppt ch07
9780538745840 ppt ch07
Â
9780538745840 ppt ch06
9780538745840 ppt ch06
Â
Recently uploaded
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
Â
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
ssuser54595a
Â
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Celine George
Â
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
JemimahLaneBuaron
Â
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
pboyjonauth
Â
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
SafetyChain Software
Â
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
RKavithamani
Â
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
manuelaromero2013
Â
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
Sayali Powar
Â
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
dawncurless
Â
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
sanyamsingh5019
Â
MENTAL STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
PoojaSen20
Â
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
David Douglas School District
Â
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
9953056974 Low Rate Call Girls In Saket, Delhi NCR
Â
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Sapana Sha
Â
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
JhengPantaleon
Â
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
NirmalaLoungPoorunde1
Â
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
InMediaRes1
Â
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
GeoBlogs
Â
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
UmakantAnnand
Â
Recently uploaded
(20)
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
Â
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
Â
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Â
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
Â
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
Â
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
Â
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Â
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
Â
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
Â
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
Â
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
Â
MENTAL STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
Â
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
Â
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Â
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Â
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
Â
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
Â
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
Â
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
Â
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
Â
9781337102087 ppt ch06
1.
1 C++ Programming: From
Problem Analysis to Program Design, Eighth Edition Chapter 6 User-Defined Functions
2.
2 Objectives (1 of
2) • In this chapter, you will: • Learn about standard (predefined) functions and discover how to use them in a program • Learn about user-defined functions • Examine value-returning functions , including actual and formal parameters • Explore how to construct and use a value-returning, user-defined function in a program • Learn about function prototypes • Learn how to construct and use void functions © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
3.
3 Objectives (2 of
2) • Discover the difference between value and reference parameters • Explore reference parameters and value-returning functions • Learn about the scope of an identifier • Examine the difference between local and global identifiers • Discover static variables • Learn how to debug programs using drivers and stubs • Learn function overloading • Explore functions with default parameters © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
4.
4 Introduction • Functions allow
complicated programs to be divided into manageable pieces • Functions are often called modules • They are like miniature programs that can be combined to form larger programs © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
5.
5 Predefined Functions (1
of 2) • In C++, a function is similar to that of a function in algebra • It has a name • It does some computation • Some of the predefined mathematical functions are: pow(x, y) sqrt(x) floor(x) © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
6.
6 Predefined Functions (2
of 2) • Predefined functions are organized into separate libraries • I/O functions are in iostream header • Math functions are in cmath header • To use predefined functions, you must include the header file using an include statement • See Table 6-1 in the text for some common predefined functions © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
7.
7 User-Defined Functions • Value-returning
functions have a return type • Return a value of a specific data type using the return statement • Void functions do not have a return type • Do not use a return statement to return a value © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
8.
8 Value-Returning Functions (1
of 3) • To use these functions, you must: • Include the appropriate header file in your program using the include statement • Know the following items: - Name of the function - Number of parameters, if any - Data type of each parameter - Data type of the value returned, called the type of the function © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
9.
9 Value-Returning Functions (2
of 3) • Can use the value returned by a value-returning function by: • Saving it for further calculation • Using it in some calculation • Printing it • A value-returning function is used: • In an assignment • As a parameter in a function call • In an output statement © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
10.
10 Value-Returning Functions (3
of 3) • Heading (or function header): the first line of the function • Example: int abs(int number) • The body is the function’s code that accomplishes the task • Formal parameter: a variable declared in the heading • Example: number • Actual parameter: a variable or expression listed in a call to a function • Example: x = pow(u, v) © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
11.
11 Syntax: Value-Returning Function •
Syntax • functionType is also called the data type or return type © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
12.
12 Syntax: Formal Parameter
List FIGURE 6-1 Various parts of the function abs © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
13.
13 Function Call • Syntax
to call a value-returning function © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
14.
14 Syntax: Actual Parameter
List • The syntax of the actual parameter list is: • The formal parameter list can be empty • A call to a value-returning function with an empty formal parameter list is: © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
15.
15 return Statement • A
function returns its value via the return statement • It passes this value outside the function © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
16.
16 Syntax: return Statement
(1 of 2) • The return statement has this syntax: • In C++, return is a reserved word • When a return statement executes • The function immediately terminates • Control goes back to the caller • When a return statement executes in the function main, the program terminates © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
17.
17 Syntax: return Statement
(2 of 2) FIGURE 6-2 Various parts of the function larger © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
18.
18 Function Prototype • A
function prototype is the function heading without the body of the function • The general syntax of the function prototype of a value-returning function is: • It is not necessary to specify the variable name in the parameter list • The data type of each parameter must be specified © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
19.
19 Value-Returning Functions: Some
Peculiarities (1 of 2) int secret(int x) { if (x > 5) //Line 1 return 2 * x; //Line 2 } A correct definition of the function secret is: int secret(int x) { if (x > 5) //Line 1 return 2 * x; //Line 2 return x; //Line 3 } © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
20.
20 Value-Returning Functions: Some
Peculiarities (2 of 2) • Examples pointing out that the return statement only returns one value return x, y; //only the value of y will be returned int funcRet1() { int x = 45; return 23, x; //only the value of x is returned } int funcRet2(int z) { int a = 2; int b = 3; return 2 * a + b, z + b; //only the value of z + b is returned } © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
21.
21 More Examples of
Value-Returning Functions (1 of 2) char courseGrade(int score) { switch (score / 10) { case 0: case 1: case 2: case 3: case 4: case 5: return 'F'; case 6: return 'D'; case 7: return 'C'; case 8: return 'B'; case 9: case 10: return 'A'; } } © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
22.
22 More Examples of
Value-Returning Functions (2 of 2) • In addition to Example 6-3 courseGrade, other examples are given in the text • Example 6-4 (rolling a pair of dice) • Example 6-5 (Fibonacci number) • Example 6-6 (palindrome) • Example 6-7 (cable company) © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
23.
23 Flow of Compilation
and Execution (1 of 2) • Execution always begins at the first statement in the function main • Other functions are executed only when called • Function prototypes appear before any function definition • The compiler translates these first • The compiler can then correctly translate a function call © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
24.
24 Flow of Compilation
and Execution (2 of 2) • A function call transfers control to the first statement in the body of the called function • When the end of a called function is executed, control is passed back to the point immediately following the function call • A function’s returned value replaces the function call statement © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
25.
25 Void Functions (1
of 4) • User-defined void functions can be placed either before or after the function main • If user-defined void functions are placed after the function main • The function prototype must be placed before the function main • A void function does not have a return type • A return statement without any value is typically used to exit the function early © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
26.
26 Void Functions (2
of 4) • Formal parameters are optional • A call to a void function is a stand-alone statement • The function definition of void functions with parameters has the following syntax: © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
27.
27 Void Functions (3
of 4) • Formal parameter list syntax • Function call syntax • Actual parameter list syntax © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
28.
28 Void Functions (4
of 4) • Two types of formal parameters • Value parameter: a formal parameter that receives a copy of the content of corresponding actual parameter • Reference parameter: a formal parameter that receives the location (memory address) of the corresponding actual parameter © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
29.
29 Value Parameters • If
a formal parameter is a value parameter, the value of the corresponding actual parameter is copied into it • A formal parameter has its own copy of the data • During program execution, a formal parameter manipulates the data stored in its own memory space © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
30.
30 Reference Variables as
Parameters (1 of 2) • If a formal parameter is a reference parameter: • It receives the memory address of the corresponding actual parameter • During program execution to manipulate data: • Changes to a formal parameter will change the corresponding actual parameter © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
31.
31 Reference Variables as
Parameters (2 of 2) • Reference parameters are useful in three situations: • When changing the actual parameter • When returning more than one value • When passing the address would save memory space and time © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
32.
32 Value and Reference
Parameters and Memory Allocation (1 of 2) • When a function is called: • Memory for its formal parameters and its local variables is allocated in the function data area • For a value parameter, the actual parameter’s value is copied into the formal parameter’s memory cell • Changes to the formal parameter do not affect the actual parameter’s value © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
33.
33 Value and Reference
Parameters and Memory Allocation (2 of 2) • For a reference parameter, the actual parameter’s address passes to the formal parameter • Both formal and actual parameters refer to the same memory location • During execution, any change made to the formal parameter’s value immediately changes the actual parameter’s value © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
34.
34 Reference Parameters and
Value-Returning Functions • Can also use reference parameters in a value-returning function • Not recommended • By definition, a value-returning function returns a single value via return statement • If a function needs to return more than one value, change it to a void function and use reference parameters to return the values © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
35.
35 Scope of an
Identifier • Scope of an identifier: where in the program the identifier is accessible • Local identifier: identifiers declared within a function (or block) • Global identifier: identifiers declared outside of every function definition • C++ does not allow nested functions • Definition of one function cannot be included in the body of another function © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
36.
36 Rules Applied When
an Identifier is Accessed (1 of 2) • Global identifiers are accessible by a function or block if: • The identifier is declared before the function definition (block) • The function name different from the identifier • All parameters to the function have different names than the identifier name • All local identifiers have different names than the identifier name © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
37.
37 Rules Applied When
an Identifier is Accessed (2 of 2) • (Nested block) – an identifier declared within a block is accessible: • From its point of declaration to the end of the block in which it is declared • Within nested blocks if no identifier with the same name exists • The scope of a function name is similar to the scope of an identifier declared outside any block • The function name scope is the same as the global variable scope © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
38.
38 Other Notes about
Global Variables • Some compilers initialize global variables to default values • The scope resolution operator in C++ is :: • By using the scope resolution operator: • A global variable declared before the definition of a function (or block) can be accessed by the function (or block) even if the function (or block) has an identifier with the same name as the global variable • To access a global variable declared after the definition of a function, the function must not contain any identifier with the same name • Reserved word extern indicates that a global variable has been declared elsewhere © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
39.
39 Global Variables, Named
Constants, and Side Effects • Using global variables causes side effects • A function that uses global variables is not independent • If more than one function uses the same global variable: • It can be difficult to debug problems with the code • Problems caused in one area of the program may appear to be from another area • Global named constants have no side effects © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
40.
40 Static and Automatic
Variables (1 of 2) • Automatic variable: memory is allocated at block entry and deallocated at block exit • By default, variables declared within a block are automatic variables • Static variable: memory remains allocated as long as the program executes • Global variables declared outside of any block are static variables © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
41.
41 Static and Automatic
Variables (2 of 2) • Declare a static variable within a block by using the reserved word static • The syntax for declaring a static variable is: • Static variables declared within a block are local to the block • Have same scope as any other local identifier in that block © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
42.
42 Debugging: Using Drivers
and Stubs • A driver program is a separate program used to test a function • When results calculated by one function are needed in another function, use a function stub • A function stub is a function that is not fully coded © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
43.
43 Function Overloading: An
Introduction • In a C++ program, several functions can have the same name • Function overloading (or overloading a function name) occurs when creating several functions with the same name • Two functions are said to have different formal parameter lists if both functions have either: • A different number of formal parameters • If the number of formal parameters is the same, but the data type of the formal parameters differs in at least one position © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
44.
44 Function Overloading • Overloaded
functions must have different formal parameter lists • The signature: the name and formal parameter list of the function • Does not include the return type of the function • The parameter list supplied in a call to an overloaded function determines which function is executed © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
45.
45 Functions with Default
Parameters (1 of 2) • In a function call, the number of actual and formal parameters must be the same • C++ relaxes this condition for functions with default parameters • Can specify the value of a default parameter in the function prototype • If you do not specify the value for a default parameter when calling the function, the default value is used © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
46.
46 Functions with Default
Parameters (2 of 2) • All default parameters must be the rightmost parameters of the function • If a default parameter value is not specified: • You must omit all of the arguments to its right • Default values can be constants, global variables, or function calls • Cannot assign a constant value as a default value to a reference parameter © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
47.
47 Quick Review (1
of 4) • Functions (modules) divide a program into manageable tasks • C++ provides standard, predefined functions • Two types of user-defined functions: value-returning functions and void functions • Variables defined in a function heading are called formal parameters • Expressions, variables, or constant values in a function call are called actual parameters © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
48.
48 Quick Review (2
of 4) • Function heading and the body of the function are called the definition of the function • A value-returning function returns its value via the return statement • A prototype is the function heading without the body of the function • User-defined functions execute only when they are called • Void functions do not have a data type © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
49.
49 Quick Review (3
of 4) • There are two types of formal parameters • A value parameter receives a copy of its corresponding actual parameter • A reference parameter receives the memory address of its corresponding actual parameter • Variables declared within a function (or block) are called local variables • Variables declared outside of every function definition (and block) are global variables © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
50.
50 Quick Review (4
of 4) • An automatic variable is a variable for which memory is allocated on function/block entry and deallocated on function/block exit • A static variable is a variable for which memory remains allocated throughout the execution of the program • C++ functions can have default parameters © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom
Download now