|
@@ -10,36 +10,38 @@ Up to now we've seen how to use variables to store and manipulate data of certai
|
10
|
10
|
|
11
|
11
|
|
12
|
12
|
|
13
|
|
-##Objectives:
|
|
13
|
+## Objectives:
|
14
|
14
|
|
15
|
15
|
1. Create objects from a class.
|
16
|
16
|
2. Analyze the declaration of a class to understand how to create and manipulate objects of the class.
|
17
|
17
|
3. Practice the creation and manipulation of objects, and the invocation of "setters" and "getters".
|
18
|
18
|
|
19
|
19
|
|
20
|
|
-##Pre-Lab:
|
|
20
|
+## Pre-Lab:
|
21
|
21
|
|
22
|
22
|
Before arriving to the laboratory you should have:
|
23
|
23
|
|
24
|
24
|
1. Reviewed the following concepts:
|
25
|
25
|
|
26
|
|
- a. the creation of objects of a class.
|
|
26
|
+ a. the creation of objects of a class.
|
27
|
27
|
|
28
|
|
- b. using the "getter" method functions to access the attributes of an object.
|
|
28
|
+ b. using the "getter" method functions to access the attributes of an object.
|
29
|
29
|
|
30
|
|
- c. using the "setter" method functions to modify the attributes of an object.
|
|
30
|
+ c. using the "setter" method functions to modify the attributes of an object.
|
31
|
31
|
|
32
|
32
|
2. Studied the documentation for the class `Bird` available in the documentation for this project (`objects-birds/doc/en/html/class_bird.html`).
|
33
|
33
|
|
34
|
34
|
3. Studied the concepts and instructions for the laboratory session.
|
35
|
35
|
|
|
36
|
+4. Taken the Pre-Lab quiz available in Moodle.
|
|
37
|
+
|
36
|
38
|
|
37
|
39
|
---
|
38
|
40
|
|
39
|
41
|
---
|
40
|
42
|
|
41
|
43
|
|
42
|
|
-##Classes and Objects in C++
|
|
44
|
+## Classes and Objects in C++
|
43
|
45
|
|
44
|
46
|
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*).
|
45
|
47
|
|
|
@@ -47,7 +49,7 @@ It is not necessary to know all of the details about the methods of the object t
|
47
|
49
|
|
48
|
50
|
Take a look at the documentation of the `Bird` class which can be found in [this link.](http://ada.uprrp.edu/~ranazario/bird-html/class_bird.html).
|
49
|
51
|
|
50
|
|
-###Classes
|
|
52
|
+### Classes
|
51
|
53
|
|
52
|
54
|
A class is a description of the data and processes of an object. The class’ declaration establishes the attributes that each of the objects of the class will have, and the methods that it can invoke.
|
53
|
55
|
|
|
@@ -83,7 +85,7 @@ The following is the skeleton of the declaration of a class:
|
83
|
85
|
|
84
|
86
|
You can see the declaration of the `Bird` class in the file `bird.h` included in this laboratory experience's program.
|
85
|
87
|
|
86
|
|
-###Objects
|
|
88
|
+### Objects
|
87
|
89
|
|
88
|
90
|
An object is an entity that contains data (same as a variable), called its `attributes`, and it also contains procedures, called `method`, that are used to manipulate them. The objects are "instances" of a class that are created in a similar manner as how variables are defined:
|
89
|
91
|
|
|
@@ -91,7 +93,7 @@ An object is an entity that contains data (same as a variable), called its `attr
|
91
|
93
|
|
92
|
94
|
By creating an object we have available the methods of the class that the object belongs to.
|
93
|
95
|
|
94
|
|
-###Methods of a Class
|
|
96
|
+### Methods of a Class
|
95
|
97
|
|
96
|
98
|
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`.
|
97
|
99
|
|