[...]... Pearson Addison-Wesley Slide 4- 24 Display 4.3 (1/2) Back Copyright © 2007 Pearson Education, Inc Publishing as Pearson Addison-Wesley Next Slide 4- 25 Display 4.3 (2/2) Copyright © 2007 Pearson Education, Inc Publishing as Pearson Addison-Wesley Back Next Slide 4- 26 Function Call Details The values of the arguments are plugged into the formal parameters (Call-by-value mechanism with call-by-value parameters)... Determine the value of pow(2,3) fabs (-3 .5) 7 / abs (-2 ) ceil(5.8) sqrt(pow(3,2)) floor(5.8) Convert the following to C++ x+ y Copyright © 2007 Pearson Education, Inc Publishing as Pearson Addison-Wesley − b + b2 − 4ac 2a x y+ 7 Slide 4- 18 4.3 Programmer-Defined Functions Copyright © 2007 Pearson Education, Inc Publishing as Pearson Addison-Wesley Programmer-Defined Functions Two components of a... namespace std; Copyright © 2007 Pearson Education, Inc Publishing as Pearson Addison-Wesley Slide 4- 12 Other Predefined Functions abs(x) - int value = abs (-8 ); Returns absolute value of argument x Return value is of type int Argument is of type x Found in the library cstdlib fabs(x) - double value = fabs (-8 .0); Returns the absolute value of argument x Return value is of type double... 2007 Pearson Education, Inc Publishing as Pearson Addison-Wesley Slide 4- 16 Old Style Type Cast C++ is an evolving language This older method of type casting may be discontinued in future versions of C++ candy_per_person = double(total_candy)/number_of_people; Copyright © 2007 Pearson Education, Inc Publishing as Pearson Addison-Wesley Slide 4- 17 Section 4.2 Conclusion Can you Determine the... 4.4 (2) Copyright © 2007 Pearson Education, Inc Publishing as Pearson Addison-Wesley Slide 4- 27 Display 4.4 (1/2) Back Copyright © 2007 Pearson Education, Inc Publishing as Pearson Addison-Wesley Next Slide 4- 28 Display 4.4 (2/2) Copyright © 2007 Pearson Education, Inc Publishing as Pearson Addison-Wesley Back Next Slide 4- 29 Alternate Declarations Two forms for function declarations List... this! Copyright © 2007 Pearson Education, Inc Publishing as Pearson Addison-Wesley (2) Slide 4- 31 Display 4.5 (1/2) Back Copyright © 2007 Pearson Education, Inc Publishing as Pearson Addison-Wesley Next Slide 4- 32 Display 4.5 (2/2) Copyright © 2007 Pearson Education, Inc Publishing as Pearson Addison-Wesley Back Next Slide 4- 33 Function Definition Syntax Within a function definition Variables... least one return statement must end the function Each branch of an if-else statement might have its own return statement Display 4.6 Copyright © 2007 Pearson Education, Inc Publishing as Pearson Addison-Wesley Slide 4- 34 Display 4.6 Copyright © 2007 Pearson Education, Inc Publishing as Pearson Addison-Wesley Back Next Slide 4- 35 Placing Definitions A function call must be preceded by either ... Argument is of type double Display 4.2 Found in the library cmath Copyright © 2007 Pearson Education, Inc Publishing as Pearson Addison-Wesley Slide 4- 13 Display 4.2 Copyright © 2007 Pearson Education, Inc Publishing as Pearson Addison-Wesley Back Next Slide 4- 14 Type Casting Recall the problem with integer division: int total_candy = 9, number_of_people = 4; double candy_per_person; candy_per_person... Pearson Addison-Wesley Slide 4- 22 The Return Statement Ends the function call Returns the value calculated by the function Syntax: return expression; expression performs the calculation or expression is a variable containing the calculated value Example: return subtotal + subtotal * TAX_RATE; Copyright © 2007 Pearson Education, Inc Publishing as Pearson Addison-Wesley Slide 4- 23 The Function... one type from another type static_cast(total_candy) produces a double representing the integer value of total_candy Copyright © 2007 Pearson Education, Inc Publishing as Pearson Addison-Wesley Slide 4- 15 Type Cast Example int total_candy = 9, number_of_people = 4; double candy_per_person; candy_per_person = static_cast(total_candy) / number_of_people; candy_per_person now is 2.25! . Addison-Wesley Chapter 4 Procedural Abstraction and Functions That Return a Value Slide 4- 3 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Overview 4.1 Top-Down. Publishing as Pearson Addison-Wesley 4.2 Predefined Functions Slide 4- 8 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Predefined Functions C++ comes with libraries. sqrt(area); Slide 4- 10 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Back Next Display 4.1 Slide 4- 11 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Function