UML - Introduction to Functions and Classes Value-Returning...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
Introduction to Functions and Classes
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Value-Returning Functions Because the value returned by a value-returning function is unique, we must either do one of the following: Save the value for further calculation X = fun1 (A, b); Use the value in some calculation X = fun1 (A,b) * D + sqrt(A); Print the value cout << “Result is: “ << fun1 (A,b); A value-returning function is used in an assignment or in an output statement
Background image of page 2
Value-Returning Functions (continued) Properties that form the function definition: 1. Name of the function 2. Number of parameters 3. Data type of each parameter 4. Type of the function (return value type) 5. Code required to accomplish the task (the body of the function)
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
User-Defined Functions Void functions : do not have a return type Value-returning functions : have a data type To use these functions you need to: Know the name of the function Know the number of parameters, if any Know the data type of each parameter Know the data type of the value computed by the function, called the type of the function Include the correct header file (if necessary)
Background image of page 4
Value-Returning Functions (continued) Heading : first four properties above Formal Parameter : variable declared in the heading of the function Actual Parameter : variable or expression listed in a call to a function Function Prototype : Introduction of a function Function Call: Using a function
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
// Function Prototype float Round_it (float ); or float Round_it (float Average) ; // Function Definition float Round_it (float Average) // Function header (heading) { float Temp ; // Code segment Temp = floor(Average + 0.5) ; return (Temp) ; // Returned value } // Function call float avg ; cin >> avg ; cout << “Your average is: “ << avg << endl ; avg = Round_it (avg) ; cout <<“Your letter grade is : “<< avg << endl ;
Background image of page 6
Value-Returning Functions (continued) Syntax: functionType : type of the value returned by the function Also called the data type
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Syntax The syntax of the formal parameter list is: The syntax for a function call is: The syntax for the actual parameter list is:
Background image of page 8
Functions The formal parameter list can be empty If the formal parameter list is empty Parentheses are still needed Function heading of the value-returning
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/04/2011 for the course BUAD 1 taught by Professor Na during the Spring '09 term at USC.

Page1 / 32

UML - Introduction to Functions and Classes Value-Returning...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online