Przeglądaj źródła

Updates README-en.md

Auto commit by GitBook Editor
Rafael Arce Nazario 8 lat temu
rodzic
commit
e0314e92f4
1 zmienionych plików z 307 dodań i 307 usunięć
  1. 307
    307
      README-en.md

+ 307
- 307
README-en.md Wyświetl plik

@@ -1,307 +1,307 @@
1
-# Using functions in C++ - DVD Info
2
-
3
-
4
-![main1.png](images/main1.png)
5
-![main2.png](images/main2.png)
6
-![main3.png](images/main3.png)
7
-
8
-
9
-
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
-
12
-You've seen that all programs written in C++ must contain the `main` function where the program begins. You've probably already used functions such as `pow`, `sin`, `cos`, or `sqrt` from the `cmath` library. Since in almost all of the upcoming lab experiences you will continue using pre-defined functions, you need to understand how to work with them. In future exercises, you will learn how to design and validate functions. In this laboratory experience, you will search and display information contained in a DVD data base to practice declaring simple functions and calling pre-defined functions.
13
-
14
-
15
-##Objectives:
16
-
17
-1. Identify the parts of a function: return type, name, list of parameters, and body. 
18
-2. Call pre-defined functions by passing arguments by value ("pass by value"), and by reference ("pass by reference"). 
19
-3. Implement a simple function that utilizes parameters by reference.
20
-
21
-
22
-##Pre-Lab:
23
-
24
-Before you get to the laboratory you should have:
25
-
26
-1. Reviewed the following concepts:
27
-
28
-    a. the basic elements of a function definition in C++
29
-
30
-    b. how to call functions in C++
31
-
32
-    c. the difference between parameters that are passed by value and by reference
33
-
34
-    d. how to return the result of a function.
35
-
36
-2. Studied the concepts and instructions for the laboratory session.
37
-
38
-3. Taken the Pre-Lab quiz, available in Moodle.
39
-
40
----
41
-
42
----
43
-
44
-## Functions
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.
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.
49
-
50
-### Function header
51
-
52
-The first sentence of a function is called the *header* and its structure is as follows:
53
-
54
-`type name(type parameter01, ..., type parameter0n)`
55
-
56
-For example,
57
-
58
-```cpp
59
-int example(int var1, float var2, char &var3)
60
-```
61
-
62
-would be the header of the function called `example`, which returns an integer value. The function receives as arguments an integer value (and will store a copy in `var1`), a value of type `float` (and will store a copy in `var2`) and the reference to a variable of type `char` that will be stored in the reference variable `var3`. Note that `var3` has a & symbol before the name of the variable. This indicates that `var3` will contain the reference to a character.
63
-
64
-### Calling a function
65
-
66
-The following line assigns the value returned by the function `example` to an integer variable `x`:
67
-
68
-```cpp
69
-x = example(2, 3.5, unCar);
70
-```
71
-
72
-Note that when calling the function we don't include the type of the variables in the arguments as in the function's definition. The third parameter `&var3` is a reference variable. Thus, what is being sent to the third argument when calling the function is a *reference* to the variable `unCar`. Any assignments that are made to the variable `var3` will change the contents of the variable `unCar`.
73
-
74
-You can also use the function's result without having to store it in a variable. 
75
-
76
-The following line sends the return value of function `example` to the `cout` object, so that it is displayed in the terminal:
77
-
78
-```cpp
79
-cout << "The result of the function example is:" << example(2, 3.5, unCar);`
80
-```
81
-
82
-or use it in an arithmetic expression:
83
-
84
-```cpp
85
-y = 3 + example(2, 3.5, unCar);
86
-```
87
-
88
-
89
-### Overloaded Functions
90
-
91
-Overloaded functions are functions that have the same name, but different *signatures*. The signature of a function is composed of the name of the function and the types of parameters it receives. The signature does not include the return type.
92
-
93
-The following function prototypes have the **same signature**:
94
-
95
-```cpp
96
-int example(int, int) ;
97
-void example(int, int) ; 
98
-string example(int, int) ;
99
-```
100
-
101
-Note that each has the same name, `example`, and receives the same amount of parameters of the same type `(int, int)`.
102
-
103
-The following function prototypes have **different signatures**:
104
-
105
-```cpp
106
-int example(int) ;
107
-int elpmaxe(int) ;
108
-```
109
-
110
-Note that even though the functions have the same amount of parameters with the same type `int`, the name of the functions is different.
111
-
112
-The following function prototypes are overloaded versions of the function `example`:
113
-
114
-```cpp
115
-int example(int) ;
116
-void example(char) ;
117
-int example(int, int) ;
118
-int example(char, int) ;
119
-int example(int, char) ;
120
-```
121
-
122
-All of the above functions have the same name, `example`, but different parameters. The first and second functions have the same amount of parameters, but their arguments are of different types. The fourth and fifth functions have arguments of type `char` and `int`, but they have a different order in each case.
123
-
124
-In that last example, the function `example` is overloaded since there are five functions with different signatures but with the same name.
125
-
126
-
127
-### Default Values
128
-
129
-Values by default can be assigned to the parameters of the functions starting from the rightmost parameter. It is not necessary to initialize all of the parameters, but the ones that are initialized should be consecutive: parameters in between two parameters cannot be left uninitialized. This allows calling the function without having to send values in the positions that correspond to the initialized parameters.
130
-
131
-**Examples of Function Headers and Valid Function Calls:**
132
-
133
-1. **Header:** `int example(int var1, float var2, int var3 = 10)` Here `var3` is initialized to 10.
134
-
135
-    **Calls:**
136
-
137
-    a. `example(5, 3.3, 12)` This function call assigns the value 5 to `var1`, the value 3.3 to `var2`, and the value of 12 to `var3`.
138
-
139
-    b. `example(5, 3.3)` This function call sends the values for the first two parameters and the value for the last parameter will be the value assigned by default in the header. That is, the values in the variables in the function will be as follows: `var1` will be 5, `var2` will be 3.3, and `var3` will be 10.
140
-
141
-2. **Header:** `int example(int var1, float var2=5.0, int var3 = 10)`
142
-Here `var2` is initialized to 5 and `var3` to 10.
143
-
144
-    **Calls:**
145
-
146
-    a. `example(5, 3.3, 12)` This function call assigns the value 5 to `var1`, the value 3.3 to `var2`, and the value 12 to `var3`.
147
-
148
-    b. `example(5, 3.3)` In this function call only the first two parameters are given values, and the value for the last parameter is the value by default. That is, the value for `var1` within the function will be 5, that of `var2` will be 3.3, and `var3` will be 10.
149
-
150
-    c. `example(5)` In this function call only the first parameter is given a value, and the last two parameters will be assigned values by default. That is, `var1` will be 5, `var2` will be 5.0, and `var3` will be 10.
151
-
152
-
153
-**Example of a Valid Function Header with Invalid Function Calls:**
154
-
155
-1. **Header:** `int example(int var1, float var2=5.0, int var3 = 10)` 
156
-
157
-    **Invocation:**
158
-
159
-    a. `example(5, , 10)` This function call is **invalid** because it leaves an empty space in the middle argument.
160
-
161
-    b. `example()` This function call is **invalid** because `var1` was not assigned as a default value. A valid call to the function `example` needs at least one argument (the first). 
162
-
163
-**Examples of Invalid Function Headers:**
164
-
165
-1. `int example(int var1=1, float var2, int var3)` This header is invalid because the default values can only be assigned starting from the rightmost parameter.
166
-
167
-2. `int example(int var1=1, float var2, int var3=10)` This header is invalid because you can't place parameters without values between other parameters with default values. In this case, `var2` doesn't have a default value but `var1` and `var3` do.
168
-
169
----
170
-
171
----
172
-
173
-##DVD Movies and the DVD Data Base
174
-
175
-DVD stands for "digital versatile disk" or "digital video disk", which is an optical disc format for storing digital information invented by Philips, Sony, Toshiba, and Panasonic in 1995. The DVD offers larger storage capacity than compact disks (CD) but has the same dimensions. DVDs can be used to store any kind of digital data but they are mainly famous for their use in the distribution of movies.
176
-
177
-
178
----
179
-
180
----
181
-
182
-
183
-!INCLUDE "../../eip-diagnostic/DVD/en/diag-dvd-01.html"
184
-<br>
185
-
186
-!INCLUDE "../../eip-diagnostic/DVD/en/diag-dvd-03.html"
187
-<br>
188
-
189
-!INCLUDE "../../eip-diagnostic/DVD/en/diag-dvd-11.html"
190
-<br>
191
-
192
-!INCLUDE "../../eip-diagnostic/DVD/en/diag-dvd-12.html"
193
-<br>
194
-
195
-<br>
196
-
197
----
198
-
199
----
200
-
201
-
202
-
203
-## Laboratory Session:
204
-
205
-In this laboratory session we will be using a database of DVD movies maintained by [http://www.hometheaterinfo.com/dvdlist.htm](http://www.hometheaterinfo.com/dvdlist.htm). This database contains 44MB of information for movies that have been distributed in DVD. Some of the stored information in the database for each DVD is: DVD title, publishing studio, date of publication, type of sound, versions, price, rating, year and genre. The information for each movie is stored in the following format:
206
-
207
-```
208
-DVD_Title|Studio|Released|Status|Sound|Versions|Price|Rating|Year|Genre|Aspect|UPC|DVD_ReleaseDate|ID|Timestamp
209
-```
210
-
211
-For example, 
212
-
213
-```
214
-Airplane! (Paramount/ Blu-ray/ Checkpoint)|Paramount||Discontinued|5.1 DTS-HD|
215
-LBX, 16:9, BLU-RAY|21.99|PG|1980|Comedy|1.85:1|097361423524|2012-09-11 00:00:00|
216
-230375|2013-01-01 00:00:00
217
-```
218
-
219
-
220
-### Exercise 1 - Familiarize Yourself with the Defined Functions
221
-
222
-The first step in this laboratory experience is to familiarize yourself with the functions that are already defined in the code. Your tasks require that you imitate what the functions do, for this reason it is important that you understand how to call, declare and define the functions. 
223
-
224
-#### Instructions
225
-
226
-1. Load the project `DVDInfo` into `QtCreateor`. There are two wayss to do this: 
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. 
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. 
230
-
231
-2. Configure the project. The file `main.cpp` has the function calls that you will use in the next exercises. The declarations and definitions of the functions that will be called can be found in the files `movie.h` and `movie.cpp`.
232
-
233
-3. Double click on the file `movie.h` that contains this project's function prototypes. Go to `movie.h` and identify which functions are overloaded and describe why.
234
-    
235
-     Study the function prototypes and documentation in `movie.h` so that you understand the task they carry out and the data types they receive and return. For each of the following functions, identify the data types they receive and return:
236
-
237
-     ```
238
-     showMovie
239
-     showMovies (las dos)
240
-     getMovieName
241
-     getMovieByName
242
-     ```
243
-     
244
-     You can find the function definitions in the file `movie.cpp`. Note that some versions of the function `showMovie` use the object called `fields` of the `QStringList` class. The purpose of this object is to provide easy access to information fields of each movie, using an index between 0 and 14.  For example, you may use fields[0] to access a movie’s title, fields[1] to access a movie’s studio, fields[8] to access its year, and so forth.
245
-
246
----
247
-
248
-!INCLUDE "../../eip-diagnostic/DVD/en/diag-dvd-06.html"
249
-<br>
250
-
251
-
252
-### Exercise 2 - Call and Modify Functions
253
-
254
-In this exercise you will modify the `main` function and some of the pre-defined functions so that they display only certain movies from the database, display only part of the information, or display the information in a specific format.
255
-
256
-#### Instructions
257
-
258
-1. Perform the following implementations in the `main` function (in the `main.cpp` file):
259
-    * Add code so that the program displays the movies that have positions from 80 to 100.
260
-    * Add code so that the program displays only the movies that have “forrest gump” in the title.
261
-    * Add code so that the program displays only the movie in position 75125 using function composition and the function `showMovie`.
262
-    * Add code so that the program displays the name and the rating of the movie in position 75125.
263
-1. Modify the `getMovieInfo` function in the file `movie.cpp` so that it receives an additional parameter by reference where the name of the movie will be assigned. Remember that you must also modify the function's prototype in `movie.h`.
264
-1. Add the necessary code to the `main` function so that, using `getMovieInfo`, it displays the name, rating, year and the genre of the movie in position 75125 in one line. Hint: note that the function `getMovieInfo` has parameters that are passed by reference. 
265
-
266
-### Exercise 3 - Define and Implement Functions
267
-
268
-The functions whose prototypes are in `movie.h` are implemented in the file `movie.cpp`. In this exercise you will use the files `movie.h`, `movie.cpp`, and `main.cpp` to define and implement additional functions. As you implement these functions, remember to use good programming techniques and document your program.
269
-
270
-#### Instructions
271
-
272
-1. Study the functions that are already implemented in `movie.cpp` so that they may be used as examples for the functions you will create.
273
-
274
-2. Implement a function `getMovieStudio` that receives a string with the information of a movie and returns the name of the film's **studio**. Remember to add the function's prototype in the file `movie.h`. Invoke the function `getMovieStudio` in `main()` to display the name and studio of the movie in the position 75125 and demonstrate its functionality. 
275
-
276
-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.
277
-
278
-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. 
279
-
280
-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.
281
-
282
----
283
-
284
----
285
-
286
-## Deliverables
287
-
288
-Use "Deliverables" in Moodle to hand in the files `main.cpp`, `movie.cpp`, and `movie.h` with the function calls, changes, implementations and declarations that you made in Exercises 2 and 3. Remember to use good programming techniques, include the names of the programmers involved, and document your program.
289
-
290
-
291
-
292
----
293
-
294
----
295
-
296
-## References
297
-
298
-[1] http://mathbits.com/MathBits/CompSci/functions/UserDef.htm
299
-
300
-[2] http://www.digimad.es/autoria-dvd-duplicado-cd-video.html
301
-
302
-[3] http://www.soft32.com/blog/platforms/windows/keep-your-dvd-collection-up-to-date-with-emdb-erics-movie-database/
303
-
304
-[4] http://www.hometheaterinfo.com/dvdlist.htm
305
-
306
-
307
-
1
+# Using functions in C++ - DVD Info
2
+
3
+
4
+![main1.png](images/main1.png)
5
+![main2.png](images/main2.png)
6
+![main3.png](images/main3.png)
7
+
8
+
9
+
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
+
12
+You've seen that all programs written in C++ must contain the `main` function where the program begins. You've probably already used functions such as `pow`, `sin`, `cos`, or `sqrt` from the `cmath` library. Since in almost all of the upcoming lab experiences you will continue using pre-defined functions, you need to understand how to work with them. In future exercises, you will learn how to design and validate functions. In this laboratory experience, you will search and display information contained in a DVD data base to practice declaring simple functions and calling pre-defined functions.
13
+
14
+
15
+##Objectives:
16
+
17
+1. Identify the parts of a function: return type, name, list of parameters, and body. 
18
+2. Call pre-defined functions by passing arguments by value ("pass by value"), and by reference ("pass by reference"). 
19
+3. Implement a simple function that utilizes parameters by reference.
20
+
21
+
22
+##Pre-Lab:
23
+
24
+Before you get to the laboratory you should have:
25
+
26
+1. Reviewed the following concepts:
27
+
28
+    a. the basic elements of a function definition in C++
29
+
30
+    b. how to call functions in C++
31
+
32
+    c. the difference between parameters that are passed by value and by reference
33
+
34
+    d. how to return the result of a function.
35
+
36
+2. Studied the concepts and instructions for the laboratory session.
37
+
38
+3. Taken the Pre-Lab quiz, available in Moodle.
39
+
40
+---
41
+
42
+---
43
+
44
+## Functions
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.
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.
49
+
50
+### Function header
51
+
52
+The first sentence of a function is called the *header* and its structure is as follows:
53
+
54
+`type name(type parameter01, ..., type parameter0n)`
55
+
56
+For example,
57
+
58
+```cpp
59
+int example(int var1, float var2, char &var3)
60
+```
61
+
62
+would be the header of the function called `example`, which returns an integer value. The function receives as arguments an integer value (and will store a copy in `var1`), a value of type `float` (and will store a copy in `var2`) and the reference to a variable of type `char` that will be stored in the reference variable `var3`. Note that `var3` has a & symbol before the name of the variable. This indicates that `var3` will contain the reference to a character.
63
+
64
+### Calling a function
65
+
66
+The following line assigns the value returned by the function `example` to an integer variable `x`:
67
+
68
+```cpp
69
+x = example(2, 3.5, unCar);
70
+```
71
+
72
+Note that when calling the function we don't include the type of the variables in the arguments as in the function's definition. The third parameter `&var3` is a reference variable. Thus, what is being sent to the third argument when calling the function is a *reference* to the variable `unCar`. Any assignments that are made to the variable `var3` will change the contents of the variable `unCar`.
73
+
74
+You can also use the function's result without having to store it in a variable. 
75
+
76
+The following line sends the return value of function `example` to the `cout` object, so that it is displayed in the terminal:
77
+
78
+```cpp
79
+cout << "The result of the function example is:" << example(2, 3.5, unCar);`
80
+```
81
+
82
+or use it in an arithmetic expression:
83
+
84
+```cpp
85
+y = 3 + example(2, 3.5, unCar);
86
+```
87
+
88
+
89
+### Overloaded Functions
90
+
91
+Overloaded functions are functions that have the same name, but different *signatures*. The signature of a function is composed of the name of the function and the types of parameters it receives. The signature does not include the return type.
92
+
93
+The following function prototypes have the **same signature**:
94
+
95
+```cpp
96
+int example(int, int) ;
97
+void example(int, int) ; 
98
+string example(int, int) ;
99
+```
100
+
101
+Note that each has the same name, `example`, and receives the same amount of parameters of the same type `(int, int)`.
102
+
103
+The following function prototypes have **different signatures**:
104
+
105
+```cpp
106
+int example(int) ;
107
+int elpmaxe(int) ;
108
+```
109
+
110
+Note that even though the functions have the same amount of parameters with the same type `int`, the name of the functions is different.
111
+
112
+The following function prototypes are overloaded versions of the function `example`:
113
+
114
+```cpp
115
+int example(int) ;
116
+void example(char) ;
117
+int example(int, int) ;
118
+int example(char, int) ;
119
+int example(int, char) ;
120
+```
121
+
122
+All of the above functions have the same name, `example`, but different parameters. The first and second functions have the same amount of parameters, but their arguments are of different types. The fourth and fifth functions have arguments of type `char` and `int`, but they have a different order in each case.
123
+
124
+In that last example, the function `example` is overloaded since there are five functions with different signatures but with the same name.
125
+
126
+
127
+### Default Values
128
+
129
+Values by default can be assigned to the parameters of the functions starting from the rightmost parameter. It is not necessary to initialize all of the parameters, but the ones that are initialized should be consecutive: parameters in between two parameters cannot be left uninitialized. This allows calling the function without having to send values in the positions that correspond to the initialized parameters.
130
+
131
+**Examples of Function Headers and Valid Function Calls:**
132
+
133
+1. **Header:** `int example(int var1, float var2, int var3 = 10)` Here `var3` is initialized to 10.
134
+
135
+    **Calls:**
136
+
137
+    a. `example(5, 3.3f, 12)` This function call assigns the value 5 to `var1`, the value 3.3 to `var2`, and the value of 12 to `var3`.
138
+
139
+    b. `example(5, 3.3f)` This function call sends the values for the first two parameters and the value for the last parameter will be the value assigned by default in the header. That is, the values in the variables in the function will be as follows: `var1` will be 5, `var2` will be 3.3, and `var3` will be 10.
140
+
141
+2. **Header:** `int example(int var1, float var2 = 5.0f, int var3 = 10)`
142
+Here `var2` is initialized to 5 and `var3` to 10.
143
+
144
+    **Calls:**
145
+
146
+    a. `example(5, 3.3f, 12)` This function call assigns the value 5 to `var1`, the value 3.3 to `var2`, and the value 12 to `var3`.
147
+
148
+    b. `example(5, 3.3f)` In this function call only the first two parameters are given values, and the value for the last parameter is the value by default. That is, the value for `var1` within the function will be 5, that of `var2` will be 3.3, and `var3` will be 10.
149
+
150
+    c. `example(5)` In this function call only the first parameter is given a value, and the last two parameters will be assigned values by default. That is, `var1` will be 5, `var2` will be 5.0, and `var3` will be 10.
151
+
152
+
153
+**Example of a Valid Function Header with Invalid Function Calls:**
154
+
155
+1. **Header:** `int example(int var1, float var2 = 5.0f, int var3 = 10)` 
156
+
157
+    **Invocation:**
158
+
159
+    a. `example(5, , 10)` This function call is **invalid** because it leaves an empty space in the middle argument.
160
+
161
+    b. `example()` This function call is **invalid** because `var1` was not assigned as a default value. A valid call to the function `example` needs at least one argument (the first). 
162
+
163
+**Examples of Invalid Function Headers:**
164
+
165
+1. `int example(int var1=1, float var2, int var3)` This header is invalid because the default values can only be assigned starting from the rightmost parameter.
166
+
167
+2. `int example(int var1=1, float var2, int var3=10)` This header is invalid because you can't place parameters without values between other parameters with default values. In this case, `var2` doesn't have a default value but `var1` and `var3` do.
168
+
169
+---
170
+
171
+---
172
+
173
+##DVD Movies and the DVD Data Base
174
+
175
+DVD stands for "digital versatile disk" or "digital video disk", which is an optical disc format for storing digital information invented by Philips, Sony, Toshiba, and Panasonic in 1995. The DVD offers larger storage capacity than compact disks (CD) but has the same dimensions. DVDs can be used to store any kind of digital data but they are mainly famous for their use in the distribution of movies.
176
+
177
+
178
+---
179
+
180
+---
181
+
182
+
183
+!INCLUDE "../../eip-diagnostic/DVD/en/diag-dvd-01.html"
184
+<br>
185
+
186
+!INCLUDE "../../eip-diagnostic/DVD/en/diag-dvd-03.html"
187
+<br>
188
+
189
+!INCLUDE "../../eip-diagnostic/DVD/en/diag-dvd-11.html"
190
+<br>
191
+
192
+!INCLUDE "../../eip-diagnostic/DVD/en/diag-dvd-12.html"
193
+<br>
194
+
195
+<br>
196
+
197
+---
198
+
199
+---
200
+
201
+
202
+
203
+## Laboratory Session:
204
+
205
+In this laboratory session we will be using a database of DVD movies maintained by [http://www.hometheaterinfo.com/dvdlist.htm](http://www.hometheaterinfo.com/dvdlist.htm). This database contains 44MB of information for movies that have been distributed in DVD. Some of the stored information in the database for each DVD is: DVD title, publishing studio, date of publication, type of sound, versions, price, rating, year and genre. The information for each movie is stored in the following format:
206
+
207
+```
208
+DVD_Title|Studio|Released|Status|Sound|Versions|Price|Rating|Year|Genre|Aspect|UPC|DVD_ReleaseDate|ID|Timestamp
209
+```
210
+
211
+For example, 
212
+
213
+```
214
+Airplane! (Paramount/ Blu-ray/ Checkpoint)|Paramount||Discontinued|5.1 DTS-HD|
215
+LBX, 16:9, BLU-RAY|21.99|PG|1980|Comedy|1.85:1|097361423524|2012-09-11 00:00:00|
216
+230375|2013-01-01 00:00:00
217
+```
218
+
219
+
220
+### Exercise 1 - Familiarize Yourself with the Defined Functions
221
+
222
+The first step in this laboratory experience is to familiarize yourself with the functions that are already defined in the code. Your tasks require that you imitate what the functions do, for this reason it is important that you understand how to call, declare and define the functions. 
223
+
224
+#### Instructions
225
+
226
+1. Load the project `DVDInfo` into `QtCreateor`. There are two wayss to do this: 
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. 
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. 
230
+
231
+2. Configure the project. The file `main.cpp` has the function calls that you will use in the next exercises. The declarations and definitions of the functions that will be called can be found in the files `movie.h` and `movie.cpp`.
232
+
233
+3. Double click on the file `movie.h` that contains this project's function prototypes. Go to `movie.h` and identify which functions are overloaded and describe why.
234
+    
235
+     Study the function prototypes and documentation in `movie.h` so that you understand the task they carry out and the data types they receive and return. For each of the following functions, identify the data types they receive and return:
236
+
237
+     ```
238
+     showMovie
239
+     showMovies (las dos)
240
+     getMovieName
241
+     getMovieByName
242
+     ```
243
+     
244
+     You can find the function definitions in the file `movie.cpp`. Note that some versions of the function `showMovie` use the object called `fields` of the `QStringList` class. The purpose of this object is to provide easy access to information fields of each movie, using an index between 0 and 14.  For example, you may use fields[0] to access a movie’s title, fields[1] to access a movie’s studio, fields[8] to access its year, and so forth.
245
+
246
+---
247
+
248
+!INCLUDE "../../eip-diagnostic/DVD/en/diag-dvd-06.html"
249
+<br>
250
+
251
+
252
+### Exercise 2 - Call and Modify Functions
253
+
254
+In this exercise you will modify the `main` function and some of the pre-defined functions so that they display only certain movies from the database, display only part of the information, or display the information in a specific format.
255
+
256
+#### Instructions
257
+
258
+1. Perform the following implementations in the `main` function (in the `main.cpp` file):
259
+    * Add code so that the program displays the movies that have positions from 80 to 100.
260
+    * Add code so that the program displays only the movies that have “forrest gump” in the title.
261
+    * Add code so that the program displays only the movie in position 75125 using function composition and the function `showMovie`.
262
+    * Add code so that the program displays the name and the rating of the movie in position 75125.
263
+1. Modify the `getMovieInfo` function in the file `movie.cpp` so that it receives an additional parameter by reference where the name of the movie will be assigned. Remember that you must also modify the function's prototype in `movie.h`.
264
+1. Add the necessary code to the `main` function so that, using `getMovieInfo`, it displays the name, rating, year and the genre of the movie in position 75125 in one line. Hint: note that the function `getMovieInfo` has parameters that are passed by reference. 
265
+
266
+### Exercise 3 - Define and Implement Functions
267
+
268
+The functions whose prototypes are in `movie.h` are implemented in the file `movie.cpp`. In this exercise you will use the files `movie.h`, `movie.cpp`, and `main.cpp` to define and implement additional functions. As you implement these functions, remember to use good programming techniques and document your program.
269
+
270
+#### Instructions
271
+
272
+1. Study the functions that are already implemented in `movie.cpp` so that they may be used as examples for the functions you will create.
273
+
274
+2. Implement a function `getMovieStudio` that receives a string with the information of a movie and returns the name of the film's **studio**. Remember to add the function's prototype in the file `movie.h`. Invoke the function `getMovieStudio` in `main()` to display the name and studio of the movie in the position 75125 and demonstrate its functionality. 
275
+
276
+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.
277
+
278
+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. 
279
+
280
+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.
281
+
282
+---
283
+
284
+---
285
+
286
+## Deliverables
287
+
288
+Use "Deliverables" in Moodle to hand in the files `main.cpp`, `movie.cpp`, and `movie.h` with the function calls, changes, implementations and declarations that you made in Exercises 2 and 3. Remember to use good programming techniques, include the names of the programmers involved, and document your program.
289
+
290
+
291
+
292
+---
293
+
294
+---
295
+
296
+## References
297
+
298
+[1] http://mathbits.com/MathBits/CompSci/functions/UserDef.htm
299
+
300
+[2] http://www.digimad.es/autoria-dvd-duplicado-cd-video.html
301
+
302
+[3] http://www.soft32.com/blog/platforms/windows/keep-your-dvd-collection-up-to-date-with-emdb-erics-movie-database/
303
+
304
+[4] http://www.hometheaterinfo.com/dvdlist.htm
305
+
306
+
307
+