|
|
|
|
4
|
![main2.png](images/main2.png)
|
4
|
![main2.png](images/main2.png)
|
5
|
![main4.png](images/main4.png)
|
5
|
![main4.png](images/main4.png)
|
6
|
|
6
|
|
7
|
-[verano 2016 - Coralys - Ive]
|
|
|
|
|
7
|
+[verano 2016 - Coralys - Ive - Coralys]
|
8
|
|
8
|
|
9
|
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 completing the code for a game in which a frog jumps from leaf to leaf.
|
9
|
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 completing the code for a game in which a frog jumps from leaf to leaf.
|
10
|
|
10
|
|
|
|
|
|
22
|
|
22
|
|
23
|
1. Reviewed the following concepts:
|
23
|
1. Reviewed the following concepts:
|
24
|
|
24
|
|
25
|
- a. Implementing arithmetic expressions in C++.
|
|
|
|
|
25
|
+ a. Implementing arithmetic expressions in C++
|
26
|
|
26
|
|
27
|
b. Basic data types in C++ (int, float, double)
|
27
|
b. Basic data types in C++ (int, float, double)
|
28
|
|
28
|
|
29
|
- c. Using "type casting" to cast the value of variables to other data types within expressions.
|
|
|
|
|
29
|
+ c. Using "type casting" to cast the value of variables to other data types within expressions
|
30
|
|
30
|
|
31
|
- d. Using arithmetic functions and constants from the `cmath` library.
|
|
|
|
|
31
|
+ d. Using arithmetic functions and constants from the `cmath` library
|
32
|
|
32
|
|
33
|
- e. Quadratic equations and their graphs.
|
|
|
|
|
33
|
+ e. Quadratic equations and their graphs
|
34
|
|
34
|
|
35
|
2. Studied the concepts and instructions for the laboratory session.
|
35
|
2. Studied the concepts and instructions for the laboratory session.
|
36
|
-3. Taken the Pre-Lab quiz available in Moodle.
|
|
|
|
|
36
|
+3. Taken the Pre-Lab quiz, available in Moodle.
|
37
|
|
37
|
|
38
|
|
38
|
|
39
|
|
39
|
|
|
|
|
|
63
|
|
63
|
|
64
|
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).
|
64
|
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).
|
65
|
|
65
|
|
66
|
-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
|
|
|
|
|
66
|
+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:
|
67
|
|
67
|
|
68
|
$$ x = x_1 $$
|
68
|
$$ x = x_1 $$
|
69
|
$$ x = x_2 $$
|
69
|
$$ x = x_2 $$
|
|
|
|
|
121
|
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.
|
121
|
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.
|
122
|
|
122
|
|
123
|
|
123
|
|
124
|
-**Instructions**
|
|
|
|
|
124
|
+#### Instructions
|
125
|
|
125
|
|
126
|
-1. Load the proyect `QuadraticFrog` into `QtCreator`. There are two ways to do this:
|
|
|
|
|
126
|
+1. Load the project `QuadraticFrog` into `QtCreator`. There are two ways to do this:
|
127
|
|
127
|
|
128
|
- * Using the virtual machine: Double click the file `QuadraticFrog.pro` that can be found in the `home/Documents/eip/Expressions-QuadraticFrog` of your virtual machine.
|
|
|
|
|
128
|
+ * Using the virtual machine: Double click the file `QuadraticFrog.pro` located in the folder `home/eip/labs/expressions-quadraticFrog` of your virtual machine.
|
129
|
|
129
|
|
130
|
- * Downloading the proyect's folder from `Bitbucket`: Use a terminal and write the command `git clone http://bitbucket.org/eip-uprrp/expressions-quadraticfrog` to download the folder `QuadraticFrog` from `Bitbucket`. Double click the file `QuadraticFrog.pro`located in the folder that you downloaded to your computer.
|
|
|
|
|
130
|
+ * Downloading the project's folder from `Bitbucket`: Use a terminal and write the command `git clone http://bitbucket.org/eip-uprrp/expressions-quadraticfrog` to download the folder `expressions-quadraticfrog` from `Bitbucket`. Double click the file `QuadraticFrog.pro`located in the folder that you downloaded to your computer.
|
131
|
|
131
|
|
132
|
-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.
|
|
|
|
|
132
|
+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, so this is why the message is displayed.
|
133
|
|
133
|
|
134
|
3. You will write the equations for the quadratic formula in the file `QuadraticFormula.cpp` (in `Sources`). In the function `QuadraticPlus` add the equation
|
134
|
3. You will write the equations for the quadratic formula in the file `QuadraticFormula.cpp` (in `Sources`). In the function `QuadraticPlus` add the equation
|
135
|
|
135
|
|
|
|
|
|
151
|
|
151
|
|
152
|
---
|
152
|
---
|
153
|
|
153
|
|
154
|
-5. To play, the frog should leap 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 $$a x^2 + b x + c = a(x-x_1)(x-x_2),$$ as in the explanation above.
|
|
|
|
|
154
|
+5. To play, the frog should leap 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 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 $$a x^2 + b x + c = a(x-x_1)(x-x_2),$$ as in the explanation above.
|
155
|
|
155
|
|
156
|
|
156
|
|
157
|
|
157
|
|
158
|
|
158
|
|
159
|
### Exercise 2 - Write a program to obtain a student's grade point average (GPA)
|
159
|
### Exercise 2 - Write a program to obtain a student's grade point average (GPA)
|
160
|
|
160
|
|
161
|
-Suppose that all courses in Yauco'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.
|
|
|
|
|
161
|
+Suppose that all courses in Yauco'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 and $$F = 0$$ points per credit.
|
162
|
|
162
|
|
163
|
-**Instructions**
|
|
|
|
|
163
|
+#### Instructions
|
164
|
|
164
|
|
165
|
-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).
|
|
|
|
|
165
|
+1. Start a new "Non-Qt" project called "Average". Your `main()` function will have 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).
|
166
|
|
166
|
|
167
|
-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.
|
|
|
|
|
167
|
+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.
|
168
|
|
168
|
|
169
|
**Hints:**
|
169
|
**Hints:**
|
170
|
|
170
|
|
|
|
|
|
180
|
|
180
|
|
181
|
## Deliverables
|
181
|
## Deliverables
|
182
|
|
182
|
|
183
|
-1. Use "Deliverable 1' in Moodle to submit the file `QuadraticFormula.cpp` containing the code with the functions `QuadraticPlus` and `QuadraticMinus`. Remember to use good programming practices, by including the names of the programmers and documenting your program.
|
|
|
|
|
183
|
+1. Use "Deliverable 1' in Moodle to submit the file `QuadraticFormula.cpp` containing the code with the functions `QuadraticPlus` and `QuadraticMinus`. Remember to use good programming practices, include the names of the programmers, and document your program.
|
184
|
|
184
|
|
185
|
-2. Use "Deliverable 2" to submit the file `main.cpp` with the code to compute grade average. 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.
|
|
|
|
|
185
|
+2. Use "Deliverable 2" to submit the file `main.cpp` with the code to compute the grade point average. 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.
|