|
|
|
|
49
|
To facilitate this laboratory experience, we will begin by reviewing some concepts related to objects and we will describe the `Bird` class.
|
49
|
To facilitate this laboratory experience, we will begin by reviewing some concepts related to objects and we will describe the `Bird` class.
|
50
|
|
50
|
|
51
|
|
51
|
|
52
|
-##Classes and objects in C++
|
|
|
|
|
52
|
+##Classes and Objects in C++
|
53
|
|
53
|
|
54
|
An *object* is an entity that contains data and procedures to manipulate them. Similar to how each variable has a *type* of data associated to it, each object has a *class* associated to it, which describes the properties of the the objects: its data (*attributes*), and the procedures that can be used to manipulate its data (*methods*).
|
54
|
An *object* is an entity that contains data and procedures to manipulate them. Similar to how each variable has a *type* of data associated to it, each object has a *class* associated to it, which describes the properties of the the objects: its data (*attributes*), and the procedures that can be used to manipulate its data (*methods*).
|
55
|
|
55
|
|
|
|
|
|
101
|
|
101
|
|
102
|
By creating an object we have available the methods of the class that the object belongs to.
|
102
|
By creating an object we have available the methods of the class that the object belongs to.
|
103
|
|
103
|
|
104
|
-###Methods of a class
|
|
|
|
|
104
|
+###Methods of a Class
|
105
|
|
105
|
|
106
|
The methods of a class determine the actions that we can take on the objects of that class. The methods are similar to functions in the sense that they can receive parameters and return a result. An elementary way to know the methods of a class is reading the class declaration. For example, the following is a section of the declaration of the class `Bird` in the file `bird.h`.
|
106
|
The methods of a class determine the actions that we can take on the objects of that class. The methods are similar to functions in the sense that they can receive parameters and return a result. An elementary way to know the methods of a class is reading the class declaration. For example, the following is a section of the declaration of the class `Bird` in the file `bird.h`.
|
107
|
|
107
|
|
|
|
|
|
218
|
cout << piolin.getSize();
|
218
|
cout << piolin.getSize();
|
219
|
```
|
219
|
```
|
220
|
|
220
|
|
221
|
-#### Other functions or methods you will use in this laboratory experience
|
|
|
|
|
221
|
+#### Other Functions or Methods You will use in this Laboratory Experience
|
222
|
|
222
|
|
223
|
**MainWindow:** The file `mainwindow.h` contains the declaration of a class called `MainWindow`. The objects that are instances of this class will be able to use the overloaded methods
|
223
|
**MainWindow:** The file `mainwindow.h` contains the declaration of a class called `MainWindow`. The objects that are instances of this class will be able to use the overloaded methods
|
224
|
|
224
|
|
|
|
|
|
259
|
---
|
259
|
---
|
260
|
|
260
|
|
261
|
|
261
|
|
262
|
-## Laboratory session
|
|
|
|
|
262
|
+## Laboratory session:
|
263
|
|
263
|
|
264
|
-### Exercise 1 - Study the inheritance rules for the *Birds* family
|
|
|
|
|
264
|
+### Exercise 1 - Study the Inheritance Rules for the *Birds* Family
|
265
|
|
265
|
|
266
|
-#### The *Birds* family
|
|
|
|
|
266
|
+#### The *Birds* Family
|
267
|
|
267
|
|
268
|
Juana and Abelardo, mother and father birds, are about to have a baby they will call Piolín. As with real birds, the "Qt birds" expect their babies to have inherited attributes from their mother and father.
|
268
|
Juana and Abelardo, mother and father birds, are about to have a baby they will call Piolín. As with real birds, the "Qt birds" expect their babies to have inherited attributes from their mother and father.
|
269
|
|
269
|
|
270
|
When the laboratory experience is finished, your program will create two birds (Juana and Abelardo) with random characteristics and a third bird (Piolín), with characteristics determined by the parent's characteristics, following a set of rules similar to the rules of genetic inheritance.
|
270
|
When the laboratory experience is finished, your program will create two birds (Juana and Abelardo) with random characteristics and a third bird (Piolín), with characteristics determined by the parent's characteristics, following a set of rules similar to the rules of genetic inheritance.
|
271
|
|
271
|
|
272
|
|
272
|
|
273
|
-#### Inheritance rules
|
|
|
|
|
273
|
+#### Inheritance Rules
|
274
|
|
274
|
|
275
|
-**Eye color**
|
|
|
|
|
275
|
+**Eye Color**
|
276
|
|
276
|
|
277
|
The baby will always inherit the mother's eye color
|
277
|
The baby will always inherit the mother's eye color
|
278
|
|
278
|
|
|
|
|
|
280
|
|
280
|
|
281
|
The size of the bird is smallest between the mother's or father's size.
|
281
|
The size of the bird is smallest between the mother's or father's size.
|
282
|
|
282
|
|
283
|
-**Face color**
|
|
|
|
|
283
|
+**Face Color**
|
284
|
|
284
|
|
285
|
The gene dominance for the face color is given by the following list, ordered from color with most dominance color to color with least dominance:
|
285
|
The gene dominance for the face color is given by the following list, ordered from color with most dominance color to color with least dominance:
|
286
|
|
286
|
|
|
|
|
|
308
|
* In other cases, the baby will inherit the eyebrows with most dominance from the parent's eyebrows.
|
308
|
* In other cases, the baby will inherit the eyebrows with most dominance from the parent's eyebrows.
|
309
|
|
309
|
|
310
|
|
310
|
|
311
|
-### Exercise 2 - Study the `main` function
|
|
|
|
|
311
|
+### Exercise 2 - Study the `main` Function
|
312
|
|
312
|
|
313
|
-#### Instructions:
|
|
|
|
|
313
|
+#### Instructions
|
314
|
|
314
|
|
315
|
1. Load the project `BirthOfABird` into `QtCreator`. There are two ways to do this:
|
315
|
1. Load the project `BirthOfABird` into `QtCreator`. There are two ways to do this:
|
316
|
|
316
|
|
|
|
|
|
336
|
|
336
|
|
337
|
---
|
337
|
---
|
338
|
|
338
|
|
339
|
-### Exercise 3 - Write the code to determine Piolín's characteristics
|
|
|
|
|
339
|
+### Exercise 3 - Write the Code to determine Piolín's Characteristics
|
340
|
|
340
|
|
341
|
Study the header for the `birth` function. In this function, write the necessary code so baby Piolín has the characteristics dictated by the rules of inheritance exposed previously.
|
341
|
Study the header for the `birth` function. In this function, write the necessary code so baby Piolín has the characteristics dictated by the rules of inheritance exposed previously.
|
342
|
|
342
|
|