1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to...
-
Upload
felix-moore -
Category
Documents
-
view
217 -
download
0
Transcript of 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to...
![Page 1: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/1.jpg)
1
Objectives ❏ To design and implement programs with more than one function❏ To be able to design multi-function programs❏ To understand the purpose of the function declaration, call, and
definition❏ To understand the four basic function designs❏ To understand how two functions communicate through
parameters❏ To understand the differences between global and local scope
Chapter 4Chapter 4 FunctionsFunctions
![Page 2: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/2.jpg)
2
FIGURE 4-1 Derived Types
![Page 3: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/3.jpg)
3
4-1 Designing Structured Programs
The programs we have presented so far have been very The programs we have presented so far have been very simple. They solved problems that could be understood simple. They solved problems that could be understood without too much effort. without too much effort.
The principles of top–down design and structured The principles of top–down design and structured programming dictate that a program should be divided programming dictate that a program should be divided into a main module and its related modules. Each into a main module and its related modules. Each module should also be divided into submodules module should also be divided into submodules according to software engineering principles that we according to software engineering principles that we discuss in Section 4.8, “Software Engineering.”discuss in Section 4.8, “Software Engineering.”
![Page 4: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/4.jpg)
4
In top–down design, a program is divided into a main module and its related modules.
Each module is in turn divided into submodules until the resulting modules are intrinsic; that is, until they are
implicitly understood without further division.
NoteNote
![Page 5: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/5.jpg)
5
FIGURE 4-2 Structure Chart
![Page 6: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/6.jpg)
6
4-2 Functions in C
In C, the idea of top–down design is done using In C, the idea of top–down design is done using functions. A C program is made of one or more functions. A C program is made of one or more functions, one and only one of which must be namedfunctions, one and only one of which must be namedmainmain. .
In general, the purpose of a function is to receive zero In general, the purpose of a function is to receive zero or more pieces of data, operate on them, and return at or more pieces of data, operate on them, and return at most one piece of data. At the same time, a function most one piece of data. At the same time, a function can have a side effect. A function side effect is an can have a side effect. A function side effect is an action that results in a change in the state of the action that results in a change in the state of the program. program.
![Page 7: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/7.jpg)
7
In C, a program is made of one or more functions, one and only one of which must be called main.
The execution of the program always starts with main, but it can call other functions
to do some part of the job.
NoteNote
![Page 8: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/8.jpg)
8
FIGURE 4-3 Structure Chart for a C Program
![Page 9: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/9.jpg)
9
FIGURE 4-4 Function Concept
![Page 10: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/10.jpg)
10
A function in C can have a return value, a side effect, or both.
The side effect occurs before the value is returned. The function’s value is the value in the expression of
the return statement. A function can be calledfor its value, its side effect, or both.
NoteNote
![Page 11: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/11.jpg)
11
PROGRAM 4-1 Sample Program with Subfunction
![Page 12: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/12.jpg)
12
![Page 13: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/13.jpg)
13
4-3 User-Defined Functions
Like every other object in C, functions must be both Like every other object in C, functions must be both declared and defined. The function declaration gives declared and defined. The function declaration gives the whole picture of the function that needs to be the whole picture of the function that needs to be defined later. The function definition contains the defined later. The function definition contains the code for a function.code for a function.
Basic Function DesignsFunction DefinitionFunction DeclarationThe Function Call
Topics discussed in this section:Topics discussed in this section:
![Page 14: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/14.jpg)
14
A function name is used three times: for declaration, in a call, and for definition.
NoteNote
![Page 15: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/15.jpg)
15
FIGURE 4-5 Declaring, Calling, and Defining Functions
Defining Function
![Page 16: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/16.jpg)
16
FIGURE 4-6 void Function with Parameters
![Page 17: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/17.jpg)
17
PROGRAM 4-2
void Function with a Parameter
![Page 18: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/18.jpg)
18
FIGURE 4-7 Non-void Function without Parameters
![Page 19: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/19.jpg)
19
FIGURE 4-8 Calling a Function That Returns a Value
![Page 20: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/20.jpg)
20
PROGRAM 4-3
Read a Number and Square It
![Page 21: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/21.jpg)
21
![Page 22: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/22.jpg)
22
FIGURE 4-9 Function Definition
![Page 23: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/23.jpg)
23
FIGURE 4-10 Function Return Statements
![Page 24: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/24.jpg)
24
FIGURE 4-11 Function Local Variables
![Page 25: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/25.jpg)
25
Formal (形式 ) and Actual (實際 ) ParametersFormal parameters are variables that are declared in the header of the function definition.
Actual parameters are the expressions in the calling statement.
Formal and actual parameters must match exactly in type, order, and number.
Their names, however, do not need to match.
NoteNote
![Page 26: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/26.jpg)
26
FIGURE 4-12 Parts of a Function Call
![Page 27: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/27.jpg)
27
FIGURE 4-13 Examples of Function Calls
![Page 28: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/28.jpg)
28
PROGRAM 4-4
Print Least Significant Digit
![Page 29: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/29.jpg)
29
FIGURE 4-14 Design for Add Two Digits
![Page 30: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/30.jpg)
30
PROGRAM 4-5 Add Two Digits
2015/03/18
![Page 31: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/31.jpg)
31
PROGRAM 4-6
Print Six Digits with Comma
![Page 32: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/32.jpg)
32
FIGURE 4-15 Design for Strange College fees
![Page 33: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/33.jpg)
33
PROGRAM 4-7
Strange College Fees
/* This program prints the tuition at Strange College. Strange charges $10 for registration, plus $10 per unit and a penalty of $50 for each 12 units, or fraction of 12, over 12. */
![Page 34: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/34.jpg)
34
4-4 Inter-Function Communication
Although the calling and called functions are two Although the calling and called functions are two separate entities, they need to communicate to exchange separate entities, they need to communicate to exchange data. The data flow between the calling and called data. The data flow between the calling and called functions can be divided into three strategies: a functions can be divided into three strategies: a downward flow, an upward flow, and a bi-directional downward flow, an upward flow, and a bi-directional flow. flow.
Basic ConceptC Implementation
Topics discussed in this section:Topics discussed in this section:
![Page 35: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/35.jpg)
35
FIGURE 4-16 Data Flow Strategies
![Page 36: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/36.jpg)
36
FIGURE 4-17 Downward Communication in C
![Page 37: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/37.jpg)
37
FIGURE 4-18 Downward Communication
![Page 38: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/38.jpg)
38
FIGURE 4-19 Upward Communication in C
Call by address
![Page 39: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/39.jpg)
39
FIGURE 4-20 Upward Communication
![Page 40: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/40.jpg)
40
To send data from the called function to the calling function:
1. We need to use the & symbol in front of the data variable when we call the function.2. We need to use the * symbol after the data type when we declare the address variable3. We need to use the * in front of the variable when we store data indirect
NoteNote
![Page 41: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/41.jpg)
41
FIGURE 4-21 Bi-directional Communication in C
![Page 42: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/42.jpg)
42
FIGURE 4-22 Bi-directional Communication
%
![Page 43: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/43.jpg)
43
FIGURE 4-23 Exchange Function
![Page 44: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/44.jpg)
44
FIGURE 4-24 Calculate Quotient and Remainder
![Page 45: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/45.jpg)
45
FIGURE 4-25 Quotient and Remainder Design
![Page 46: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/46.jpg)
46
PROGRAM 4-8
Quotient and Remainder
![Page 47: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/47.jpg)
47
![Page 48: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/48.jpg)
48
4-5 Standard Functions
C provides a rich collection of standard functions C provides a rich collection of standard functions whose definitions have been written and are ready to whose definitions have been written and are ready to be used in our programs. To use these functions, we be used in our programs. To use these functions, we must include their function declarations.must include their function declarations.
Math FunctionsRandom Numbers
Topics discussed in this section:Topics discussed in this section:
![Page 49: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/49.jpg)
49
FIGURE 4-26 Library Functions and the Linker
![Page 50: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/50.jpg)
50
Absolution Value Functions
![Page 51: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/51.jpg)
51
FIGURE 4-27 Ceiling Function
![Page 52: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/52.jpg)
52
FIGURE 4-28 Floor Function
![Page 53: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/53.jpg)
53
Truncation and Round Function
![Page 54: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/54.jpg)
54
Power and Square Root Function
![Page 55: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/55.jpg)
55
FIGURE 4-29 Random Number Generation
Random numbers
![Page 56: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/56.jpg)
56
FIGURE 4-30 Generating a Random Number Series
![Page 57: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/57.jpg)
57
srand must be called only once for each randomnumber series.
NoteNote
![Page 58: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/58.jpg)
58
PROGRAM 4-9
Creating Temporal Random Numbers
![Page 59: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/59.jpg)
59
PROGRAM 4-10
Creating Pseudorandom Numbers
![Page 60: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/60.jpg)
60
FIGURE 4-31 Random Number Scaling for 3–7
![Page 61: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/61.jpg)
61
PROGRAM 4-11 Generating Random Numbers in the Range 10 to 20
![Page 62: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/62.jpg)
62
PROGRAM 4-12
Generating Random Real Numbers
![Page 63: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/63.jpg)
63
4-6 Scope
Scope determines the region of the program in which a Scope determines the region of the program in which a defined object is visible. Scope pertains to any object defined object is visible. Scope pertains to any object that can be declared, such as a variable orthat can be declared, such as a variable ora function declaration. a function declaration.
Global ScopeLocal Scope
Topics discussed in this section:Topics discussed in this section:
![Page 64: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/64.jpg)
64
FIGURE 4-32 Scope for Global and Block Areas
![Page 65: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/65.jpg)
65
Variables are in scope from declaration until the end of their block.
NoteNote
![Page 66: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/66.jpg)
66
4-7 Programming Example— Incremental Development
Top–down development, a concept inherent to Top–down development, a concept inherent to modular programming, allows us to develop programs modular programming, allows us to develop programs incrementally. By writing and debugging each incrementally. By writing and debugging each function separately, we are able to solve the program function separately, we are able to solve the program in smaller steps, making the whole process easier.in smaller steps, making the whole process easier.
First Increment: main and getDataSecond Increment: addFinal Increment: Print ResultsThe
Topics discussed in this section:Topics discussed in this section:
![Page 67: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/67.jpg)
67
FIGURE 4-33 Calculator Program Design
![Page 68: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/68.jpg)
68
PROGRAM 4-13
Calculator Program—First Increment
![Page 69: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/69.jpg)
69
PROGRAM 4-14 Calculator Program—Second Increment
![Page 70: 1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.](https://reader036.fdocuments.in/reader036/viewer/2022062518/5697bf941a28abf838c90409/html5/thumbnails/70.jpg)
70
PROGRAM 4-15 Calculator Program—Final Increment