Chapter 4 Slides

Chapter 4 Slides - Click to edit Master subtitle style...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Click to edit Master subtitle style Chapter 4 Chapter 4 11 Engineering Problem Solving with C Chapter 4 Modular Programming with Functions Chapter 4 Chapter 4 22 Objectives To understand how to construct programs modularly from small pieces called functions.. To introduce the common math functions available in the C standard library. To be able to create new functions. To understand the mechanisms used to pass information between functions. Click to edit Master subtitle style Chapter 4 Chapter 4 33 Modularity Idea is to divide and conquer Construct a program from smaller pieces or components These smaller pieces are called modules Each piece more manageable than the original program Chapter 4 Chapter 4 44 Modularity Execution of a program begins in the main function The main function can call other functions Functions defined in the same file and/or Function defined in other files or libraries Functions are also referred to as modules A module is a set of statements that performs a task or computes a value Chapter 4 Chapter 4 55 Program Modules in C Functions or modules in C: Programs combine user-defined functions with library functions C standard library has a wide variety of functions To perform a function call means that we invoke the function Provide function name and arguments (data) Function performs operations or manipulations Function returns results Chapter 4 Chapter 4 66 Program Modules in C (contd ) Function call analogy: Boss asks worker to complete task Worker gets information, does task, returns result Information hiding: boss does not know details Chapter 4 Chapter 4 77 Program Modules in C (contd ) main worker1 worker2 worker3 worker4 worker5 Example: Hierarchical boss function/worker function relationship. Chapter 4 Chapter 4 88 Example: Structure Chart The main function references other functions, which in turn may call additional functions Chapter 4 Chapter 4 99 Examples: Structure Charts The main function references other functions, which in turn may call additional functions Chapter 4 Chapter 4 1010 Advantages of using modules Modules can be written and tested separately Large projects can be developed in parallel Reduces length of program, making it more readable Promotes the concept of abstraction (hiding of internal details of function so other users need not be concerned with them) Chapter 4 Chapter 4 1111 Advantages of using modules (contd ) Functions All variables defined inside functions are local variables known only in function defined Parameters communicate information between functions Benefits of functions Divide and conquer: manageable program development Software reusability Avoidance of code repetition Chapter 4 Chapter 4 1212 Functions Pre-defined (were introduced in Chapt. 2) standard libraries Programmer defined Chapter 4 Chapter 4 1313 Pre-defined Functions Example: sine of an angle...
View Full Document

This note was uploaded on 09/26/2008 for the course ESE 124 taught by Professor Sussman-fort during the Spring '08 term at SUNY Stony Brook.

Page1 / 104

Chapter 4 Slides - Click to edit Master subtitle style...

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

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