|
@@ -6,13 +6,11 @@
|
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
|
|
-*Object Oriented Programming* (OOP) is a programming paradigm that promotes the design of programs by having different objects interacting together to solve a problem. C++ is one of the programming languages that promotes object oriented programming, allowing programmers to create their own classes from scratch or derive them from other existing classes. Other languages that promote OOP are Java, Python, Javascript and PHP.
|
12
|
|
-
|
13
|
|
-In OOP, each object encapsulates within itself certain properties about the entity being modeled (for example, an object that models a *point* encapsulates the coordinates *x* and *y* of the point being represented). Furthermore, each object allows certain actions to be carried out on itself with the *methods* that the object contains. For example, an object of class *point* could carry out the action of changing the value of the *x* coordinate.
|
14
|
|
-
|
15
|
|
-When an object class we need to use in our program has not been predefined in a library, we need to declare and implement our own class. To do this, we define *classes* that contain data with certain *properties* or *attributes* and actions that we want to carry out with this data through the use of *methods* or *member functions*. This way, we can organize the information and processes in *objects* that have the properties and methods of a class. In today's laboratory experience you will practice defining a class and implementing some of its methods by completing a program that simulates a basketball game between two players, maintaining the score for the game and the global statistics for the two players.
|
|
11
|
+Object Oriented Programming (OOP) is a programming paradigm that promotes the design of programs by having different objects interacting together to solve a problem. C++ is one of the programming languages that promotes object oriented programming, allowing programmers to create their own classes from scratch or derive them from other existing classes. Other languages that promote OOP are Java, Python, JavaScript and PHP.
|
|
12
|
+In OOP, each object encapsulates within itself certain properties about the entity being modeled. For example, an object that models a point encapsulates the coordinates x and y of the point being represented. Furthermore, each object allows certain actions to be carried out on itself with the methods that the object contains. For example, an object of class point could carry out the action of changing the value of the x coordinate.
|
|
13
|
+When an object class we need to use in our program has not been predefined in a library, we need to declare and implement our own class. To do this, we define classes that contain data with certain properties or attributes, and actions that we want to carry out with this data through the use of methods or member functions. This way, we can organize the information and processes in objects that have the properties and methods of a class. In today's laboratory experience, you will practice defining a class and implementing some of its methods by completing a program that simulates a basketball game between two players, maintaining the score for the game and the global statistics for the two players.
|
16
|
14
|
|
17
|
15
|
|
18
|
16
|
## Objectives:
|
|
@@ -26,14 +24,13 @@ When an object class we need to use in our program has not been predefined in a
|
26
|
24
|
|
27
|
25
|
Before coming to the laboratory you should have:
|
28
|
26
|
|
29
|
|
-
|
30
|
27
|
1. Reviewed the concepts related to classes and objects.
|
31
|
28
|
|
32
|
29
|
2. Studied the skeleton for the program in `main.cpp`.
|
33
|
30
|
|
34
|
31
|
3. Studied the concepts and instructions for the laboratory session.
|
35
|
32
|
|
36
|
|
-4. Taken the Pre-Lab quiz available in Moodle.
|
|
33
|
+4. Taken the Pre-Lab quiz, available in Moodle.
|
37
|
34
|
|
38
|
35
|
---
|
39
|
36
|
|
|
@@ -41,12 +38,12 @@ Before coming to the laboratory you should have:
|
41
|
38
|
|
42
|
39
|
## The Game
|
43
|
40
|
|
44
|
|
-The skeleton for the program that we provide simulates a basketball game between two players. The successful throws into the basket receive two points. The data is initiated with the name of each player and the global statistics in the "tournament": total of games played, attempted throws, successful throws and rebounds. The program includes random functions and formulas to determine the player that attempts a throw, if the player scores, and the player that takes the rebound. During the simulated game the score for each player is kept and each player's data is updated. At the end of the game, a table with the statistics is displayed.
|
|
41
|
+The skeleton for the program that we provide simulates a basketball game between two players. The successful throws into the basket receive two points. The data is initiated with the name of each player and the global statistics in the "tournament": total of games played, attempted throws, successful throws and rebounds. The program includes random functions and formulas to determine the player that attempts a throw, if the player scores, and the player that takes the rebound. During the simulated game the score for each player is kept and each player's data is updated. At the end of the game, a table with the statistics is displayed.
|
45
|
42
|
|
46
|
43
|
The algorithm that simulates the game is the following:
|
47
|
44
|
|
48
|
45
|
```
|
49
|
|
-1. init the player
|
|
46
|
+1. initialize the player
|
50
|
47
|
2. assign jugadorEnOfensiva randomly
|
51
|
48
|
3. while (none has won)
|
52
|
49
|
4. simulate a shot to the basket
|
|
@@ -60,7 +57,7 @@ The algorithm that simulates the game is the following:
|
60
|
57
|
12. update statistics of the player that shot the basket
|
61
|
58
|
13. determine who gets the rebound
|
62
|
59
|
14. update the statistics of the player that got the rebound
|
63
|
|
-15. assign a pleyer in offense (jugadorEnOfensiva)
|
|
60
|
+15. assign a player in offense (jugadorEnOfensiva)
|
64
|
61
|
16. show the players statistics
|
65
|
62
|
```
|
66
|
63
|
|
|
@@ -84,11 +81,11 @@ For this laboratory experience, you will define the `BBPlayer` class that contai
|
84
|
81
|
#### Methods
|
85
|
82
|
|
86
|
83
|
* default constructor. *(method included in `main.cpp`)*
|
87
|
|
-* `setAll()`: methods that assigns an initial value to all of the attributes of the object. Notice that this method is invoked at the beginning of `main` to assign initial values to the array `P` that is an array of two objects of the `BBPlayer` class.
|
|
84
|
+* `setAll()`: method that assigns an initial value to all of the attributes of the object. Notice that this method is invoked at the beginning of `main` to assign initial values to the array `P` that is an array of two objects of the `BBPlayer` class.
|
88
|
85
|
* `name()`: method to acquire the name of the player.
|
89
|
86
|
* `shotPercentage()`: method to compute the percent of throws scored; is used to determine if the attempted throw is scored by a player. *(method included in `main.cpp`)*
|
90
|
87
|
* `reboundsPerGame()`: method to compute the average number of rebounds caught by a player; is used to determine if the player successfully catches the rebound. *(method included in `main.cpp`)*
|
91
|
|
-* 'shotMade()': method that registers that a shot was scored, that a shot was attempted, and updates the score for the player.
|
|
88
|
+* `shotMade()`: method that registers that a shot was scored, that a shot was attempted, and updates the score for the player.
|
92
|
89
|
* `shotMissed()`: method that registers an attempted throw (but unsuccessful).
|
93
|
90
|
* `reboundMade()`: method that registers that a rebound was caught.
|
94
|
91
|
* `addGame()`: method that registers that a game was played.
|
|
@@ -111,9 +108,9 @@ For this laboratory experience, you will define the `BBPlayer` class that contai
|
111
|
108
|
|
112
|
109
|
## Laboratory Session:
|
113
|
110
|
|
114
|
|
-In this laboratory experience, your task will be to define the `BBPlayer` class with the attributes and method prototypes listed above. The skeleton for the program includes the code to define some of the methods; others will have to be defined.
|
|
111
|
+In this laboratory experience, your task will be to define the `BBPlayer` class with the attributes and method prototypes listed above. The skeleton for the program includes the code to define some of the methods; others you will have to be define.
|
115
|
112
|
|
116
|
|
-The skeleton for the program also includes the `test_BBPlayer` function that does unit tests to each of the functions in the program. The tests are commented and, as you define each function, you will remove the comment, test and modify the function, until the test for that function is passed. Once all of the functions are ready and have passed the tests, the whole program is tested by removing the necessary comments in the `main` function.
|
|
113
|
+The skeleton for the program also includes the `test_BBPlayer` function that does unit tests to each of the functions in the program. The tests are commented and, as you define each function, you will remove the comments, test and modify the function, until the test for that function is passed. Once all of the functions are ready and have passed the tests, the whole program is tested by removing the necessary comments in the `main` function.
|
117
|
114
|
|
118
|
115
|
|
119
|
116
|
### Exercise 1 - Download and understand the provided code
|
|
@@ -192,3 +189,6 @@ Use "Deliverable" in Moodle to hand in the `main.cpp` file. Remember to use good
|
192
|
189
|
[2] http://www.musthavemenus.com/category/bar-clipart.html
|
193
|
190
|
|
194
|
191
|
[3] http://basketball.isport.com/basketball-guides/finding-your-niche-in-basketball
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|