Computer Programming Basics Assistant Professor Jeon, Seokhee Assistant Professor Department of Computer Engineering, Kyung Hee University, Korea.

Slides:



Advertisements
Similar presentations
Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 4 Modular Programming with Functions.
Advertisements

1 Lecture 16:User-Definded function I Introduction to Computer Science Spring 2006.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 7: User-Defined Functions II.
Functions Applications of Computer Programming in Earth Sciences Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng.
Chapter 6: User-Defined Functions I
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 6: User-Defined Functions I.
1 Midterm Review COMP 102. Tips l Eat a light meal before the exam l NO electronic devices (including calculators, dictionaries, phones, pagers, etc.)
Chapter 6: User-Defined Functions I
1Chapter 2. 2 Example 3Chapter 2 4 EXAMPLE 5Chapter 2.
Chapter 6: Function. Scope of Variable A scope is a region of the program and broadly speaking there are three places, where variables can be declared:
Java Methods By J. W. Rider. Java Methods Modularity Declaring methods –Header, signature, prototype Static Void Local variables –this Return Reentrancy.
CMSC 104, Version 8/061L18Functions1.ppt Functions, Part 1 of 4 Topics Using Predefined Functions Programmer-Defined Functions Using Input Parameters Function.
Fortran- Subprograms Chapters 6, 7 in your Fortran book.
Chapter 6: User-Defined Functions I Instructor: Mohammad Mojaddam
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.
Chapter 6: User-Defined Functions
Project 1 Due Date: September 25 th Quiz 4 is due September 28 th Quiz 5 is due October2th 1.
Functions Manesh T 2 Chapter Topics Define Function Standard (Predefined) Functions User-Defined Functions Parts of functions.
Functions Modules in C++ are called functions and classes Functions are block of code separated from main() which do a certain task every C++ program must.
Programming in C++ Language ( ) Lecture 5: Functions-Part1 Dr. Lubna Badri.
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.
1 CSE1301 Computer Programming Lecture 12 Functions (Part 1)
FUNCTIONS AND STRUCTURED PROGRAMMING CHAPTER 10. Introduction A c program is composed of at least one function definition, that is the main() function.
ECE122 Feb. 22, Any question on Vehicle sample code?
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
Chapter 6 User-Defined Functions I. Objectives Standard (predefined) functions What are they, and How to use them User-Defined Functions Value returning.
Introduction to C++ Programming Language Assistant Professor Jeon, Seokhee Assistant Professor Department of Computer Engineering, Kyung Hee University,
Cosc175/module.ppt1 Introduction to Modularity Function/procedures void/value-returning Arguments/parameters Formal arguments/actual arguments Pass by.
User defined functions
Chapter 3 Top-Down Design with Functions Part II J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National.
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.
User Defined Methods Methods are used to divide complicated programs into manageable pieces. There are predefined methods (methods that are already provided.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
Modular Programming – User Defined Functions. CSCE 1062 Outline  Modular programming – user defined functions  Value returning functions  return statement.
Functions Math library functions Function definition Function invocation Argument passing Scope of an variable Programming 1 DCT 1033.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
Chapter 3: User-Defined Functions I
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
Chapter 5 Methods 1. Motivations Method : groups statements that perform a function.  Level of abstraction (black box)  Code Reuse – no need to reinvent.
AP Java Ch. 4 Review Question 1  Java methods can return only primitive types (int, double, boolean, etc).
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to.
COP 2220 Computer Science I Topics –Breaking Problems Down –Functions –User-defined Functions –Calling Functions –Variable Scope Lecture 4.
Computer Programming Basics Assistant Professor Jeon, Seokhee Assistant Professor Department of Computer Engineering, Kyung Hee University, Korea.
Functions, Part 1 of 3 Topics  Using Predefined Functions  Programmer-Defined Functions  Using Input Parameters  Function Header Comments Reading 
ECE 103 Engineering Programming Chapter 30 C Functions Herbert G. Mayer, PSU CS Status 8/9/2014 Initial content copied verbatim from ECE 103 material developed.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 4.
TK1924 Program Design & Problem Solving Session 2011/2012
Chapter 6: User-Defined Functions I
Introduction to C++ Programming Language
Introduction to C++ Programming Language
Functions Review.
Procedures and Modular Programming
Chapter 10: Void Functions
FIGURE 4-10 Function Return Statements
FIGURE 4-10 Function Return Statements
2011/11/10: Lecture 21 CMSC 104, Section 4 Richard Chang
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
Introduction to C++ Programming Language
FIGURE 4-10 Function Return Statements
Chapter 6: User-Defined Functions I
Chapter 9: Value-Returning Functions
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.
Introduction to C++ Programming Language
Computer Programming Basics
Department of Statistics St. Joseph’s College (Autonomous)
FIGURE 4-10 Function Return Statements
Presentation transcript:

Computer Programming Basics Assistant Professor Jeon, Seokhee Assistant Professor Department of Computer Engineering, Kyung Hee University, Korea

CHAPTER 4 FUNCTIONS - 1

Designing Structured Programs 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.

Structure Chart

Functions in C++ In C++, a program is made of one or more functions, one and only one of which must be named main. The execution of the program always starts with main, but it can call other functions to do some part of the job.

Structure Chart for a C++ Program

Functions in C++ A function in C++ can have a value, a side effect, or both. –The side effect occurs before the value is returned. –The function’s value is the value of the expression in the return statement. –A function can be called for its value, its side effect, or both.

Functions in C++

User-Defined Functions - Declaring, Calling, and Defining

Functions without Return Value (Only Have Side Effect)

void functions cannot be used in an expression; they must be a separate statement. Functions that return a value may be used in an expression or as a separate statement.

Functions with Return Value

Function Definition

Function Return Statements

Function Local Variables

Notes on Parameters Formal parameters are variables that are declared in the header of the function definition. Actual parameters are the expressions in the calling statement. The formal and actual parameters must match exactly in type, order, and number. Their names, however, do not need to be the same.

Part of a Function Call The type of the expression in the return statement must match the return type in the function header.

Examples of Function Calls

Program 4-1

Program 4-2

Program 4-3

Program 4-4

Program 4-5

Program 4-6