Presentation is loading. Please wait.

Presentation is loading. Please wait.

Functions Are supposed to be fun…. Parameter=Door The word parameter is to function as door is to house. A parameter is used to get data into a function.

Similar presentations


Presentation on theme: "Functions Are supposed to be fun…. Parameter=Door The word parameter is to function as door is to house. A parameter is used to get data into a function."— Presentation transcript:

1

2 Functions Are supposed to be fun….

3 Parameter=Door The word parameter is to function as door is to house. A parameter is used to get data into a function through variables. FUNCTION parameter

4 Function Declarations A form that contains a r rr return type, function’s name, and parameter declarations. –d–d–d–double cube(int side); These are written before the main programming section and below the includes.

5 Function Implementation A detailed, complete and executable description of a function. double cube(int side) { return (side*side*side); } These are written after the main programming section.

6 Parameters A formal parameter is found in the function heading in the implementation section. An actual parameter is when you call the function. The number of arguments in a formal parameter is the same as the actual parameter.

7 Function declaration For example #include int cube (int side); void main { int theside; cout<<“enter the side of the cube”; cin>> theside; cout<<“The volume of the cube is “<< cube(theside); getch(); } int cube (int side); { return(side*side*side); } Function implementation actual parameter formal parameter Notice the TYPES in the parameters match?

8 Return Value The function itself can return a value. –Use this if you only have one thing you need from a function. If you need more than one value from a function you can return values using the parameters. –void get_length(int &width, int &length); –use void if you are not returning a value through the function.

9 Generic Functions The function is used for different things that have the same overall appearance. get_side(“length”); get_side(“width”); Implementation int get_side(apstring name); { int side; cout<<“Please enter the “<<name<< “of your figure.” cin>>side; return(side); }

10 Assignment Problem number 6 on page 193. All work should be done in functions. The main section should only call the functions. The input files are the 1st 4 digits of the team name there are 3 teams. The names of the teams can be found in team.txt and the output file is bowl.txt. Listen for more instructions. Sample input files will be given. DUE FRIDAY.


Download ppt "Functions Are supposed to be fun…. Parameter=Door The word parameter is to function as door is to house. A parameter is used to get data into a function."

Similar presentations


Ads by Google