Chương 3 - Functions

Functions are "the central objects of investigation" in most fields of modern mathematics. There are many ways to describe or represent a function. Some functions may be defined by a formula or algorithm that tells how to compute the output for a given input. Others are given by a picture, called the graph of the function. | Chapter 3 - Functions Outline Introduction Program Components in C++ Math Library Functions Functions Function Definitions Function Prototypes Header Files Random Number Generation Example: A Game of Chance and Introducing enum Storage Classes Scope Rules Recursion Example Using Recursion: The Fibonacci Series Recursion vs. Iteration Functions with Empty Parameter Lists Chapter 3 - Functions Outline Inline Functions References and Reference Parameters Default Arguments Unary Scope Resolution Operator Function Overloading Function Templates Introduction Divide and conquer Construct a program from smaller pieces or components Each piece more manageable than the original program Program Components in C++ Modules: functions and classes Programs use new and “prepackaged” modules New: programmer-defined functions, classes Prepackaged: from the standard library Functions . | Chapter 3 - Functions Outline Introduction Program Components in C++ Math Library Functions Functions Function Definitions Function Prototypes Header Files Random Number Generation Example: A Game of Chance and Introducing enum Storage Classes Scope Rules Recursion Example Using Recursion: The Fibonacci Series Recursion vs. Iteration Functions with Empty Parameter Lists Chapter 3 - Functions Outline Inline Functions References and Reference Parameters Default Arguments Unary Scope Resolution Operator Function Overloading Function Templates Introduction Divide and conquer Construct a program from smaller pieces or components Each piece more manageable than the original program Program Components in C++ Modules: functions and classes Programs use new and “prepackaged” modules New: programmer-defined functions, classes Prepackaged: from the standard library Functions invoked by function call Function name and information (arguments) it needs Function definitions Only written once Hidden from other functions Program Components in C++ Boss to worker analogy A boss (the calling function or caller) asks a worker (the called function) to perform a task and return (., report back) the results when the task is done. Math Library Functions Perform common mathematical calculations Include the header file Functions called by writing functionName (argument); or functionName(argument1, argument2, ); Example cout Math Library Functions Function arguments can be Constants sqrt( 4 ); Variables sqrt( x ); Expressions sqrt( sqrt( x ) ) ; sqrt( 3 - 6x ); Functions Functions Modularize a program Software reusability Call function multiple times Local variables Known only in the function in which

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã 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.