01969_PPT_ch07 - Programming Logic and Design Fifth...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
Programming Logic and Design Fifth Edition, Comprehensive Chapter 7 Using Methods
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Programming Logic and Design, Fifth Edition, Comprehensive 2 Objectives Review how to use a simple method with local variables and constants Create a method that requires a single parameter Create a method that requires multiple parameters Create a method that returns a value Pass an array to a method
Background image of page 2
Programming Logic and Design, Fifth Edition, Comprehensive 3 Objectives (continued) Overload methods Learn how to avoid ambiguous methods Use prewritten, built-in methods Create an IPO chart Learn to reduce coupling and increase cohesion
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Programming Logic and Design, Fifth Edition, Comprehensive 4 Review of Simple Methods Method : programming module that contains a series of statements to perform a task Can invoke a method from another program or method Program can contain unlimited number of methods Method can be called unlimited number of times Method must include: Header Body Return statement
Background image of page 4
Programming Logic and Design, Fifth Edition, Comprehensive 5 Review of Simple Methods (continued) Simple methods require no arguments and send no return values Variables are in scope ( local ) to the method in which they are declared Two or more methods may access the same data Pass data from one method to another
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Programming Logic and Design, Fifth Edition, Comprehensive 6 Figure 7-1 A program that calculates the user’s weight on the moon
Background image of page 6
Programming Logic and Design, Fifth Edition, Comprehensive 7 Figure 7-2 Output of moon weight calculator program in Figure 7-1
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Programming Logic and Design, Fifth Edition, Comprehensive 8 Creating Methods That Require a Single Parameter Some methods require outside information Parameters : communications received by a method Argument : value in parentheses when calling a method Implementation hiding : encapsulation of method details Program need not know how method works internally Interface to the method is the only part of the method the client sees
Background image of page 8
Programming Logic and Design, Fifth Edition, Comprehensive 9 Figure 7-3 Moon weight program that passes an argument to a method
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Programming Logic and Design, Fifth Edition, Comprehensive 10 Figure 7-3 Moon weight program that passes an argument to a method (continued)
Background image of page 10
Programming Logic and Design, Fifth Edition, Comprehensive 11 Figure 7-4 Typical execution of moon weight program in Figure 7-3
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Programming Logic and Design, Fifth Edition, Comprehensive 12 Creating Methods That Require a Single Parameter (continued) Method declaration must include Type of the parameter Local name for the parameter Parameters in parentheses hold values that are “dropped in” to the method Variable declared in method header is a local variable Goes out of scope when method ends Variables passed to a method are passed by value Copy of the value sent to the method Stored in a new memory location
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 50

01969_PPT_ch07 - Programming Logic and Design Fifth...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online