|
@@ -6,9 +6,9 @@
|
6
|
6
|
![main2.png](images/main2.png)
|
7
|
7
|
![main3.png](images/main3.png)
|
8
|
8
|
|
9
|
|
-[Verano 2016 - Ive]
|
|
9
|
+[Verano 2016 - Ive - Tatiana]
|
10
|
10
|
|
11
|
|
-Commonly, when solving a problem, there are one or more steps that depend on whether certain conditions are met. Computer programs are built to solve problems, so they should have a structure that allows them to make decisions. In C++ the decision instructions (or conditionals) are structured using `if`, `else`, `else if` or `switch`. Relational expressions and logical operators are common when handling decision structures. In today's laboratory experience you will practice the use of some decision structures by completing the design of a class called `Bird`. You will also review concepts related to objects.
|
|
11
|
+In almost every instance in which we want to solve a problem there are one or more options that depend on whether certain conditions are met. Computer programs are built to solve problems, therefore they should have a structure that allows them to make decisions. In C++, decision instructions (or conditionals) are structured using if, else, else if or switch. Relational expressions and logical operators are common when handling decision structures. In this laboratory experience, you will practice the use of some of these decision structures by completing a design using the class called Bird. In addition, you will review concepts related to objects.
|
12
|
12
|
|
13
|
13
|
## Objectives:
|
14
|
14
|
|
|
@@ -22,7 +22,7 @@ Commonly, when solving a problem, there are one or more steps that depend on whe
|
22
|
22
|
|
23
|
23
|
Before you get to the laboratory you should have:
|
24
|
24
|
|
25
|
|
-1. Reviewed the following concepts related to desition structures:
|
|
25
|
+1. Reviewed the following concepts related to decision structures:
|
26
|
26
|
|
27
|
27
|
a. Logical operators
|
28
|
28
|
|
|
@@ -30,7 +30,7 @@ Before you get to the laboratory you should have:
|
30
|
30
|
|
31
|
31
|
2. Reviewed the following concepts related to objects and classes in C++:
|
32
|
32
|
|
33
|
|
- a. creation of objects of a class.
|
|
33
|
+ a. the creation of objects of a class.
|
34
|
34
|
|
35
|
35
|
b. using the "getter" methods to access an object's attributes.
|
36
|
36
|
|
|
@@ -40,7 +40,7 @@ Before you get to the laboratory you should have:
|
40
|
40
|
|
41
|
41
|
4. Studied the concepts and instructions for this laboratory session.
|
42
|
42
|
|
43
|
|
-5. Taken the Pre-Lab quiz available in Moodle.
|
|
43
|
+5. Taken the Pre-Lab quiz, available in Moodle.
|
44
|
44
|
|
45
|
45
|
---
|
46
|
46
|
|
|
@@ -51,9 +51,9 @@ To facilitate this laboratory experience, we will begin by reviewing some concep
|
51
|
51
|
|
52
|
52
|
##Classes and objects in C++
|
53
|
53
|
|
54
|
|
-An *object* es 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 that describes the properties of 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
|
|
56
|
|
-To define and use an object it is not necessary to know all of the details about the methods of the object, but you must know how to create it and how to interact with it. The necessary information is available in the class' documentation. Before creating objects of any class we should familiarize ourselves with its documentation. The documentation indicates, among other things, what entity is trying to be represented in the class, and its interface or methods available to manipulate the objects of the class.
|
|
56
|
+It is not necessary to know all of the details about the methods of the object to define and use an object, but you must know how to create it and how to interact with it. The necessary information is available in the class' documentation. Before creating objects of any class, we should familiarize ourselves with its documentation. The documentation indicates, among other things, what entity is trying to be represented in the class, and its interface or methods available to manipulate the objects of the class.
|
57
|
57
|
|
58
|
58
|
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).
|
59
|
59
|
|
|
@@ -95,7 +95,7 @@ You can see the declaration of the `Bird` class in the file `bird.h` included in
|
95
|
95
|
|
96
|
96
|
###Objects
|
97
|
97
|
|
98
|
|
-An object is an entity that contains data (as well as a variable), called its `attributes`, and also contain 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:
|
|
98
|
+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:
|
99
|
99
|
|
100
|
100
|
`ClassName objectName;`
|
101
|
101
|
|
|
@@ -103,7 +103,7 @@ By creating an object we have available the methods of the class that the object
|
103
|
103
|
|
104
|
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 de 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
|
|
108
|
108
|
---
|
109
|
109
|
|
|
@@ -135,7 +135,7 @@ class Bird : public QWidget
|
135
|
135
|
|
136
|
136
|
---
|
137
|
137
|
|
138
|
|
-Once the object is created, its methods provide the only way to change its attributes, to obtain information about them, or to compute with them. This is why the set of methods is commonly called *interface*. The methods are the interface between the object’s user and its content.
|
|
138
|
+Once the object is created, its methods provide the only way to change its attributes, to obtain information about them, or to compute with them. This is why the set of methods is commonly called the *interface*. The methods are the interface between the object’s user and its content.
|
139
|
139
|
|
140
|
140
|
In general, in each class the prototypes of the methods are defined to construct the objects, and to search, manipulate and store the data. The following is a general format of a method prototype:
|
141
|
141
|
|
|
@@ -145,7 +145,7 @@ Afterwards, we write the corresponding function to the method in the project's c
|
145
|
145
|
|
146
|
146
|
`TypeReturned ClassName::MethodName(parameters)`
|
147
|
147
|
|
148
|
|
-We declare public methods within the class so that objects that are instances of a class have permission to access private variables (these are the setters and getters). It's prefered to use private variables and access them through the setters and getters, instead of declaring them public since the object that is associated to these variables has control over the changes that are made.
|
|
148
|
+We declare public methods within the class so that objects that are instances of a class have permission to access private variables (these are the setters and getters). It's preferred to use private variables and access them through the setters and getters, instead of declaring them public since the object that is associated to these variables would have control over the changes that are made.
|
149
|
149
|
|
150
|
150
|
To invoke a method we write the name of the object, followed by a period and then the name of the method:
|
151
|
151
|
|
|
@@ -154,7 +154,7 @@ To invoke a method we write the name of the object, followed by a period and the
|
154
|
154
|
|
155
|
155
|
#### Constructors
|
156
|
156
|
|
157
|
|
-The first methods of a class that we should understand are the *constructors*. A class can have multiple constructors. One of the constructors will be invoked automatically each time an object of that class is created. In most of the cases, the constructors are used to initialize the values for the object’s attributes. To create objects of a class, we must know which are the constructors of the class.
|
|
157
|
+The first methods of a class that we should understand are the *constructors*. A class can have multiple constructors. One of the constructors will be invoked automatically each time an object of that class is created. In most cases, the constructors are used to initialize the values for the object’s attributes. To create objects of a class, we must know which are the constructors of the class.
|
158
|
158
|
|
159
|
159
|
|
160
|
160
|
|
|
@@ -319,8 +319,6 @@ The genes in the eyebrows follow these rules:
|
319
|
319
|
|
320
|
320
|
2. Configure the project.
|
321
|
321
|
|
322
|
|
- **Important:** In the "Configure Project" window, select the configuration Qt 5.3 or Qt 5.4 clang 64 bit. If you use another configuration the project will not compile.
|
323
|
|
-
|
324
|
322
|
3. Compile and run the project. You should see a window with two birds that represent Juana and Abelardo. After a second, you will witness the birth of their baby, Piolín. Despite that, this Piolín could have been from another nest and not their son since it has random characteristics.
|
325
|
323
|
|
326
|
324
|
4. Open the file `main.cpp` (you will not make changes in any other file in this project). Study the `main` function. You will NOT make changes to the `main` function. Note that the `main` function essentially does two things:
|
|
@@ -372,3 +370,6 @@ https://sites.google.com/a/wellesley.edu/wellesley-cs118-spring13/lectures-labs/
|
372
|
370
|
|
373
|
371
|
|
374
|
372
|
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
|