visual c++ programming: concepts and projects chapter 6b methods (tutorial)
TRANSCRIPT
![Page 1: VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)](https://reader036.vdocument.in/reader036/viewer/2022062309/56649f475503460f94c68eb3/html5/thumbnails/1.jpg)
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS
Chapter 6BMethods (Tutorial)
![Page 2: VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)](https://reader036.vdocument.in/reader036/viewer/2022062309/56649f475503460f94c68eb3/html5/thumbnails/2.jpg)
Tutorial: Planetary Motion
Visual C++ Programming
2
Problem Analysis Create a program with a planet that orbits
around a central sun Planets orbit in an elliptical path The program will draw the planet at a new
location at regular intervals To calculate the next position of the planet you
need to know the x coordinate of the center of the ellipse The length of the semimajor axis of the ellipse The angle of the planet from the semimajor axis
![Page 3: VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)](https://reader036.vdocument.in/reader036/viewer/2022062309/56649f475503460f94c68eb3/html5/thumbnails/3.jpg)
Visual C++ Programming
3
![Page 4: VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)](https://reader036.vdocument.in/reader036/viewer/2022062309/56649f475503460f94c68eb3/html5/thumbnails/4.jpg)
Visual C++ Programming
4
![Page 5: VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)](https://reader036.vdocument.in/reader036/viewer/2022062309/56649f475503460f94c68eb3/html5/thumbnails/5.jpg)
Design
Visual C++ Programming
5
Interface sketch Controls
PictureBox to draw on Timer control to execute commands at regular
intervals Constants
Center of the ellipse Length of the semimajor and semiminor axes
Instance variables Graphics and Drawing objects
![Page 6: VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)](https://reader036.vdocument.in/reader036/viewer/2022062309/56649f475503460f94c68eb3/html5/thumbnails/6.jpg)
Visual C++ Programming
6
![Page 7: VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)](https://reader036.vdocument.in/reader036/viewer/2022062309/56649f475503460f94c68eb3/html5/thumbnails/7.jpg)
Visual C++ Programming
7
![Page 8: VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)](https://reader036.vdocument.in/reader036/viewer/2022062309/56649f475503460f94c68eb3/html5/thumbnails/8.jpg)
Visual C++ Programming
8
![Page 9: VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)](https://reader036.vdocument.in/reader036/viewer/2022062309/56649f475503460f94c68eb3/html5/thumbnails/9.jpg)
Visual C++ Programming
9
![Page 10: VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)](https://reader036.vdocument.in/reader036/viewer/2022062309/56649f475503460f94c68eb3/html5/thumbnails/10.jpg)
Visual C++ Programming
10
![Page 11: VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)](https://reader036.vdocument.in/reader036/viewer/2022062309/56649f475503460f94c68eb3/html5/thumbnails/11.jpg)
Design (continued)
Visual C++ Programming
11
Algorithm Algorithm for Timer1_Tick()
Refresh the PictureBox Draw the sun Draw the planet Increase the angle
![Page 12: VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)](https://reader036.vdocument.in/reader036/viewer/2022062309/56649f475503460f94c68eb3/html5/thumbnails/12.jpg)
Visual C++ Programming
12
![Page 13: VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)](https://reader036.vdocument.in/reader036/viewer/2022062309/56649f475503460f94c68eb3/html5/thumbnails/13.jpg)
Visual C++ Programming
13
![Page 14: VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)](https://reader036.vdocument.in/reader036/viewer/2022062309/56649f475503460f94c68eb3/html5/thumbnails/14.jpg)
Development
Visual C++ Programming
14
Create the interface Assign an image file to the PictureBox to
appear in the background Important: to make the image appear
Download the image Place it in your Project folder (within your
Solution folder of the same name) Project6 (Solution folder)
Project6 (Project folder) Use the Properties window to assign the image
to the PictureBox
![Page 15: VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)](https://reader036.vdocument.in/reader036/viewer/2022062309/56649f475503460f94c68eb3/html5/thumbnails/15.jpg)
Visual C++ Programming
15
![Page 16: VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)](https://reader036.vdocument.in/reader036/viewer/2022062309/56649f475503460f94c68eb3/html5/thumbnails/16.jpg)
Visual C++ Programming
16
![Page 17: VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)](https://reader036.vdocument.in/reader036/viewer/2022062309/56649f475503460f94c68eb3/html5/thumbnails/17.jpg)
Visual C++ Programming
17
![Page 18: VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)](https://reader036.vdocument.in/reader036/viewer/2022062309/56649f475503460f94c68eb3/html5/thumbnails/18.jpg)
Visual C++ Programming
18
![Page 19: VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)](https://reader036.vdocument.in/reader036/viewer/2022062309/56649f475503460f94c68eb3/html5/thumbnails/19.jpg)
Visual C++ Programming
19
![Page 20: VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)](https://reader036.vdocument.in/reader036/viewer/2022062309/56649f475503460f94c68eb3/html5/thumbnails/20.jpg)
Visual C++ Programming
20
![Page 21: VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)](https://reader036.vdocument.in/reader036/viewer/2022062309/56649f475503460f94c68eb3/html5/thumbnails/21.jpg)
Development (continued)
Visual C++ Programming
21
Coding Declare and assign static constants Declare handles for Graphics object and
Drawing objects Form1_Load()
Construct graphics and drawing objects btnStart_Click()
Start the Timer control btnStop_Click()
Stop the Timer control
![Page 22: VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)](https://reader036.vdocument.in/reader036/viewer/2022062309/56649f475503460f94c68eb3/html5/thumbnails/22.jpg)
Visual C++ Programming
22
![Page 23: VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)](https://reader036.vdocument.in/reader036/viewer/2022062309/56649f475503460f94c68eb3/html5/thumbnails/23.jpg)
Visual C++ Programming
23
![Page 24: VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)](https://reader036.vdocument.in/reader036/viewer/2022062309/56649f475503460f94c68eb3/html5/thumbnails/24.jpg)
Visual C++ Programming
24
![Page 25: VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)](https://reader036.vdocument.in/reader036/viewer/2022062309/56649f475503460f94c68eb3/html5/thumbnails/25.jpg)
Visual C++ Programming
25
![Page 26: VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)](https://reader036.vdocument.in/reader036/viewer/2022062309/56649f475503460f94c68eb3/html5/thumbnails/26.jpg)
Development (continued)
Visual C++ Programming
26
Coding Timer1_Tick() Declare local variables Refresh the pictureBox Draw the sun Draw the planet
Convert angle from degrees to radians Calculate planet x and y coordinates Draw the planet
Increase angle by 5 degrees
![Page 27: VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)](https://reader036.vdocument.in/reader036/viewer/2022062309/56649f475503460f94c68eb3/html5/thumbnails/27.jpg)
Visual C++ Programming
27
![Page 28: VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)](https://reader036.vdocument.in/reader036/viewer/2022062309/56649f475503460f94c68eb3/html5/thumbnails/28.jpg)
Visual C++ Programming
28
![Page 29: VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)](https://reader036.vdocument.in/reader036/viewer/2022062309/56649f475503460f94c68eb3/html5/thumbnails/29.jpg)
On Your Own
Visual C++ Programming
29
Instance methods with return values (Planets version 2) ConvertToRadians()
Instance methods with value parameters (Planets version 3) DrawPlanets()
Instance methods with reference parameters (Planets version 4) SetXY()