CNSP - Lecture 6 Chapter 6�Part II
BY PROF. RAFAEL ORTA
Disclosure: this presentation includes slides that were provided by the textbook publisher and Dr. Hnatyshin, some are adaptation and some are an exact replica.
This week we will cover
What are the 3 repetition flow control structures we covered last week?
While, For and Do- While
6.1 Value and Reference Parameters
5
Listing 6.1 Function to compute sum and average
6
Notes on Call-by-Reference
void computeSumAve(float, float, float&, float&);
7
Call-by-Value and Call-by-Reference Parameters
8
When to Use a Reference or a Value Parameter
Program Style
10
Summary of Value and Reference Parameters
11
Argument/Parameter List Correspondence
12
How do you declare a reference parameter?
A/ You place an & after the variable type.
6.2 Functions with Output and Input Parameters
15
Listing 6.5 Function to order three numbers
16
Notice that the output of one function is the input of the other
Does C++ makes any distinction between output and input – output parameters?
A/ No
6.3 Stepwise Design with Functions
19
Figure 6.4 Structure chart for general sum and average problem
20
What is an alternative to returning values from a function other than passing arguments by reference in the function call?
A/ To use the return clause of the function.
In a function where you are passing to it all the parameters by value, can you return the output or result of it without using the return clause or global variables?
A/ No, it must be either passed by reference, using a global variable, or using the return clause.
6.5 Debugging and Testing a Program System
25
Why?
Top-Down Testing and Stubs
26
Listing 6.12 Stub for function computeSum
27
Bottom-Up Testing and Drivers
28
Listing 6.13 A driver to test computeSum
29
Debugging Tips for Program Systems
30
Debugging Tips for Program Systems
31
Black-Box Testing
32
White-Box Testing
33
What is the difference between black-box testing and white-box testing?
A/ Black-box implies no knowledge about the program by the tested, white-box has knowledge and focuses in testing all possible paths?
6.6 Recursive Functions
37
Template for a Recursive Function
1. If the stopping case is reached
1.1 Return a value for the stopping case
Else
1.2 Return a value computed by calling the function again with different arguments
38
Listing 6.14 Recursive function factorial
39
6.7 Common Programming Errors
41