tailieunhanh - Lecture C++ for everyone (2nd edition): Chapter 5 - Cay S. Horstmann
Chapter 5 - Functions. In this chapter, you will learn how to design and implement your own functions. using the process of stepwise refinement, you will be able to break up complex tasks into sets of cooperating functions. | C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Chapter Five: Functions Slides by Evan Gallagher C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved To be able to implement functions To become familiar with the concept of parameter passing To appreciate the importance of function comments To develop strategies for decomposing complex tasks into simpler ones To be able to determine the scope of a variable To recognize when to use value and reference parameters Chapter Goals C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Call a Function to Get Something Done If it’s chilly in here do something about it! C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved What Is a Function? Why Functions? A function is a sequence of instructions with a name. A function packages a computation into a form that can be easily understood | C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Chapter Five: Functions Slides by Evan Gallagher C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved To be able to implement functions To become familiar with the concept of parameter passing To appreciate the importance of function comments To develop strategies for decomposing complex tasks into simpler ones To be able to determine the scope of a variable To recognize when to use value and reference parameters Chapter Goals C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Call a Function to Get Something Done If it’s chilly in here do something about it! C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved What Is a Function? Why Functions? A function is a sequence of instructions with a name. A function packages a computation into a form that can be easily understood and reused. C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Calling a Function A programmer calls a function to have its instructions executed. the caller (getting things done) the function (has the modify temperature instructions) C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Calling a Function int main() { double z = pow(2, 3); . } By using the expression: pow(2, 3) main calls the pow function, asking it to compute 23. The main function is temporarily suspended. The instructions of the pow function execute and compute the result. The pow function returns its result back to main, and the main function resumes execution. C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Calling a Function Execution flow during a function call C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Parameters int main() { double
đang nạp các trang xem trước