|
@@ -140,29 +140,31 @@ To plot a curve that is described by parametric equations, we compute the $$x$$
|
140
|
140
|
---
|
141
|
141
|
|
142
|
142
|
3. The file `main.cpp` (in Sources) contains the function `main()` where you will be adding code. Open this file and study the code.
|
143
|
|
-
|
144
|
|
- QApplication a(argc, argv);
|
145
|
|
- XYPlotWindow wLine;
|
146
|
|
- XYPlotWindow wCircle;
|
147
|
|
- XYPlotWindow wHeart;
|
148
|
|
- XYPlotWindow wButterfly;
|
149
|
|
-
|
150
|
|
- double y = 0.00;
|
151
|
|
- double x = 0.00;
|
152
|
|
- double increment = 0.01;
|
153
|
|
-
|
154
|
|
- for (double t = 0; t < 2*M_PI; t = t + increment) {
|
155
|
|
- // parametric equations
|
156
|
|
- x = t;
|
157
|
|
- y = t;
|
158
|
|
-
|
159
|
|
- // add x and y as a point in the graph
|
160
|
|
- wLine.AddPointToGraph(x,y);
|
161
|
|
- }
|
162
|
|
-
|
163
|
|
- // After all the points have been added, plot and show the graph
|
164
|
|
- wLine.Plot();
|
165
|
|
- wLine.show();
|
|
143
|
+
|
|
144
|
+ ```cpp
|
|
145
|
+ QApplication a(argc, argv);
|
|
146
|
+ XYPlotWindow wLine;
|
|
147
|
+ XYPlotWindow wCircle;
|
|
148
|
+ XYPlotWindow wHeart;
|
|
149
|
+ XYPlotWindow wButterfly;
|
|
150
|
+
|
|
151
|
+ double y = 0.00;
|
|
152
|
+ double x = 0.00;
|
|
153
|
+ double increment = 0.01;
|
|
154
|
+
|
|
155
|
+ for (double t = 0; t < 2*M_PI; t = t + increment) {
|
|
156
|
+ // parametric equations
|
|
157
|
+ x = t;
|
|
158
|
+ y = t;
|
|
159
|
+
|
|
160
|
+ // add x and y as a point in the graph
|
|
161
|
+ wLine.AddPointToGraph(x,y);
|
|
162
|
+ }
|
|
163
|
+
|
|
164
|
+ // After all the points have been added, plot and show the graph
|
|
165
|
+ wLine.Plot();
|
|
166
|
+ wLine.show();
|
|
167
|
+ ```
|
166
|
168
|
|
167
|
169
|
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.
|
168
|
170
|
|