当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

《C++程序设计》(英文版) Chapter 7 Topics

资源类别:文库,文档格式:PPT,文档页数:56,文件大小:3.11MB,团购合买
Chapter 7 Topics Writing a Program Using Functional Decomposition Writing a Void Function for a Task Using Function Arguments and Parameters correctly
点击下载完整版文档(PPT)

Programming in c++ Functions Dale/eems/Headington

1 Functions

Programming in C++ Chapter 7 Topics Writing a Program Using Functional Decomposition Writing a Void Function for a Task s Using Function Arguments and Parameters correctly Differences between Value Parameters and Reference Parameters s Using Local Variables in a Function Function Preconditions and Postconditions

2 Chapter 7 Topics ❖Writing a Program Using Functional Decomposition ❖Writing a Void Function for a Task ❖Using Function Arguments and Parameters correctly ❖Differences between Value Parameters and Reference Parameters ❖Using Local Variables in a Function ❖Function Preconditions and Postconditions

Programming in C++ Functions oevery C++ program must have a function called main program execution always begins with function main o any other functions are subprograms and must be called

3 Functions ❖every C++ program must have a function called main ❖program execution always begins with function main ❖any other functions are subprograms and must be called

Programming in C++ Function Call(Invocation One function calls another by using the name of the called function next to( enclosing an argument list A function call temporarily transfers control from the calling function to the called function

4 Function Call (Invocation) One function calls another by using the name of the called function next to ( ) enclosing an argument list. A function call temporarily transfers control from the calling function to the called function

Programming in C++ Function Call Syntax FunctionName( Argument List The argument list is a way for functions to communicate with each other by passing information y The argument list can contain 0, 1, or more arguments, separated by commas, depending on the function

5 FunctionName ( Argument List ); ➢ The argument list is a way for functions to communicate with each other by passing information. ➢ The argument list can contain 0, 1, or more arguments, separated by commas, depending on the function. Function Call Syntax

Programming in C++ Function Call Syntax( Cont) Argument List Expression, Expression >When a function call is executed the arguments are passed to the parameters according to their positions, left to right, and control is then transferred to the first executable statement in the function body. )When the last statement in the function has executed control returns to the point from which the function was called

6 Function Call Syntax(Cont.) Expression, Expression… Argument List ➢When a function call is executed, the arguments are passed to the parameters according to their positions, left to right, and control is then transferred to the first executable statement in the function body. ➢When the last statement in the function has executed, control returns to the point from which the function was called

Programming in C++ TWo Parts of Function Definition int Cube( int n) heading body return nxnxn

7 Two Parts of Function Definition int Cube ( int n ) heading { body return n * n * n ; }

Programming in C++ What is in a heading? type of value returned name of parameter list int Cube int n

8 What is in a heading? int Cube ( int n ) type of value returned name of function parameter list

Programming in C++ What is in a prototype? A prototype looks like a heading but must end with a semicolon; and its parameter list just needs to contain the type of each parameter. int Cube( int ); prototype

9 What is in a prototype? A prototype looks like a heading but must end with a semicolon; and its parameter list just needs to contain the type of each parameter. int Cube( int ); // prototype

Programming in C++ The difference between Function Definition and Function Prototype )Function Definition: A function declaration that includes the body of the function >Function Prototype: A function declaration that without the body of the function Note that all definitions are declarations but not all declarations are definitions The rule throughout C++ is that you can declare an item as many times as you wish, but you can define it only once 10

10 The difference between Function Definition and Function Prototype ➢Function Definition: A function declaration that includes the body of the function. ➢Function Prototype: A function declaration that without the body of the function. • Note that all definitions are declarations, but not all declarations are definitions. • The rule throughout C++ is that you can declare an item as many times as you wish, but you can define it only once

点击下载完整版文档(PPT)VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
共56页,可试读19页,点击继续阅读 ↓↓
相关文档

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有