Assignment

Contents:

  • Overview
  • Internet Requirements
  • Practice Problems
  • Problems to be Submitted
  • Extra Credit

  • Overview

    Topic: High-Level Programming
    Related Reading: Ch. 8.1-8.3 of Dale/Lewis as well as Lab 8 of Meyer
    Due:

    Internet Requirements

    For this assignment, we will rely at times on the Palgo software demonstrated in class. You will need to have an external Internet connection to run this software.

    Practice Problems

  • Exercise 17 of Ch. 8 (p. 267); answer in back of text

  • Review the program examples that come with the Palgo package.

  • Try Exercises 1 and 2 from Lab 8 of the Meyer book.

  • We have not often explored the publishers web site for the text. Complete the crossword puzzle associated with Chapter 8. (The answers can be revealed through the icon near the bottom-left corner of the puzzle.)

  • Problems to be Submitted (20 points)

    1. (6 points)
        For this problem, you can use Palgo to do the work for you if you'd like. Though on a test, you would certainly be expected to do such a problem on your own, so please make sure that you fully understand the answer.

      1. What value or sequence of values will be printed when running the following segment of code?
           val = 3
           while val < 6
             print(val)
             val = val + 1
           end
        

      2. What value or sequence of values will be printed when running the following segment of code?
           val = 11
           while val >= 7
             val = val -1
             print(val)
           end
        

    2. (4 points)
      Modify the PlotPoint subroutine in the following Palgo program, so that it only plots a point in the case that x>2*y.

      define PlotPoint(x,y)
        draw(x,y)
      end
      
      /* include, but do not change anything below this line */
      color("red")
      repeat 1000 times
        PlotPoint(random(20),random(20))
        wait(100)
      end
      
      

    3. (5 points)
      Modify the PlotPoint subroutine in the following Palgo program, so that it always draws the point x,y, however chooses the color based on the following rules:
    4. blue: whenever x <= y AND x <= (19-y)
    5. red: whenever y < x <= (19-y)
    6. green: whenever y < x AND (19-y) < x
    7. yellow: whenever (19-y) < x <= y
    8. define PlotPoint(x,y)
        draw(x,y)
      end
      
      /* include, but do not change anything below this line */
      color("red")
      repeat 1000 times
        PlotPoint(random(20),random(20))
        wait(100)
      end
      
      

      A typical result of running such a program is the following. Please be careful in handling the boundaries between colors precisely.

    9. (5 points)
      Write a Palgo program which draws a red X across the entire grid, as shown here:
    Overall, please type your answers to all of the problems in a single document to be submitted electronically. Please see details about the submission process.

    Extra Credit (2 points)

    Write a subroutine
        define rectangle(leftX,topY,width,height)
            ...
        end
    
    Which draws in a filled rectangle with the top left corner in the given location and with specified dimensions.

    Once you have tested this routine to see that it works, then you can modify the "Random Colored Dots" program to develop a random colored rectangles program, as described in the "Deeper Investigation" section of Lab 8 of the Meyer text.


    Last modified: 16 February 2003