|
@@ -51,7 +51,7 @@ Before you get to the laboratory you should have:
|
51
|
51
|
|
52
|
52
|
## Functions
|
53
|
53
|
|
54
|
|
-In mathematics, a function $$f$$ is a rule that is used to assign to each element $$x$$ from a set called *domain*, one (and only one) element $$y$$ from a set called *range*. This rule is commonly represented with an equation, $$y=f(x)$$. The variable $$x$$ is the parameter of the function and the variable $$y$$ will contain the result of the function. A function can have more than one parameter, but only one result. For example, a function can have the form $$y=f(x_1,x_2)$$ where there are two parameters, and for each pair $$(a,b)$$ that is used as an argument in the function and the function will have only one value of $$y=f(a,b)$$. The domain of the function tells us the type of value that the parameter should have and the range tells us the value that the returned result will have.
|
|
54
|
+In mathematics, a function $$f$$ is a rule that is used to assign to each element $$x$$ from a set called *domain*, one (and only one) element $$y$$ from a set called *range*. This rule is commonly represented with an equation, $$y=f(x)$$. The variable $$x$$ is the parameter of the function and the variable $$y$$ will contain the result of the function. A function can have more than one parameter, but only one result. For example, a function can have the form $$y=f(x_1,x_2)$$ where there are two parameters, and for each pair $$(a,b)$$ that is used as an argument in the function, the function will have only one value of $$y=f(a,b)$$. The domain of the function tells us the type of value that the parameter should have and the range tells us the value that the returned result will have.
|
55
|
55
|
|
56
|
56
|
Functions in programming languages are similar. A function has a series of instructions that take the assigned values as parameters and perform a certain task. In C++ and other programming languages, functions return only one result, as it happens in mathematics. The only difference is that a *programming* function could possibly not return any value (in this case the function is declared as `void`). If the function will return a value, we use the instruction `return`. As in math that you need to specify the domain and range, in programming you need to specify the types of values that the function's parameters and result will have; this is done when declaring the function.
|
57
|
57
|
|
|
@@ -307,7 +307,7 @@ In the introduction to the topic of functions you saw that in mathematics and in
|
307
|
307
|
wCircleR5.AddPointToGraph(x,y);
|
308
|
308
|
}
|
309
|
309
|
|
310
|
|
- After the function call, each ordered pair $$(x,y)$$ is added to the circle’s graph by the member function `AddPointToGraph(x,y)`. After the cycle, the member function `Plot()` is called, which draws the points, and the member function `show()`, which displays the graph. The *members functions* are functions that allow use to work with and object’s data. Notice that each one of the member functions is written after `wCircleR5`, followed by a period. In an upcoming laboratory experience you will learn more about objects, and practice how to create them and invoke their method functions.
|
|
310
|
+ After the function call, each ordered pair $$(x,y)$$ is added to the circle’s graph by the member function `AddPointToGraph(x,y)`. After the cycle, the member function `Plot()` is called, which draws the points, and the member function `show()`, which displays the graph. The *member functions* are functions that allow us to work with an object’s data. Notice that each one of the member functions is written after `wCircleR5`, followed by a period. In an upcoming laboratory experience you will learn more about objects, and practice how to create them and invoke their method functions.
|
311
|
311
|
|
312
|
312
|
The `circle` function implemented in the program is very restrictive since it always calculates the values for the coordinates $$x$$ and $$y$$ of the same circle: the circle with center in the origin and radius 5.
|
313
|
313
|
|