Đang chuẩn bị liên kết để tải về tài liệu:
Lecture Programming in C++ - Chapter 7: Functions

Không đóng trình duyệt đến khi xuất hiện nút TẢI XUỐNG

Lecture Programming in C++ - Chapter 7: Functions. On completion of this chapter students will know how to: Define and call functions, determine the scope of a variable, pass values by reference, overload functions, create random numbers. | Chapter 7 - Functions Functions Code group that performs single task Specification refers to what goes into and out of function Design refers to function’s task(s) Two groups Library Programmer-defined Lesson 7.1 Function Categories Return no value Return a single value Use “pass by reference” Lesson 7.1 Function Basics Need three things to use function Function declaration (prototype) Indicates function exists and describes it Must be done before use of function Function call (invocation) Causes control to transfer from function to function Function definition Header line followed by function body enclosed in braces Lesson 7.1 Function Declaration Indicates function name, return type and types of values passed to function General form ftype fname (atype, atype); ftype is function return type fname is function name atype is argument type (may be different) multiple argument separated by commas Lesson 7.1 Function Call Transfers program control to function General form fname (exp1, . | Chapter 7 - Functions Functions Code group that performs single task Specification refers to what goes into and out of function Design refers to function’s task(s) Two groups Library Programmer-defined Lesson 7.1 Function Categories Return no value Return a single value Use “pass by reference” Lesson 7.1 Function Basics Need three things to use function Function declaration (prototype) Indicates function exists and describes it Must be done before use of function Function call (invocation) Causes control to transfer from function to function Function definition Header line followed by function body enclosed in braces Lesson 7.1 Function Declaration Indicates function name, return type and types of values passed to function General form ftype fname (atype, atype); ftype is function return type fname is function name atype is argument type (may be different) multiple argument separated by commas Lesson 7.1 Function Call Transfers program control to function General form fname (exp1, exp2); fname is function name exp1 and exp2 are arguments Variables or constants Called argument list Lesson 7.1 Function Definition Includes function’s executable statements General form (example with two arguments) Lesson 7.1 Function return type Function return type Function argument declarations Function body ftype fname (atype aname, atype aname) { } Argument Lists Lists in function call and function header must coordinate number order type Example: Lesson 7.1 kinetic_energy (mass, velocity); void kinetic_energy (int m, double v) Function call in main Function header 2 arguments in each mass should be declared an integer and velocity a double in program Function Arrangement Not necessary for first function to be main Function definition must be located outside body of any other function Can write function declaration outside body of all functions or within function if within, can only be called from function where declared Function declaration MUST appear before call Lesson 7.1

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.