CSE 203 Homework 5

You may complete this homework, as any homework in this course, either alone as an individual, or in partnership with one other person.  Please make sure every author's name is listed at the top.
  1. This homework serves as partial practice for the midterm exam.  A similar (but different) question on the exam, unfortunately, serves partly as a test of how fast you can legibly copy down and write new Phrogram program statements!  What I really want to be testing is how well you think about solving the problem, and how well you can predict what your new program will do given exactly what you've written even though you can't, during the exam, test it on a computer.  I can't, at least for now, think of another way of testing your problem-solving and prediction abilities.  Consequently, I suggest that each person in the partnership actually practice writing down your answer so that you can practice writing both quickly and legibly.  I also suggest that you come up with your answer on your own and without first testing it on a computer before discussing it with your partner.  Later on, you and your partner can compare answers and check them out on the computer.
  2. Write out answers to questions 3.a. and 3.b. below.
  3. Given the following program, which I claim starts a flag in the lower right-hand corner of the window and moves it diagonally up and to the left,
    / Date: October 17, 2006
    // Author: Wayne Heym
    Program Sprite_Moving_Diagonally
    Method Main()

    Define F1 As Sprite
    F1.Load( "ohio-flag.gif" )
    Define F1Xpos As Decimal = ScreenWidth() - F1.Width
    Define F1Ypos As Decimal = ScreenHeight() - F1.Height
    Define F1_X_Speed As Decimal = -6
    Define F1_Y_Speed As Decimal = -6

    F1.MoveTo( F1Xpos, F1Ypos )
    F1.Show()

    While Not IsKeyDown( Escape )
    RefreshScreen()
    DoEvents()
    Delay( 15 )
    F1Xpos = F1Xpos + F1_X_Speed
    F1Ypos = F1Ypos + F1_Y_Speed
    F1.MoveTo( F1Xpos, F1Ypos )
    End While

    End Method

    End Program
    1. Draw a picture of the window and an arrow showing the direction that I claim flag F1 will move when this program runs.  Label this arrow "F1".  I want you to modify this program so that a second Ohio flag, call it, say F2, starts in the upper right-hand corner of the window and moves, at the same time F1 is moving, but in a different direction and at a different speed.  F2 should move half as fast as F1 and move diagonally down and to the left.  Draw in your picture an arrow showing the direction F2 should travel, and label that arrow "F2".
    2. Re-write this entire program including all additions and changes you would need to make to have two flags moving simultaneously as I've already described in part a. above.  After you've written it, read it over carefully, thinking about what would actually happen if you ran it on a computer, to see if you can catch any mistakes you might have made, and correct them.