1 / 49

4-4 Inter-Function Communication

4-4 Inter-Function Communication.

lynde
Télécharger la présentation

4-4 Inter-Function Communication

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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. 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. 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. PROGRAM 4-8 Quotient and Remainder Computer Science: A Structured Programming Approach Using C

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

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

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

  16. 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.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.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-29Random 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. Note srand must be called only once for each randomnumber series. Computer Science: A Structured Programming Approach Using C

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

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

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

  28. 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. PROGRAM 4-11 Generating Random Numbers in the Range 10 to 20 Computer Science: A Structured Programming Approach Using C

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

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

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

  34. 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. Note Variables are in scope from declaration until the end of their block. Computer Science: A Structured Programming Approach Using C

  37. 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. PROGRAM 4-13 Calculator Program—First Increment Computer Science: A Structured Programming Approach Using C

  40. PROGRAM 4-13 Calculator Program—First Increment Computer Science: A Structured Programming Approach Using C

  41. PROGRAM 4-13 Calculator Program—First Increment Computer Science: A Structured Programming Approach Using C

  42. PROGRAM 4-14 Calculator Program—Second Increment Computer Science: A Structured Programming Approach Using C

  43. PROGRAM 4-14 Calculator Program—Second Increment Computer Science: A Structured Programming Approach Using C

  44. PROGRAM 4-14 Calculator Program—Second Increment Computer Science: A Structured Programming Approach Using C

  45. PROGRAM 4-14 Calculator Program—Second Increment Computer Science: A Structured Programming Approach Using C

  46. PROGRAM 4-15 Calculator Program—Final Increment Computer Science: A Structured Programming Approach Using C

  47. PROGRAM 4-15 Calculator Program—Final Increment Computer Science: A Structured Programming Approach Using C

  48. PROGRAM 4-15 Calculator Program—Final Increment Computer Science: A Structured Programming Approach Using C

  49. PROGRAM 4-15 Calculator Program—Final Increment Computer Science: A Structured Programming Approach Using C

More Related