|
|
|
|
43
|
|
43
|
|
44
|
## Functions
|
44
|
## Functions
|
45
|
|
45
|
|
46
|
-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 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.
|
|
|
|
|
46
|
+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 only have 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.
|
47
|
|
47
|
|
48
|
Functions in programming languages are similar. A function has a series of instructions that take the assigned values as parameters and performs 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 returns a value, we use the instruction `return`. As in math, you need to specify the types of values that the function's parameters and result will have; this is done when declaring the function.
|
48
|
Functions in programming languages are similar. A function has a series of instructions that take the assigned values as parameters and performs 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 returns a value, we use the instruction `return`. As in math, you need to specify the types of values that the function's parameters and result will have; this is done when declaring the function.
|
49
|
|
49
|
|
|
|
|
|
223
|
|
223
|
|
224
|
#### Instructions
|
224
|
#### Instructions
|
225
|
|
225
|
|
226
|
-1. Load the project `DVDInfo` into `QtCreateor`. There are two wayss to do this:
|
|
|
|
|
226
|
+1. Load the project `DVDInfo` into `QtCreateor`. There are two ways to do this:
|
227
|
|
227
|
|
228
|
* Using the virtual machine: Double click the file `DVDInfo.pro` located in the folder `home/eip/labs/functions-dvdinfo` of your virtual machine.
|
228
|
* Using the virtual machine: Double click the file `DVDInfo.pro` located in the folder `home/eip/labs/functions-dvdinfo` of your virtual machine.
|
229
|
* Downloading the project's folder from `Bitbucket`: Use a terminal and write the command `git clone http://bitbucket.org/eip-uprrp/functions-dvdinfo` to download the folder `functions-dvdinfo` from `Bitbucket`. Double click the file `DVDInfo.pro` located in the folder that you downloaded to your computer.
|
229
|
* Downloading the project's folder from `Bitbucket`: Use a terminal and write the command `git clone http://bitbucket.org/eip-uprrp/functions-dvdinfo` to download the folder `functions-dvdinfo` from `Bitbucket`. Double click the file `DVDInfo.pro` located in the folder that you downloaded to your computer.
|
|
|
|
|
236
|
|
236
|
|
237
|
```
|
237
|
```
|
238
|
showMovie
|
238
|
showMovie
|
239
|
- showMovies (las dos)
|
|
|
|
|
239
|
+ showMovies
|
240
|
getMovieName
|
240
|
getMovieName
|
241
|
getMovieByName
|
241
|
getMovieByName
|
242
|
```
|
242
|
```
|
|
|
|
|
290
|
|
290
|
|
291
|
3. Implement an overloaded function `getMovieInfo` that returns the name of the studio as well as the name, rating, year and genre. Call the function `getMovieInfo` in `main()` to display the name, studio, rating, year and genre of the movie in the position 75125 and demonstrate its functionality.
|
291
|
3. Implement an overloaded function `getMovieInfo` that returns the name of the studio as well as the name, rating, year and genre. Call the function `getMovieInfo` in `main()` to display the name, studio, rating, year and genre of the movie in the position 75125 and demonstrate its functionality.
|
292
|
|
292
|
|
293
|
-4. Implement a function `showMovieInLine` that **displays** the information the information displayed by `showMovie`, but in a single line. The function should have a parameter to receive a string of information of the movie. Call the function `showMovieInLine` in `main()` to display the information for the movie in position 75125 to demonstrate its functionality.
|
|
|
|
|
293
|
+4. Implement a function `showMovieInLine` that **displays** the information displayed by `showMovie`, but in a single line. The function should have a parameter to receive a string of information of the movie. Call the function `showMovieInLine` in `main()` to display the information for the movie in position 75125 to demonstrate its functionality.
|
294
|
|
294
|
|
295
|
5. Implement a function `showMoviesInLine` that **displays** the same information displayed by `showMovies` (all of the movies within a range of positions) but in a single line per movie. For example, a function call would be: `showMoviesInLine(file, 148995, 149000);`. Call the function `showMoviesInLine` in `main()` to display the information and demonstrate its functionality.
|
295
|
5. Implement a function `showMoviesInLine` that **displays** the same information displayed by `showMovies` (all of the movies within a range of positions) but in a single line per movie. For example, a function call would be: `showMoviesInLine(file, 148995, 149000);`. Call the function `showMoviesInLine` in `main()` to display the information and demonstrate its functionality.
|
296
|
|
296
|
|
|
|
|
|
312
|
|
312
|
|
313
|
[1] http://mathbits.com/MathBits/CompSci/functions/UserDef.htm
|
313
|
[1] http://mathbits.com/MathBits/CompSci/functions/UserDef.htm
|
314
|
|
314
|
|
315
|
-[2] http://www.digimad.es/autoria-dvd-duplicado-cd-video.html
|
|
|
|
|
315
|
+[2] http://www.digimad.es/autoria-bluray-dvd-duplicado-cd-video.html
|
316
|
|
316
|
|
317
|
[3] http://www.soft32.com/blog/platforms/windows/keep-your-dvd-collection-up-to-date-with-emdb-erics-movie-database/
|
317
|
[3] http://www.soft32.com/blog/platforms/windows/keep-your-dvd-collection-up-to-date-with-emdb-erics-movie-database/
|
318
|
|
318
|
|