Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to C++ Programming Language

Similar presentations


Presentation on theme: "Introduction to C++ Programming Language"— Presentation transcript:

1 Introduction to C++ Programming Language
Jeon, Seokhee Assistant Professor Department of Computer Engineering, Kyung Hee University, Korea

2 Announcement on Exam 1 10.8 (Monday)
Scope: Chapter 1 ~ Chapter 4 (Until we’ve learned today) Effect on grading: 15% Written exam with closed book Good Luck!!

3 Chapter 4 Functions

4 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.

5 Structure Chart

6 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.

7 Structure Chart for a C++ Program

8 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.

9 Functions in C++

10 User-Defined Functions - Declaring, Calling, and Defining

11 Functions without Return Value (Only Have Side Effect)

12 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.

13 Functions with Return Value

14 Function Definition

15 Function Return Statements

16 Function Local Variables

17 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.

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

19 Examples of Function Calls

20 Pass by Value Different local variables

21 Pass by Reference

22 A Bad Exchange

23 Calculate Quotient and Remainder

24 Default Parameter Arguments
Default values for parameters can be defined in function declaration

25 Library Functions and the Linker

26 Standard Library Functions

27 Floor and Ceiling Functions

28 abs(), pow(), and sqrt() abs(3)  returns 3 fabs(-3.4)  returns 3.4
pow(3.0, 4.0)  returns 81 (3^4) pow(3.4, 2.3)  returns sqrt(25.0)  returns 5.0

29 Scope for Global and Block Areas

30 Scope for Global and Block Areas
Variables are in scope from their point of definition until the end of their function or block. It is poor programming style to reuse identifiers within the same scope.


Download ppt "Introduction to C++ Programming Language"

Similar presentations


Ads by Google