|
@@ -55,7 +55,7 @@ In mathematics, a function $$f$$ is a rule that is used to assign to each elemen
|
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
|
|
58
|
|
-### Function header:
|
|
58
|
+### Function header
|
59
|
59
|
|
60
|
60
|
The first sentence of a function is called the *header* and its structure is as follows:
|
61
|
61
|
|
|
@@ -243,10 +243,10 @@ To plot a curve that is described by parametric equations, we compute the $$x$$
|
243
|
243
|
|
244
|
244
|
In the introduction to the topic of functions you saw that in mathematics and in some programming languages, a function cannot return more than one result. In this laboratory experience's exercises, you will practice how to use reference variables to obtain various results from a function.
|
245
|
245
|
|
246
|
|
-### Exercise 1: Difference between Pass by Value and Pass by Reference
|
|
246
|
+### Exercise 1 - Difference between Pass by Value and Pass by Reference
|
247
|
247
|
|
248
|
248
|
|
249
|
|
-**Instructions**
|
|
249
|
+#### Instructions
|
250
|
250
|
|
251
|
251
|
1. Load the project ‘prettyPlot’ into ‘QtCreator`. There are two ways to do this:
|
252
|
252
|
|
|
@@ -274,9 +274,9 @@ In the introduction to the topic of functions you saw that in mathematics and in
|
274
|
274
|
|
275
|
275
|
4. Execute the program and observe what is displayed in the window `Application Output`. Notice the difference between the content of the variables `argValue` and `argRef` despite the fact that both had the same initial value, and that `paramValue` and `paramRef` were assigned the same value. Explain why the content of `argValor` does not change, while the content of `argRef` changes from 0 to 1.
|
276
|
276
|
|
277
|
|
-### Exercise 2: Creation of an Overloaded Function
|
|
277
|
+### Exercise 2 - Creation of an Overloaded Function
|
278
|
278
|
|
279
|
|
-**Instructions**
|
|
279
|
+#### Instructions
|
280
|
280
|
|
281
|
281
|
1. Study the code in the `main()` function in the file `main.cpp`. The line `XYPlotWindow wCircleR5;` creates a `wCircleR5` object that will be the window where the graph will be drawn, in this case the graph of a circle of radius 5. In a similar way, the objects `wCircle` and `wButterfly` are created. Observe the `for` cycle. In this cycle a series of values for the angle $$t$$ are generated and the function `circle` is called, passing the value for $$t$$ and the references to $$x$$ and $$y$$. The `circle` function does not return a value, but by using parameters by reference, it calculates the values for the coordinates $$xCoord$$ and $$yCoord$$ for the circle with center in the origin and radius 5, and allows the `main` function to have these values in the `x` , `y` variables.
|
282
|
282
|
|
|
@@ -313,9 +313,9 @@ In the introduction to the topic of functions you saw that in mathematics and in
|
313
|
313
|
|
314
|
314
|
2. Now you will create an overloaded function `circle` that receives as arguments the value of the angle $$t$$, the reference to the variables $$x$$ and $$y$$, and the value for the radius of the circle. Call the overloaded function `circle` that you just implemented from `main()` to calculate the values of the coordinates $$x$$ and $$y$$ for the circle with radius 15 and draw its graph. Graph the circle within the `wCircle` object. To do this, you must call the method functions `AddPointToGraph(x,y)`, `Plot` and `show` from `main()`. Remember that these should be preceded by `wCircle`, for example, `wCircle.show()`.
|
315
|
315
|
|
316
|
|
-### Exercise 3: Implement a Function to Calculate the Coordinates of the Points in the Graph of a Curve
|
|
316
|
+### Exercise 3 - Implement a Function to Calculate the Coordinates of the Points in the Graph of a Curve
|
317
|
317
|
|
318
|
|
-**Instructions**
|
|
318
|
+#### Instructions
|
319
|
319
|
|
320
|
320
|
1. Now you will create a function to calculate the coordinates of the points of a graph that resembles a butterfly. The parametric equations for the coordinates of the points in the graph are given by:
|
321
|
321
|
|