|
@@ -5,7 +5,7 @@
|
5
|
5
|
![rsz_mariposa1.png](images/rsz_mariposa1.png)
|
6
|
6
|
![rsz_mariposa.png](images/rsz_mariposa.png)
|
7
|
7
|
|
8
|
|
-[Version 2016- Tatiana]
|
|
8
|
+[Version 2016- Tatiana- Ive]
|
9
|
9
|
|
10
|
10
|
A good way to organize and structure computer programs is dividing them into smaller parts using functions. Each function carries out a specific task of the problem that we are solving.
|
11
|
11
|
|
|
@@ -241,19 +241,17 @@ To plot a curve that is described by parametric equations, we compute the $$x$$
|
241
|
241
|
|
242
|
242
|
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.
|
243
|
243
|
|
244
|
|
-### Exercise 1
|
|
244
|
+### Exercise 1: Difference between pass by value and pass by reference
|
245
|
245
|
|
246
|
|
-In this exercise you will study the difference between pass by value and pass by reference.
|
247
|
246
|
|
248
|
247
|
**Instructions**
|
249
|
248
|
|
250
|
249
|
1. Load the project ‘prettyPlot’ into ‘QtCreator`. There are two ways to do this:
|
251
|
250
|
|
252
|
|
- *Using the virtual machine: Double click the file `prettyPlot.pro` located in the folder `home/eip/labs/functions-prettyplots` of your virtual machine.
|
253
|
|
- *Downloading the project’s folder from `Bitbucket`: Use a terminal and write the command `git clone http://bitbucket.org/eip-uprrp/functions-prettyplots` to download the folder `functions-prettyplots` from `Bitbucket`. Double click the file `prettyPlot.pro` located in the folder that you downloaded to your computer.
|
|
251
|
+ * Using the virtual machine: Double click the file `prettyPlot.pro` located in the folder `home/eip/labs/functions-prettyplots` of your virtual machine.
|
|
252
|
+ * Downloading the project’s folder from `Bitbucket`: Use a terminal and write the command `git clone http://bitbucket.org/eip-uprrp/functions-prettyplots` to download the folder `functions-prettyplots` from `Bitbucket`. Double click the file `prettyPlot.pro` located in the folder that you downloaded to your computer.
|
254
|
253
|
|
255
|
|
-
|
256
|
|
-3. Configure the project and execute the program by clicking on the green arrow in the menu on the left side of the Qt Creator screen. The program should show a window similar to the one in Figure 3.
|
|
254
|
+2. Configure the project and execute the program by clicking on the green arrow in the menu on the left side of the Qt Creator screen. The program should show a window similar to the one in Figure 3.
|
257
|
255
|
|
258
|
256
|
---
|
259
|
257
|
|
|
@@ -263,7 +261,7 @@ In this exercise you will study the difference between pass by value and pass by
|
263
|
261
|
|
264
|
262
|
---
|
265
|
263
|
|
266
|
|
-4. Open the file `main.cpp` (in Sources). Study the `illustration` function and how to call it from the `main` function. Note that the variables `argValue` and `argRef`are initialized to 0 and that the function call for `illustration` makes a pass by value of `argValue` and a pass by reference of `argRef`. Also note that the corresponding parameters in `illustration` are assigned a value of 1.
|
|
264
|
+3. Open the file `main.cpp` (in Sources). Study the `illustration` function and how to call it from the `main` function. Note that the variables `argValue` and `argRef`are initialized to 0 and that the function call for `illustration` makes a pass by value of `argValue` and a pass by reference of `argRef`. Also note that the corresponding parameters in `illustration` are assigned a value of 1.
|
267
|
265
|
|
268
|
266
|
void illustration(int paramValue, int ¶mRef) {
|
269
|
267
|
paramValue = 1;
|
|
@@ -272,7 +270,7 @@ In this exercise you will study the difference between pass by value and pass by
|
272
|
270
|
<< "The content of paramRef is: " << paramRef << endl;
|
273
|
271
|
}
|
274
|
272
|
|
275
|
|
-5. 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.
|
|
273
|
+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
|
274
|
|
277
|
275
|
### Exercise 2
|
278
|
276
|
|