Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to.

Slides:



Advertisements
Similar presentations
©Brooks/Cole, 2003 Chapter 10 Software Engineering.
Advertisements

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Communication between modules, cohesion and coupling
16/11/2015 9:05 AM6/11/2015 9:05 AM6/11/2015 9:05 AMFunctions Functions A function consists of: Name Name Arguments (also called parameters) Arguments.
Introduction to Computers and Programming Introduction to Methods in Java.
Chapter 6: User-Defined Functions I
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
J. Michael Moore Software Design CSCE 110 Influenced by material developed by James Tam & Jennifer Welch.
Wednesday, 10/9/02, Slide #1 CS 106 Intro to CS 1 Wednesday, 10/9/02  QUESTIONS ??  Today:  Discuss HW #02  Discuss test question types  Review 
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 6: User-Defined Functions I.
Chapter 6: User-Defined Functions I
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
Topic 4 – Programmer- Defined Functions. CISC 105 – Topic 4 Functions So far, we have only seen programs with one function, main. These programs begin.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic concepts and uses of arrays ❏ To be able to define C.
CMSC 104, Version 8/061L18Functions1.ppt Functions, Part 1 of 4 Topics Using Predefined Functions Programmer-Defined Functions Using Input Parameters Function.
Introduction to Computers
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. C How To Program - 4th edition Deitels Class 05 University.
CS0004: Introduction to Programming Subprocedures and Modular Design.
1 MT258 Computer Programming and Problem Solving Unit 7.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design First Edition by Tony Gaddis.
Chapter 06 (Part I) Functions and an Introduction to Recursion.
Computer Science: A Structured Programming Approach Using C1 4-6 Scope Scope determines the region of the program in which a defined object is visible.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To be able to list and describe the six expression categories ❏ To understand.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand how decisions are made in a computer ❏ To understand the logical.
Functions Top-down design Breaking a complex problem into smaller parts that we can understand is a common practice. The process of subdividing a problem.
Chapter 10 Software Engineering. Understand the software life cycle. Describe the development process models. Understand the concept of modularity in.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
CMSC 104, Version 8/061L17Top-DownDesign.ppt Top-Down Design Topics Top-Down Design Top-Down Design Examples The Function Concept Reading Sections 3.1.
First Steps in Modularization. Simple Program Design, Fourth Edition Chapter 8 2 Objectives In this chapter you will be able to: Introduce modularization.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To introduce the structure, union, and enumerated types ❏ To use the type definition.
First Steps in Modularization. Simple Program Design, Fourth Edition Chapter 8 2 Objectives In this chapter you will be able to: Introduce modularization.
Cosc175/module.ppt1 Introduction to Modularity Function/procedures void/value-returning Arguments/parameters Formal arguments/actual arguments Pass by.
KIC/Computer Programming & Problem Solving 1.  Introduction  Program Modules in C  Math Library Functions  Functions  Function Definitions  Function.
Topics discussed in this section:
1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to design multi-function programs ❏ To understand the purpose.
Computer Science By: Erica Ligons Compound Statement A compound statement- block A compound statement- is a unit of code consisting of zero or more statement.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
Computing Higher – SD Unit - Topic 8 – Procedure and Standard Algorithms P Lynch, St Andrew’s High School Unit 2 Software Development Process Topic.
CSI 1340 Introduction to Computer Science II Chapter 1 Software Engineering Principles.
Chapter 3: User-Defined Functions I
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the concept and use of pointers ❏ To be able to declare, define,
1 UMBC CMSC 104, Section Fall 2002 Functions, Part 1 of 3 Topics Top-down Design The Function Concept Using Predefined Functions Programmer-Defined.
Computer Science: A Structured Programming Approach Using C1 5-5 Incremental Development Part II In Chapter 4, we introduced the concept of incremental.
Computer Science: A Structured Programming Approach Using C1 5-5 Incremental Development Part II In Chapter 4, we introduced the concept of incremental.
Computer Programming Basics Assistant Professor Jeon, Seokhee Assistant Professor Department of Computer Engineering, Kyung Hee University, Korea.
COP 2220 Computer Science I Topics –Breaking Problems Down –Functions –User-defined Functions –Calling Functions –Variable Scope Lecture 4.
Functions, Part 1 of 3 Topics  Using Predefined Functions  Programmer-Defined Functions  Using Input Parameters  Function Header Comments Reading 
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand how decisions are made in a computer ❏ To understand the logical.
Chapter 12 Enumerated, Structure, and Union Types Objectives
Functions Review.
FIGURE 4-10 Function Return Statements
Chapter 9 Pointers Objectives
3-7 Sample Programs This section contains several programs that you should study for programming technique and style. Computer Science: A Structured.
Topics discussed in this section:
4-2 Functions in C In C, the idea of top–down design is done using functions. A C program is made of one or more functions, one and only one of which.
Chapter 4 Functions Objectives
Topics discussed in this section:
Topics discussed in this section:
Topics discussed in this section:
Topics discussed in this section:
4-2 Functions in C In C, the idea of top–down design is done using functions. A C program is made of one or more functions, one and only one of which.
IMPLICIT DIFFERENTIATION
Topics discussed in this section:
Introduction to C++ Programming Language
Selection—Making Decisions
Topics discussed in this section:
IMPLICIT DIFFERENTIATION
Introduction to Computers
Presentation transcript:

