Browse Source

Changes in the sources, updated README

Jose Ortiz 9 years ago
parent
commit
644f3c013e
1 changed files with 0 additions and 352 deletions
  1. 0
    352
      README.md

+ 0
- 352
README.md View File

@@ -1,352 +0,0 @@
1
-[English](#markdown-header-arithmetic-expressions-quadratic-frog) | [Español](#markdown-header-expresiones-aritmeticas-sapo-cuadratico)
2
-
3
-# Expresiones aritméticas - Sapo Cuadrático
4
-
5
-
6
-![main1.png](images/main1.png)
7
-![main2.png](images/main2.png)
8
-![main4.png](images/main4.png)
9
-
10
-
11
-Las expresiones aritméticas son parte esencial de casi cualquier algoritmo que resuelve un problema útil.  Por lo tanto,  implementar expresiones aritméticas correctamente es una destreza básica en cualquier lenguaje de programación de computadoras. En esta experiencia de laboratorio practicarás la implementación de expresiones aritméticas en C++ escribiendo ecuaciones para la fórmula cuadrática y así completar el código para  un juego en el que un sapito brinca de una hoja a otra.
12
-
13
-
14
-##Objetivos:
15
-
16
-1. Implementar expresiones aritméticas en C++ para definir la trayectoria del brinco de un sapito en un juego.
17
-2. Utilizar constantes adecuadamente.
18
-3. Definir variables utilizando tipos de datos adecuados.
19
-4. Convertir el valor de un dato a otro tipo cuando sea necesario.
20
-
21
-
22
-##Pre-Lab:
23
-
24
-Antes de llegar al laboratorio debes:
25
-
26
-1. Haber repasado los siguientes conceptos:
27
-
28
-    a. implementar expresiones aritméticas en C++
29
-
30
-    b. tipos de datos nativos de C++ (int, float, double, char)
31
-
32
-    c. usar "type casting" para covertir el valor de una variable a otro tipo dentro de expresiones.
33
-
34
-    d. utilizar funciones y constantes aritméticas de la biblioteca `cmath`
35
-
36
-    e. ecuaciones cuadráticas y sus gráficas.
37
-
38
-2. haber estudiado los conceptos e instrucciones para la sesión de laboratorio.
39
-
40
-3. haber tomado el quiz Pre-Lab que se encuentra en Moodle.
41
-
42
----
43
----
44
-
45
-
46
-
47
-##Fórmula cuadrática
48
-
49
-Una *ecuación cuadrática* tiene la forma 
50
-
51
-$$y = a x^2+ b x + c,$$
52
-
53
-donde $a, b, c$ son números reales y $a\not=0$. La gráfica de una ecuación cuadrática es una *parábola* que abre hacia arriba si $a > 0$ y abre hacia abajo si $a < 0$. 
54
-
55
-Una gráfica interseca el eje de $x$ cuando $y=0$. Por lo tanto, si una parábola interseca el eje de $x$, los intersectos están dados por las soluciones reales de la ecuación
56
-
57
-$$0 = a x^2 + b x + c.$$
58
-
59
-Las soluciones a la ecuación anterior se pueden obtener utilizando la *fórmula cuadrática*:
60
-
61
-$$x=\frac{-b±\sqrt{b^2-4ac}}{2a}.$$
62
-
63
-Nota que si el *discriminante*  $b^2-4ac$ de la fórmula cuadrática es negativo, los valores de $x$ serán números imaginarios y no se pueden graficar en el plano cartesiano porque los puntos $(x,y)$ en este plano tienen coordenadas que son números reales. Por lo tanto, si el discriminante es negativo, la parábola no interseca el eje de $x$. Si el discriminate es igual a $0$, entonces la parábola interseca el eje de $x$ en un solo punto (solo el vértice toca el eje de $x$).
64
-
65
-Si el discriminante es positivo, la fórmula cuadrática nos dá dos soluciones a la ecuación $0 = a x^2 + b x + c$ y estas soluciones son los intersectos en el eje de $x$. Por ejemplo, supón que la fórmula cuadrática nos dá dos valores 
66
-
67
-$$x=x_1$$
68
-$$x=x_2$$
69
-
70
-Entonces, 
71
-
72
-$$a x^2 + b x + c = a(x-x_1)(x-x_2),$$
73
-
74
-
75
-donde $x_1$ y $x_2$ son los cortes en el eje de $x$. Si $a<0$, la gráfica de la parábola será similar a la de la Figura 1.
76
-
77
----
78
-
79
-![parabola.png](images/parabola.png)
80
-
81
-<b>Figura 1.</b> Parábola que abre hacia abajo e interseca el eje de $x$ en $x_1$ y $x_2$.
82
-
83
-
84
----
85
-
86
-Nota que la ecuación
87
-
88
-$$y=-(x-x_1)(x-x_2)$$
89
-
90
-es una ecuación cuadrática cuya parábola abre hacia abajo e  interseca el eje de $x$ en  $x_1$ y $x_2$. Por ejemplo, la ecuación
91
-
92
-$$y=-(x+2)(x-3)=-x^2+x+6$$
93
-
94
-es una ecuación cuadrática cuya parábola abre hacia abajo e interseca el eje de $x$ en $x_1=-2$ y $x_2=3$. Nota que, en esta ecuación, los valores de $a,b,c$  son $a=-1, \ b=1, \ c=6$.
95
-
96
----
97
----
98
-
99
-##Sesión de laboratorio:
100
-
101
-###Ejercicio 1
102
-
103
-En este ejercicio implementarás la fórmula cuadrática para completar un juego en el que un sapito brinca de una hoja a otra. Asumirás que las hojas están localizadas sobre el eje de $x$ y que el brinco del sapito estará determinado por una parábola que abre hacia abajo. Si quieres que el sapito brinque de hoja a hoja, debes hayar una ecuación cuadrática cuya parábola abra hacia abajo e interseque el eje de $x$ en los lugares donde están localizadas las hojas. Tu tarea es escribir las ecuaciones para la fórmula cuadrática.
104
-
105
-
106
-
107
-**Instrucciones**
108
-
109
-1.   Carga a Qt el proyecto `QuadraticFrog`  haciendo doble "click" en el archivo `QuadraticFrog.pro` que se encuentra en la carpeta `Documents/eip/Expressions-QuadraticFrog` de tu computadora. También puedes ir a `http://bitbucket.org/eip-uprrp/quadraticfrog` para descargar la carpeta `QuadraticFrog` a tu computadora.
110
-
111
-2. Configura el proyecto y ejecuta el programa marcando la flecha verde en el menú de la izquierda de la ventana de Qt Creator. El programa te dará un mensaje que dice que la fórmula cuadrática está mal escrita. Esto sucede porque el programa tiene instrucciones que prueban el programa y verifican que la implementación del código esté correcta. Tu programa aún no tiene las instrucciones para evaluar la fórmula cuadrática y por esto sale el mensaje. 
112
-
113
-3. En el archivo `QuadraticFormula.cpp` (en `Sources`) escribirás las ecuaciones para la fórmula cuadrática. En la función `QuadraticPlus` añade la ecuación
114
-
115
-    $$result=\frac{-b+\sqrt{b^2-4ac}}{2a},$$
116
-
117
-    y en la función `QuadraticMinus` añade la ecuación
118
-
119
-    $$result=\frac{-b-\sqrt{b^2-4ac}}{2a}.$$
120
-
121
-    Los otros archivos del proyecto tienen código que hará pruebas a  las ecuaciones que escribiste evaluando varios valores para $a, b ,c$ y verificando que el resultado que producen las ecuaciones es el esperado.  La validación del código de un programa es una parte importante de el desarrollo de programas y proyectos.
122
-
123
-4. Ejecuta el programa marcando el botón verde en el menú de la izquierda. Si las ecuaciones que escribiste están correctas, deberá aparecer una ventana parecida a la Figura 2.
124
-
125
-    ---
126
-
127
-    ![figure2.png](images/figure2.png)
128
-
129
-    <b>Figura 2.</b> Ventana del juego *Quadratic Frog*.
130
-
131
-
132
-    ---
133
-
134
-
135
-5. Entrega el archivo `QuadraticFormula.cpp` que contiene las funciones las funciones `QuadraticPlus` y `QuadraticMinus` utilizando   "Entrega 1" en Moodle. Recuerda utilizar buenas prácticas de programación, incluir el nombre de los programadores y documentar tu programa.
136
-
137
-6. Para jugar, el sapito deberá brincar de una hoja a otra. Nota que las hojas tienen valores para $x_1$ y $x_2$. Estos valores representan los intercectos en el eje de $x$ de la parábola. Debes entrar los valores para los coeficientes $a,b,c$ de la ecuación cuadrática de modo que la gráfica sea una parábola que abra hacia abajo e interseque el eje de $x$ en los valores $x_1, x_2$ que salen en las hojas. Puedes obtener los valores de $a,b,c$ notando que 
138
-
139
- $$a x^2 + b x + c = a(x-x_1)(x-x_2),$$
140
-
141
- como en la explicación de arriba. 
142
-
143
-
144
-
145
-###Ejercicio 2
146
-
147
-En este ejercicio escribirás un  programa para obtener el promedio de puntos para la nota de un estudiante.
148
-
149
-Supón que todos los cursos en la Universidad de Yauco son de $3$ créditos y que las notas tienen las siguientes puntuaciones: $A = 4$ puntos por crédito; $B = 3$ puntos por crédito; $C = 2$ puntos por crédito; $D = 1$ punto por crédito y $F = 0$ puntos por crédito. 
150
-
151
-**Instrucciones**
152
-
153
-1. Crea un nuevo proyecto "Non-Qt" llamado Promedio. Tu función `main()`  contendrá el código necesario para pedirle al usuario el número de A's, B's, C's, D's y F's obtenidas por el estudiante y computar el promedio de puntos para la nota (GPA por sus siglas en inglés).
154
-
155
-2. Tu código debe definir las constantes $A=4, B=3, C=2, D=1, F=0$ para la puntuación de las notas, y pedirle al usuario que entre los valores para las variables $NumA$, $NumB$, $NumC$, $NumD$, $NumF$. La variable $NumA$ representará el número de cursos en los que el estudiante obtuvo $A$,  $NumB$ representará el número de cursos en los que el estudiante obtuvo $B$, etc. El programa debe desplegar el GPA del estudiante en una escala de 0 a 4 puntos. 
156
-
157
-
158
-
159
-    **Ayudas:** 
160
-
161
-    1. El promedio se obtiene sumando las puntuaciones  correspondientes a las notas obtenidas (por ejemplo, una A en un curso de 3 créditos tiene una puntuación de 12), y dividiendo esa suma por el número total de créditos.
162
-
163
-    2. Recuerda que, en C++, si divides dos números enteros el resultado se "truncará" y será un número entero. Utiliza "type casting": `static_cast\<tipo\>(expresión)' para resolver este problema.
164
-
165
-3. Verifica tu programa calculando el promedio de un estudiante que tenga dos A y dos B; ¿qué nota tendría este estudiante, A o B (la A va desde 3.5 a 4.0)?. Cuando tu programa esté correcto, guarda el archivo `main.cpp` y entrégalo  utilizando  "Entrega 2" en Moodle. Recuerda seguir las instrucciones en el uso de nombres y tipos para las variables,  incluir el nombre de los programadores, documentar tu programa y utilizar buenas prácticas de programación. 
166
-
167
-
168
----
169
----
170
----
171
-
172
-
173
-
174
-[English](#markdown-header-arithmetic-expressions-quadratic-frog) | [Español](#markdown-header-expresiones-aritmeticas-sapo-cuadratico)
175
-
176
-# Arithmetic Expressions - Quadratic Frog
177
-
178
-![main1.png](images/main1.png)
179
-![main2.png](images/main2.png)
180
-![main4.png](images/main4.png)
181
-
182
-
183
-Arithmetic expressions are an essential part of almost any algorithm that solves a useful problem. Therefore, a basic skill in any computer programming language is to implement arithmetic expressions correctly. In this laboratory experience you will practice the implementation of arithmetic expressions in C++ by writing equations for the quadratic formula and complete the code for a game in which a frog jumps from leaf to leaf.
184
-
185
-##Objectives:
186
-
187
-1. To implement arithmetic expressions in C++ to produce graphs. 
188
-2. To use constants adequately. 
189
-3. To define variables using adequate data types.
190
-4. To cast a data value to another type when necessary.
191
-
192
-
193
-##Pre-Lab:
194
-
195
-Before you get to the laboratory you should have:
196
-
197
-1. Reviewed the following concepts:
198
-
199
-    a. implementing arithmetic expressions in C++.
200
-
201
-    b. native data types in C++ (int, float, double)
202
-
203
-    c. using  "type casting" to cast the value of variables to other data types within expressions.
204
-
205
-    d. using arithmetic functions and constants from the `cmath` library.
206
-
207
-    e. quadratic equations and their graphs.
208
-
209
-2. Studied the concepts and instructions for the laboratory session.
210
-
211
-3. Taken the Pre-Lab quiz that can be found in Moodle.
212
-
213
-
214
-
215
----
216
----
217
-
218
-
219
-
220
-##Quadratic Formula
221
-
222
-A *quadratic equation* has a form 
223
-
224
-
225
-$$y = a x^2+ b x + c,$$
226
-
227
-where $a, b, c$ are real numbers and $a\not=0$. The graph of a quadratic equation is a *parabola* that opens up if $a > 0$ and opens dawn if $a < 0$.
228
-
229
-A graph intersects the $x$-axis when $y=0$. Therefore, if a parabola intersects the $x$-axis, the intersects are given by the real solutions to the equation
230
-
231
-
232
-
233
-$$0 = a x^2 + b x + c.$$
234
-
235
-The solutions to the previous equation can be obtained using the *quadratic formula*:
236
-
237
-
238
-
239
-$$x=\frac{-b±\sqrt{b^2-4ac}}{2a}.$$
240
-
241
-Note that if the *discriminant*   $b^2-4ac$ of the quadratic formula is negative, the values of $x$ are complex numbers and are not plotted in the Cartesian plane. Therefore, if the discriminant is negative, the parabola does not intersect the $x$-axis. If the discriminant is equal to $0$, then the parabola intersects the $x$-axis in only one point (only the vertex touches the $x$-axis).
242
-
243
-If the discriminant is positive, the quadratic formula gives two solutions to the equation $0 = a x^2 + b x + c$ and these solutions are the intersects in the $x$-axis. For example, suppose that the quadratic formula gives two values
244
-
245
-
246
-
247
-$$x=x_1$$
248
-$$x=x_2$$
249
-
250
-Then, 
251
-
252
-$$a x^2 + b x + c = a(x-x_1)(x-x_2),$$
253
-
254
-where $x_1$ and $x_2$ are the intersects in the $x$-axis. If $a<0$, the graph of the parabola will be similar to the one in Figure 1.
255
-
256
----
257
-
258
-![parabola.png](images/parabola.png)
259
-
260
-<b>Figure 1.</b> Parabola that opens down and intersects the $x$-axis in $x_1$ and $x_2$.
261
-
262
-
263
----
264
-
265
-Note that the equation
266
-
267
-
268
-$$y=-(x-x_1)(x-x_2)$$
269
-
270
-is a quadratic equation and its parabola opens down and intersects the $x$-axis in $x_1$ and $x_2$. For example, the equation
271
-
272
-
273
-$$y=-(x+2)(x-3)=-x^2+x+6$$
274
-
275
-is a quadratic equation with a parabola that opens down and intersects the $x$-axis at $x_1=-2$ and $x_2=3$. Note that, in this equation, the values for $a, b, c$ are  $a=-1, \ b=1, \ c=6$.
276
-
277
-
278
----
279
----
280
-
281
-##Laboratory session:
282
-
283
-###Exercise 1
284
-
285
-In this exercise you will implement the quadratic formula to complete a game in which a frog leaps from one leaf to another. You will assume that the leaves are in the $x$-axis and that the leap is determined by a parabola that opens down. If you want the frog to leap from leaf to leaf, you must find a quadratic equation with a parabola that opens down and intersects the $x$-axis in the places where the leaves are located. Your task is to write the equations for the quadratic formula.
286
-
287
-
288
-
289
-**Instructions**
290
-
291
-1.   Double click the file `QuadraticFrog.pro` that is contained in the `Documents/eip/Expressions-QuadraticFrog` folder to load the project `QuadraticFrog` into Qt. You can also download the folder `Expressions-QuadraticFrog` from  `http://bitbucket.org/eip-uprrp/expressions-quadraticfrog`.
292
-
293
-
294
-2. Configure the project and run the program by clicking the green arrow in the menu on the left side of the Qt Creator window. The program will display a message saying that the quadratic formula is wrong. This happens because the program has testing instructions that verify that the code implementation is correct. Your program is missing the code for the quadratic formula and this is why the message is displayed.
295
-
296
-3. You will write the equations for the quadratic formula in the file In the file  `QuadraticFormula.cpp` (in `Sources`). In the function  `QuadraticPlus` add the equation
297
-
298
-    $$result=\frac{-b+\sqrt{b^2-4ac}}{2a},$$
299
-
300
-    and in the function `QuadraticMinus` add the equation
301
-
302
-    $$result=\frac{-b-\sqrt{b^2-4ac}}{2a}.$$
303
-
304
-    The other files of the project have code that will test your equations by evaluating several choices for $a, b, c$ and verifying that the equations produce the expected result. Code validation is an important part of software development.
305
-
306
-
307
-4. Run the program by clicking the green arrow in the menu on the left side of the Qt Creator window. If your equations are implemented correclty, you should obtain a window similar to the one in Figure 2.
308
-
309
-    ---
310
-
311
-    ![figure2.png](images/figure2.png)
312
-
313
-    <b>Figure 2.</b> Window of the game *Quadratic Frog*.
314
-
315
-
316
-    ---
317
-
318
-
319
-5. Use "Deliver 1" in Moodle to submit the file  `QuadraticFormula.cpp` containing the code with the functions `QuadraticPlus` and `QuadraticMinus`. Remember to use good programming practices, to include the names of the programmers and to document your program.
320
-
321
-6. To play, the frog should leap jump from one leaf to another. Note that the leaves have values for $x_1$ and $x_2$. These values represent the intersects of the parabola with the $x$-axis. You should input the values for the coefficients $a, b, c$ of the quadratic equation so that its graph that is a parabola that opens down and intersects the $x$-axis in the values $x_1, x_2$ shown in the leaves. You can obtain these values noting that
322
-
323
-
324
- $$a x^2 + b x + c = a(x-x_1)(x-x_2),$$
325
-
326
- as in the explanation above. 
327
-
328
-
329
-
330
-
331
-###Exercise 2
332
-
333
-In this exercise you will write a program to obtain a student's grade point average (GPA).
334
-
335
-Suppose that all courses in Cheo's University are 3 credits each and have the following point values: $A = 4$ points per credit; $B = 3$ points per credit; $C = 2$ points per credit; $D = 1$ point per credit y $F = 0$ points per credit. 
336
-
337
-**Instructions**
338
-
339
-1. Start a new "Non-Qt" project called "Average". Your `main()` function will contain the necessary code to ask the user for the number of A's, B's, C's, D's and F's obtained and compute the grade point average (GPA).
340
-
341
-2. Your code should define the constants  $A=4, B=3, C=2, D=1, F=0$ for the points per credit, and ask the user to input the values for the variables  $NumA$, $NumB$, $NumC$, $NumD$, $NumF$. The variable $NumA$ represents the number of courses in which the student obtained A, $NumB$ represents the number of courses in which the student obtained B, etc. The program should display the GPA using the 0-4 point scale.
342
-
343
-    **Hints:** 
344
-
345
-    1. You can obtain the GPA by adding the credit points corresponding to the grades (for example, an A in a 3 credit course has a value of 12 points), and dividing this sum by the total number of credits.
346
-
347
-
348
-    2. Remember that, in C++, when both operands in the division are integers, the result will also be an integer; the remainder will be discarded. Use "type casting": `static_cast\<type\>(expression)' to solve this problem.
349
-
350
-3. Verify your program by computing the GPA of a student that has two A's and 2 B's; what is the grade of this student, A or B (A goes from 3.5 to 4 points)? When your program is correct, save the `main.cpp` file and submit it using "Deliver 2" in Moodle. Remember to follow the instructions regarding the names and types of the variables,  to include the names of the programmers, to document your program and to use good programming practices.
351
-
352
-