Functions (2) - Lecture 1 & 2 - PDF
Document Details
Tags
Summary
These lecture notes detail functions in C++. The document covers program components, math library functions, and function definitions, along with associated concepts like function prototypes and header files. The notes use a structured outline format for clarity.
Full Transcript
1 المحاضرة األولى الجزء االول- Functions Outline 3.2 Program Components in C++ 3.3 Math Library Functions 3.4 Functions 3.5 Function Definitions 3.6 Function Prototypes...
1 المحاضرة األولى الجزء االول- Functions Outline 3.2 Program Components in C++ 3.3 Math Library Functions 3.4 Functions 3.5 Function Definitions 3.6 Function Prototypes 3.7 Header Files 3.8 Random Number Generation 3.9 Example: A Game of Chance and Introducing enum 3.10 Storage Classes 3.11 Scope Rules © 2003 Prentice Hall, Inc. All rights reserved. 1 2 3.2 Program Components in C++ Divide and conquer – Construct a program from smaller pieces or components – Each piece more manageable than the original program 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 © 2003 Prentice Hall, Inc. All rights reserved. 2 1 3 3.2 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 (i.e., report back) the results when the task is done. © 2003 Prentice Hall, Inc. All rights reserved. 3 4 3.3 Math Library Functions Perform common mathematical calculations – Include the header file Functions called by writing – functionName (argument); or – functionName(argument1, argument2, …); Example cout number3; 19 20 // number1, number2 and number3 are arguments to 21 // the maximum function call 22 cout