|
@@ -5,16 +5,16 @@
|
5
|
5
|
![rsz_mariposa.png](images/rsz_mariposa.png)
|
6
|
6
|
|
7
|
7
|
|
8
|
|
-[Verano 2016 - Ive - Rafa]
|
|
8
|
+[Verano 2016 - Ive - Rafa - Coralys]
|
9
|
9
|
|
10
|
10
|
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 parametric equations to plot interesting curves.
|
11
|
11
|
|
12
|
12
|
## Objectives:
|
13
|
13
|
|
14
|
|
-1. To implement arithmetic expressions in C++ to produce graphs.
|
15
|
|
-2. To use constants adequately.
|
16
|
|
-3. To define variables using adequate data types.
|
17
|
|
-4. To cast a data value to another type when necessary.
|
|
14
|
+1. Implement arithmetic expressions in C++ to produce graphs.
|
|
15
|
+2. Use constants adequately.
|
|
16
|
+3. Define variables using adequate data types.
|
|
17
|
+4. Cast a data value to another type when necessary.
|
18
|
18
|
|
19
|
19
|
|
20
|
20
|
## Pre-Lab:
|
|
@@ -23,17 +23,17 @@ Before you get to the laboratory you should have:
|
23
|
23
|
|
24
|
24
|
1. Reviewed the following concepts:
|
25
|
25
|
|
26
|
|
- a. implementing arithmetic expressions in C++.
|
|
26
|
+ a. Implementing arithmetic expressions in C++
|
27
|
27
|
|
28
|
|
- b. native data types in C++ (int, float, double)
|
|
28
|
+ b. Basic data types in C++ (int, float, double)
|
29
|
29
|
|
30
|
|
- c. using "type casting" to cast the value of variables to other data types within expressions.
|
|
30
|
+ c. Using "type casting" to cast the value of variables to other data types within expressions
|
31
|
31
|
|
32
|
|
- d. using arithmetic functions and constants from the `cmath` library.
|
|
32
|
+ d. Using arithmetic functions and constants from the `cmath` library
|
33
|
33
|
|
34
|
|
- e. the equation and graph of a circle.
|
|
34
|
+ e. The equation and graph of a circle.
|
35
|
35
|
|
36
|
|
-2. Studied the concepts and instructions for the laboratory session.
|
|
36
|
+2. Studied the concepts and instructions for the laboratory session
|
37
|
37
|
|
38
|
38
|
3. Taken the Pre-Lab quiz, available in Moodle.
|
39
|
39
|
|
|
@@ -44,12 +44,12 @@ Before you get to the laboratory you should have:
|
44
|
44
|
|
45
|
45
|
## Parametric Equations
|
46
|
46
|
|
47
|
|
-*Parametric equations* allow us to represent a quantity as a function of one or more independent variables called *parameters*. In many occasions it is useful to represent curves using a set of parametric equations that express the coordinates of the points of the curve as functions of the parameters. For example, in your trigonometry course you should have studied that the equation of the circle of radius $$r$$ and centered at the origin has the following form:
|
|
47
|
+*Parametric equations* allow us to represent a quantity as a function of one or more independent variables called *parameters*. In many occasions it is useful to represent curves using a set of parametric equations that express the coordinates of the points of the curve as functions of the parameters. For example, in your trigonometry course you should have studied that the equation of the circle of radius $$r$$, and centered at the origin has the following form:
|
48
|
48
|
|
49
|
49
|
|
50
|
50
|
$$x^2+y^2=r^2.$$
|
51
|
51
|
|
52
|
|
-The points $$(x,y)$$ that satisfy this equation are the points that form the circle of radius $$r$$ and center at the origin. For example, the circle with $$r=2$$ and center at the origin has equation
|
|
52
|
+The points $$(x,y)$$ that satisfy this equation are the points that form the circle of radius $$r$$ and center at the origin. For example, the circle with $$r=2$$ and center at the origin has the equation
|
53
|
53
|
|
54
|
54
|
|
55
|
55
|
$$x^2+y^2=4,$$
|
|
@@ -62,7 +62,7 @@ $$x=r \cos(t)$$
|
62
|
62
|
|
63
|
63
|
$$y=r \sin(t),$$
|
64
|
64
|
|
65
|
|
-where $$t$$ is a parameter that corresponds to the measure (in radians) of the positive angle with initial side that coincides with the positive part of the $$x$$-axis and terminal side that contains the point $$(x,y)$$, as illustrated in Figure 1.
|
|
65
|
+where $$t$$ is a parameter that corresponds to the measure (in radians) of the positive angle with initial side that coincides with the positive part of the $$x$$-axis and the terminal side that contains the point $$(x,y)$$, as illustrated in Figure 1.
|
66
|
66
|
|
67
|
67
|
|
68
|
68
|
---
|
|
@@ -75,7 +75,7 @@ where $$t$$ is a parameter that corresponds to the measure (in radians) of the p
|
75
|
75
|
|
76
|
76
|
---
|
77
|
77
|
|
78
|
|
-To plot a curve that is described by parametric equations, we compute the $$x$$ and $$y$$ values for a set of values of the parameter. For example, Figure 2 shows the $$t$$, $$x$$ y $$y$$ values for some of the points in the circle with $$r = 2$$.
|
|
78
|
+To plot a curve that is described by parametric equations, we compute the $$x$$ and $$y$$ values for a set of values of the parameter. For example, Figure 2 shows the $$t$$, $$x$$ and $$y$$ values for some of the points in the circle with $$r = 2$$.
|
79
|
79
|
|
80
|
80
|
|
81
|
81
|
---
|
|
@@ -120,12 +120,12 @@ To plot a curve that is described by parametric equations, we compute the $$x$$
|
120
|
120
|
|
121
|
121
|
## Laboratory session:
|
122
|
122
|
|
123
|
|
-### Exercise 1: Plotting interesting curves
|
|
123
|
+### Exercise 1 - Plotting interesting curves
|
124
|
124
|
|
125
|
125
|
|
126
|
|
-**Instructions**
|
|
126
|
+#### Instructions
|
127
|
127
|
|
128
|
|
-1. Load the project `prettyPlot` into `QtCreator`. There are two ways to do this:
|
|
128
|
+1. Load the project `prettyPlot` into `QtCreator`. There are two ways to do this:
|
129
|
129
|
|
130
|
130
|
* Using the virtual machine: Double click the file `prettyPlot.pro` located in the folder `/home/eip/labs/expressions-prettyplots` of your virtual machine.
|
131
|
131
|
* Downloading the project’s folder from `Bitbucket`: Use a terminal and write the command `git clone http:/bitbucket.org/eip-uprrp/expressions-prettyplots` to download the folder `expressions-prettyplots` from `Bitbucket`. Double click the file `prettyPlot.pro` located in the folder that you downloaded to your computer.
|
|
@@ -165,11 +165,11 @@ To plot a curve that is described by parametric equations, we compute the $$x$$
|
165
|
165
|
wLine.Plot();
|
166
|
166
|
wLine.show();
|
167
|
167
|
|
168
|
|
- The line `XYPlotWindow wLine;` creates the object `wLine`, that is the window that will show the plot of a graph, in this case the graph of a segment. Look at the `for` loop. In this cycle several values for $$t$$ are generated and a value for $$x$$ and $$y$$ is computed for each $$t$$. Each ordered pair $$(x,y)$$ is added to the graph of the segment by the method `AddPointToGraph(x,y)`. After the cycle, there is a call to the method `Plot()`, to "draw" the points on the graph, and to the method `show()`, to show the plot. The *methods* are functions that allow us to work with the data of an object. Note that each of the methods is written after `wLine`, and followed by a period. In a future laboratory experience you will learn more about objects and practice how to create them and invoke their methods.
|
|
168
|
+ The line `XYPlotWindow wLine;` creates the object `wLine`, which is the window that will show the plot of a graph, in this case the graph of a segment. Look at the `for` loop. In this cycle several values for $$t$$ are generated and a value for $$x$$ and $$y$$ is computed for each $$t$$. Each ordered pair $$(x,y)$$ is added to the graph of the segment by the method `AddPointToGraph(x,y)`. After the cycle, there is a call to the method `Plot()`, to "draw" the points on the graph, and to the method `show()`, to show the plot. The *methods* are functions that allow us to work with the data of an object. Note that each of the methods is written after `wLine`, and followed by a period. In a future laboratory experience you will learn more about objects and you will practice how to create them and invoke their methods.
|
169
|
169
|
|
170
|
170
|
The expressions for $$x$$ and $$y$$ are parametric equations for the line that passes through the origin and has the same value for $$x$$ and $$y$$. Explain why this line only goes from 0 to approximately 6.
|
171
|
171
|
|
172
|
|
-4. You will now write the code needed to plot a circle. The line `XYPlotWindow wCircle;` creates the object `wCircle` for the window that will contain the plot of the circle. Using the code that plotted the segment as inspiration, write the necessary code for your program to graph a circle of radius 3 and centered at the origin. Run your program and, if it is necessary, modify the code until you get the right plot. Remember that the circle should be plotted inside the `wCircle` object. Thus, when you invoke the `AddPointToGraph(x,y)`, `Plot` and `show` methods, they should be preceeded by `wCircle`; e.g. `wCircle.show()`.
|
|
172
|
+4. You will now write the code needed to plot a circle. The line `XYPlotWindow wCircle;` creates the object `wCircle` for the window that will contain the plot of the circle. Using the code that plotted the segment as inspiration, write the necessary code for your program to graph a circle of radius 3 centered at the origin. Run your program and, if it is necessary, modify the code until you get the right plot. Remember that the circle should be plotted inside the `wCircle` object. Thus, when you invoke the `AddPointToGraph(x,y)`, `Plot` and `show` methods, they should be preceeded by `wCircle`; e.g. `wCircle.show()`.
|
173
|
173
|
|
174
|
174
|
5. Your next task is to plot a curve with the following parametric equations:
|
175
|
175
|
|
|
@@ -193,18 +193,18 @@ To plot a curve that is described by parametric equations, we compute the $$x$$
|
193
|
193
|
|
194
|
194
|
$$y = 10 \sin(t)(q).$$
|
195
|
195
|
|
196
|
|
- Implement the above expressions, change the condition for termination of the `for` to `t < 16*M_PI`, and look at the plot that is displayed. It should look like a butterfly. This plot should be obtained inside an `XYPlotWindow` object called `wButterfly`.
|
|
196
|
+ Implement the above expressions, change the condition for termination of the `for` loop to `t < 16*M_PI`, and look at the plot that is displayed. It should look like a butterfly. This plot should be obtained inside an `XYPlotWindow` object called `wButterfly`.
|
197
|
197
|
|
198
|
198
|
|
199
|
199
|
In [2] and [3] you can find other parametric equations of interesting curves.
|
200
|
200
|
|
201
|
201
|
|
202
|
202
|
|
203
|
|
-### Exercise 2: Computing grade point average (GPA)
|
|
203
|
+### Exercise 2 - Computing the grade point average (GPA)
|
204
|
204
|
|
205
|
|
-In this exercise you will write a program to obtain a student's grade point average (GPA). 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.
|
|
205
|
+In this exercise you will write a program to obtain a student's grade point average (GPA). 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.
|
206
|
206
|
|
207
|
|
-**Instructions**
|
|
207
|
+#### Instructions
|
208
|
208
|
|
209
|
209
|
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).
|
210
|
210
|
|
|
@@ -222,11 +222,11 @@ In this exercise you will write a program to obtain a student's grade point aver
|
222
|
222
|
|
223
|
223
|
---
|
224
|
224
|
|
225
|
|
-## Deliveralbles
|
|
225
|
+## Deliverables
|
226
|
226
|
|
227
|
|
-1. Use "Deliverable 1" in Moodle to submit the file `main.cpp` containing the code with the parametric equations for the graphs of the circle, the heart, and the butterfly. Remember to use good programming practices, to include the names of the programmers and to document your program.
|
|
227
|
+1. Use "Deliverable 1" in Moodle to submit the file `main.cpp` containing the code with the parametric equations for the graphs of the circle, the heart, and the butterfly. Remember to use good programming practices, include the names of the programmers and document your program.
|
228
|
228
|
|
229
|
|
-2. Use "Deliverable 2" in Moodle 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.
|
|
229
|
+2. Use "Deliverable 2" in Moodle 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, include the names of the programmers, document your program and use good programming practices.
|
230
|
230
|
|
231
|
231
|
---
|
232
|
232
|
|
|
@@ -239,4 +239,4 @@ In this exercise you will write a program to obtain a student's grade point aver
|
239
|
239
|
|
240
|
240
|
[2] http://paulbourke.net/geometry/butterfly/
|
241
|
241
|
|
242
|
|
-[3] http://en.wikipedia.org/wiki/Parametric_equation
|
|
242
|
+[3] http://en.wikipedia.org/wiki/Parametric_equation
|