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

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
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 《C++程序设计》(英文版) Chapter 6 Topics.ppt
- 《C++程序设计》(英文版) Chapter 5 Topics.ppt
- 《C++程序设计》(英文版) Chapter 4 Topics.ppt
- 《C++程序设计》(英文版) Chapter 3 Topics.ppt
- 《C++程序设计》(英文版) Chapter 2 Topics.ppt
- 《C++程序设计》(英文版) Chapter 1 Topics.ppt
- 《网络互连技术教程》第9章 广播.ppt
- 《网络互连技术教程》第8章 用户数据报协议—UDP.ppt
- 《网络互连技术教程》第7章 CMP和网络状态.ppt
- 《网络互连技术教程》第6章 地址解析.ppt
- 《网络互连技术教程》第5章 子网与超网.ppt
- 《网络互连技术教程》第4章 网络互连协议——IP.ppt
- 《网络互连技术教程》第3章 网络接入技术.ppt
- 《网络互连技术教程》第2章 网络互连体系.ppt
- 《网络互连技术教程》第1章 网络的历史与发展.ppt
- 《网络互连技术教程》第12章 应用服务.ppt
- 《网络互连技术教程》第11章 域名服务系统—DNS.ppt
- 《网络互连技术教程》第10章 传输控制协议—7CP.ppt
- 高职高专课程:《数据库应用技术(SQL SERVER2000)》电子教案(PPT教学课件)第9章 存储过程与触发器.ppt
- 高职高专课程:《数据库应用技术(SQL SERVER2000)》电子教案(PPT教学课件)第8章 视图及其应用.ppt
- 《C++程序设计》(英文版) Chapter 8 Topics.ppt
- 《C++程序设计》(英文版) Chapter 9 Topics.ppt
- 《C++程序设计》(英文版) Chapter 10 Topics.ppt
- 《C++程序设计》(英文版) Chapter 11 Topics.ppt
- 《C++程序设计》(英文版) Chapter 12 Topic.ppt
- 《C++程序设计》(英文版) Chapter 13 Topics.ppt
- 《C++程序设计》(英文版) Chapter 14 Topics.ppt
- 《C++程序设计》(英文版) Chapter 15 Topics.ppt
- 《Java编程技术基础》第一章 面向对象原理与实现.ppt
- 《Java编程技术基础》第二章 Java的实现基础.ppt
- 《Java编程技术基础》第二章习题.doc
- 《Java编程技术基础》第三章 类与对象(一).ppt
- 《Java编程技术基础》第三章习题.doc
- 《Java编程技术基础》第四章 类与对象(二).ppt
- 《Java编程技术基础》第四章习题.doc
- 《Java编程技术基础》第五章 异常与垃圾收集.ppt
- 《Java编程技术基础》第五章习题.doc
- 《Java编程技术基础》第十一章 Java集合框架.ppt
- 《Java编程技术基础》第十一章习题.doc
- 《Java编程技术基础》第二章 JDBC.ppt