Presentation is loading. Please wait.

Presentation is loading. Please wait.

VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)

Similar presentations


Presentation on theme: "VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)"— Presentation transcript:

1 VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)

2 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

3 Visual C++ Programming 3

4 4

5 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

6 Visual C++ Programming 6

7 7

8 8

9 9

10 10

11 Design (continued) Visual C++ Programming 11  Algorithm  Algorithm for Timer1_Tick() Refresh the PictureBox Draw the sun Draw the planet Increase the angle

12 Visual C++ Programming 12

13 Visual C++ Programming 13

14 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

15 Visual C++ Programming 15

16 Visual C++ Programming 16

17 Visual C++ Programming 17

18 Visual C++ Programming 18

19 Visual C++ Programming 19

20 Visual C++ Programming 20

21 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

22 Visual C++ Programming 22

23 Visual C++ Programming 23

24 Visual C++ Programming 24

25 Visual C++ Programming 25

26 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

27 Visual C++ Programming 27

28 Visual C++ Programming 28

29 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()


Download ppt "VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)"

Similar presentations


Ads by Google