Presentation is loading. Please wait.

Presentation is loading. Please wait.

Topics discussed in this section:

Similar presentations


Presentation on theme: "Topics discussed in this section:"— Presentation transcript:

1 Topics discussed in this section:
4-4 Inter-Function Communication Although the calling and called functions are two separate entities, they need to communicate to exchange data. The data flow between the calling and called functions can be divided into three strategies: a downward flow, an upward flow, and a bi-directional flow. Topics discussed in this section: Basic Concept C Implementation Computer Science: A Structured Programming Approach Using C

2 a calling and a called function.
Note The C language uses only call by value and return to achieve different types of communications between a calling and a called function. Call by value: value of parameter is passed, so changes made to parameter in function are not reflected in the calling function. Computer Science: A Structured Programming Approach Using C

3 FIGURE 4-17 Downward Communication in C
Computer Science: A Structured Programming Approach Using C

4 FIGURE 4-18 Downward Communication
Computer Science: A Structured Programming Approach Using C

5 FIGURE 4-19 Upward Communication in C
Computer Science: A Structured Programming Approach Using C

6 FIGURE 4-20 Upward Communication
Computer Science: A Structured Programming Approach Using C

7 To send data from the called function to the calling function:
Note 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 variable 3. We need to use the * in front of the variable when we store data indirectly Computer Science: A Structured Programming Approach Using C

8 FIGURE 4-21 Bi-directional Communication in C
Computer Science: A Structured Programming Approach Using C

9 1 FIGURE 4-22 Bi-directional Communication
Computer Science: A Structured Programming Approach Using C

10 FIGURE 4-23 Exchange Function
Computer Science: A Structured Programming Approach Using C

11 FIGURE 4-24 Calculate Quotient and Remainder
Computer Science: A Structured Programming Approach Using C

12 Quotient and Remainder
PROGRAM 4-8 Quotient and Remainder Computer Science: A Structured Programming Approach Using C

13 Quotient and Remainder
PROGRAM 4-8 Quotient and Remainder Computer Science: A Structured Programming Approach Using C

14 Quotient and Remainder
PROGRAM 4-8 Quotient and Remainder Computer Science: A Structured Programming Approach Using C

15 Quotient and Remainder
PROGRAM 4-8 Quotient and Remainder Computer Science: A Structured Programming Approach Using C

16 Topics discussed in this section:
4-5 Standard Functions C provides a rich collection of standard functions whose definitions have been written and are ready to be used in our programs. To use these functions, we must include their function declarations. Topics discussed in this section: Math Functions Random Numbers Computer Science: A Structured Programming Approach Using C

17 FIGURE 4-26 Library Functions and the Linker
Computer Science: A Structured Programming Approach Using C

18 Some functions #include<stdlib
Some functions #include<stdlib.h> abs() int = abs(int) rand() srand() Others: malloc, qsort, etc. Computer Science: A Structured Programming Approach Using C

19 Math functions #include <math. h> trig: cos(), etc
Math functions #include <math.h> trig: cos(), etc. pow(base, exp); log, exp, etc. sqrt() ceil(), floor(), trunc(), round(), etc. Computer Science: A Structured Programming Approach Using C

20 FIGURE 4-27 Ceiling Function
Computer Science: A Structured Programming Approach Using C

21 FIGURE 4-28 Floor Function
Computer Science: A Structured Programming Approach Using C

22 FIGURE 4-29 Random Number Generation
Computer Science: A Structured Programming Approach Using C

23 FIGURE 4-30 Generating a Random Number Series
Computer Science: A Structured Programming Approach Using C

24 srand must be called only once for each random number series.
Note srand must be called only once for each random number series. Computer Science: A Structured Programming Approach Using C

25 Creating Temporal Random Numbers
PROGRAM 4-9 Creating Temporal Random Numbers Computer Science: A Structured Programming Approach Using C

26 Creating Temporal Random Numbers
PROGRAM 4-9 Creating Temporal Random Numbers Computer Science: A Structured Programming Approach Using C

27 Creating Pseudorandom Numbers
PROGRAM 4-10 Creating Pseudorandom Numbers Computer Science: A Structured Programming Approach Using C

28 Creating Pseudorandom Numbers
PROGRAM 4-10 Creating Pseudorandom Numbers Computer Science: A Structured Programming Approach Using C

29 FIGURE 4-31 Random Number Scaling for 3–7
Computer Science: A Structured Programming Approach Using C

30 Generating Random Numbers in the Range 10 to 20
PROGRAM 4-11 Generating Random Numbers in the Range 10 to 20 Computer Science: A Structured Programming Approach Using C

31 Generating Random Numbers in the Range 10 to 20
PROGRAM 4-11 Generating Random Numbers in the Range 10 to 20 Computer Science: A Structured Programming Approach Using C

32 Generating Random Real Numbers
PROGRAM 4-12 Generating Random Real Numbers Computer Science: A Structured Programming Approach Using C

33 Generating Random Real Numbers
PROGRAM 4-12 Generating Random Real Numbers Computer Science: A Structured Programming Approach Using C

34 Topics discussed in this section:
4-6 Scope Scope determines the region of the program in which a defined object is visible. Scope pertains to any object that can be declared, such as a variable or a function declaration. Topics discussed in this section: Global Scope Local Scope Computer Science: A Structured Programming Approach Using C

35 FIGURE 4-32 Scope for Global and Block Areas
Computer Science: A Structured Programming Approach Using C

36 Variables are in scope from declaration until the end of their block.
Note Variables are in scope from declaration until the end of their block. Computer Science: A Structured Programming Approach Using C

37 Topics discussed in this section:
4-7 Programming Example— Incremental Development Top–down development, a concept inherent to modular programming, allows us to develop programs incrementally. By writing and debugging each function separately, we are able to solve the program in smaller steps, making the whole process easier. Topics discussed in this section: First Increment: main and getData Second Increment: add Final Increment: Print ResultsThe Computer Science: A Structured Programming Approach Using C

38 FIGURE 4-33 Calculator Program Design
Computer Science: A Structured Programming Approach Using C

39 Calculator Program—First Increment
Computer Science: A Structured Programming Approach Using C

40 Calculator Program—First Increment
Computer Science: A Structured Programming Approach Using C

41 Calculator Program—First Increment
Computer Science: A Structured Programming Approach Using C

42 Calculator Program—Second Increment
Computer Science: A Structured Programming Approach Using C

43 Calculator Program—Second Increment
Computer Science: A Structured Programming Approach Using C

44 Calculator Program—Second Increment
Computer Science: A Structured Programming Approach Using C

45 Calculator Program—Second Increment
Computer Science: A Structured Programming Approach Using C

46 Calculator Program—Final Increment
Computer Science: A Structured Programming Approach Using C

47 Calculator Program—Final Increment
Computer Science: A Structured Programming Approach Using C

48 Calculator Program—Final Increment
Computer Science: A Structured Programming Approach Using C

49 Calculator Program—Final Increment
Computer Science: A Structured Programming Approach Using C


Download ppt "Topics discussed in this section:"

Similar presentations


Ads by Google