Computer Science: A Structured Programming Approach Using C1 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 ❏ To understand the software engineering principles of functional cohesion and top–down development Chapter 4 Chapter 4 Functions Functions

Computer Science: A Structured Programming Approach Using C2 FIGURE 4-1 Derived Types

Computer Science: A Structured Programming Approach Using C3 4-1 Designing Structured Programs The programs we have presented so far have been very simple. They solved problems that could be understood without too much effort. The principles of top–down design and structured programming dictate that a program should be divided into a main module and its related modules. Each module should also be divided into submodules according to software engineering principles that we discuss in Section 4.8, “Software Engineering.”

Computer Science: A Structured Programming Approach Using C4 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. Note

Computer Science: A Structured Programming Approach Using C5 FIGURE 4-2 Structure Chart

Computer Science: A Structured Programming Approach Using C6 4-2 Functions in C In C, the idea of top–down design is done using functions. A C program is made of one or more functions, one and only one of which must be named main. In general, the purpose of a function is to receive zero or more pieces of data, operate on them, and return at most one piece of data. At the same time, a function can have a side effect. A function side effect is an action that results in a change in the state of the program.

Computer Science: A Structured Programming Approach Using C7 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. Note

Computer Science: A Structured Programming Approach Using C8 FIGURE 4-3 Structure Chart for a C Program

Computer Science: A Structured Programming Approach Using C9 FIGURE 4-4 Function Concept

Computer Science: A Structured Programming Approach Using C10 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 called for its value, its side effect, or both. Note

Computer Science: A Structured Programming Approach Using C11 PROGRAM 4-1 Sample Program with Subfunction

Computer Science: A Structured Programming Approach Using C12 PROGRAM 4-1 Sample Program with Subfunction

Computer Science: A Structured Programming Approach Using C13 PROGRAM 4-1 Sample Program with Subfunction

Computer Science: A Structured Programming Approach Using C User-Defined Functions Like every other object in C, functions must be both declared and defined. The function declaration gives the whole picture of the function that needs to be defined later. The function definition contains the code for a function. Basic Function Designs Function Definition Function Declaration The Function Call Topics discussed in this section:

Computer Science: A Structured Programming Approach Using C15 A function name is used three times: for declaration, in a call, and for definition. Note

Computer Science: A Structured Programming Approach Using C16 FIGURE 4-5 Declaring, Calling, and Defining Functions

Computer Science: A Structured Programming Approach Using C17 FIGURE 4-6 void Function with Parameters

Computer Science: A Structured Programming Approach Using C18 PROGRAM 4-2void Function with a Parameter

Computer Science: A Structured Programming Approach Using C19 PROGRAM 4-2void Function with a Parameter

Computer Science: A Structured Programming Approach Using C20 PROGRAM 4-2void Function with a Parameter

Computer Science: A Structured Programming Approach Using C21 FIGURE 4-7 Non-void Function without Parameters

Computer Science: A Structured Programming Approach Using C22 FIGURE 4-8 Calling a Function That Returns a Value

Computer Science: A Structured Programming Approach Using C23 PROGRAM 4-3Read a Number and Square It

Computer Science: A Structured Programming Approach Using C24 PROGRAM 4-3Read a Number and Square It

Computer Science: A Structured Programming Approach Using C25 PROGRAM 4-3Read a Number and Square It

Computer Science: A Structured Programming Approach Using C26 PROGRAM 4-3Read a Number and Square It

Computer Science: A Structured Programming Approach Using C27 FIGURE 4-9 Function Definition