|
|
|
|
5
|

|
5
|

|
6
|

|
6
|

|
7
|
|
7
|
|
8
|
-[Verano 2016- Tatiana - Ive]
|
|
|
|
|
8
|
+[Verano 2016- Tatiana - Ive- Tatiana]
|
9
|
|
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.
|
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
|
|
|
|
|
|
77
|
|
77
|
|
78
|
|
78
|
|
79
|
|
79
|
|
80
|
-###Overloaded functions
|
|
|
|
|
80
|
+###Overloaded Functions
|
81
|
|
81
|
|
82
|
Overloaded functions are functions that have the same name, but a different *signature*.
|
82
|
Overloaded functions are functions that have the same name, but a different *signature*.
|
83
|
|
83
|
|
|
|
|
|
117
|
In that last example, the function `example` is overloaded since there are five functions with different signatures but with the same name.
|
117
|
In that last example, the function `example` is overloaded since there are five functions with different signatures but with the same name.
|
118
|
|
118
|
|
119
|
|
119
|
|
120
|
-### Default values
|
|
|
|
|
120
|
+### Default Values
|
121
|
|
121
|
|
122
|
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.
|
122
|
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.
|
123
|
|
123
|
|
124
|
-**Examples of function headers and valid function calls:**
|
|
|
|
|
124
|
+**Examples of Function Headers and Valid Function Calls:**
|
125
|
|
125
|
|
126
|
1. **Headers:** `int example(int var1, float var2, int var3 = 10)` Here `var3` is initialized to 10.
|
126
|
1. **Headers:** `int example(int var1, float var2, int var3 = 10)` Here `var3` is initialized to 10.
|
127
|
|
127
|
|
|
|
|
|
143
|
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.
|
143
|
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.
|
144
|
|
144
|
|
145
|
|
145
|
|
146
|
-**Example of a valid function header with invalid function calls:**
|
|
|
|
|
146
|
+**Example of a Valid Function Header with Invalid Function Calls:**
|
147
|
|
147
|
|
148
|
1. **Header:** `int example(int var1, float var2=5.0, int var3 = 10)`
|
148
|
1. **Header:** `int example(int var1, float var2=5.0, int var3 = 10)`
|
149
|
|
149
|
|
|
|
|
|
153
|
|
153
|
|
154
|
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).
|
154
|
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).
|
155
|
|
155
|
|
156
|
-**Examples of invalid function headers:**
|
|
|
|
|
156
|
+**Examples of Invalid Function Headers:**
|
157
|
|
157
|
|
158
|
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.
|
158
|
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.
|
159
|
|
159
|
|
|
|
|
|
163
|
|
163
|
|
164
|
---
|
164
|
---
|
165
|
|
165
|
|
166
|
-##DVD movies and the DVD data base
|
|
|
|
|
166
|
+##DVD Movies and the DVD Data Base
|
167
|
|
167
|
|
168
|
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 famous for their use in the distribution of movies.
|
168
|
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 famous for their use in the distribution of movies.
|
169
|
|
169
|
|
|
|
|
|
193
|
|
193
|
|
194
|
|
194
|
|
195
|
|
195
|
|
196
|
-## Laboratory session
|
|
|
|
|
196
|
+## Laboratory Session
|
197
|
|
197
|
|
198
|
In this laboratory session we will be using a data base of DVD movies maintained by 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 fields of the information for each movie are stored in text with the following format:
|
198
|
In this laboratory session we will be using a data base of DVD movies maintained by 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 fields of the information for each movie are stored in text with the following format:
|
199
|
|
199
|
|
|
|
|
|
206
|
```
|
206
|
```
|
207
|
|
207
|
|
208
|
|
208
|
|
209
|
-### Exercise 1 - Familiarize yourself with the defined functions
|
|
|
|
|
209
|
+### Exercise 1 - Familiarize Yourself with the Defined Functions
|
210
|
|
210
|
|
211
|
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.
|
211
|
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.
|
212
|
|
212
|
|
|
|
|
|
238
|
<br>
|
238
|
<br>
|
239
|
|
239
|
|
240
|
|
240
|
|
241
|
-### Exercise 2 - Call and modify functions
|
|
|
|
|
241
|
+### Exercise 2 - Call and Modify Functions
|
242
|
|
242
|
|
243
|
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.
|
243
|
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.
|
244
|
|
244
|
|
|
|
|
|
256
|
|
256
|
|
257
|
6. For the movie in part 3, 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 one line. Hint: note that the function `getMovieInfo` has parameters that are passed by reference.
|
257
|
6. For the movie in part 3, 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 one line. Hint: note that the function `getMovieInfo` has parameters that are passed by reference.
|
258
|
|
258
|
|
259
|
-### Exercise 3 - Define and implement functions
|
|
|
|
|
259
|
+### Exercise 3 - Define and Implement Functions
|
260
|
|
260
|
|
261
|
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.
|
261
|
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.
|
262
|
|
262
|
|
263
|
-**Instructions**
|
|
|
|
|
263
|
+#### Instructions
|
264
|
|
264
|
|
265
|
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.
|
265
|
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.
|
266
|
|
266
|
|
|
|
|
|
286
|
|
286
|
|
287
|
---
|
287
|
---
|
288
|
|
288
|
|
289
|
-##References
|
|
|
|
|
289
|
+## References
|
290
|
|
290
|
|
291
|
[1] http://mathbits.com/MathBits/CompSci/functions/UserDef.htm
|
291
|
[1] http://mathbits.com/MathBits/CompSci/functions/UserDef.htm
|
292
|
|
292
|
|