JES Review Questions

From Georgia Tech CS 1315 Review Questions:
  1. If you type the following into the command area of JES, what will be printed on the line below?

    (a) 5.0/2
    (b) 5/2
    (c) getHeight(makeEmptyPicture(640, 480))
    (d) distance(green, green)
    (e) distance(black, blue)
    (f) range(0, 3)

  2. Please write what would be printed if you typed the follwing in the JES command area.

    (a) 13 / 2
    (b) 2 1
    (c) 2 == 2
    (d) 1 == "1"
    (e) 13 % 2

  3. Consider this code and fill in the blanks below:
    for x in range(0,1000):
      print x # First command
    print x #Second command
    

    (a) The number of times the first print command is executed: ...........
    (b) The number of times the second print command is executed: ..........
  4. Here's the input picture:

    mangle1.jpg

    And here's what it looked like afterward:

    mangle2.jpg

    Which of the below functions did this?
    (a)
    
    def mangle(picture):
      for x in range(1,getWidth(picture)/2):
        for y in range(1,getHeight(picture)/2):
          setColor(getPixel(picture,x,y),black)
      for x in range(getWidth(picture)/2,getWidth(picture)):
        for y in range(getHeight(picture)/2,getHeight(picture)):
          setColor(getPixel(picture,x,y), white)
    (b)
    
    def mangle(picture):
      for x in range(1,getWidth(picture)):
        for y in range(1,getHeight(picture)):
          setColor(getPixel(picture,x,y),white)
      for x in range(getWidth(picture)/2,getWidth(picture)):
        for y in range(getHeight(picture)/2,getHeight(picture)):
          setColor(getPixel(picture,x,y),black)
    
    (c)
    
    def mangle(picture):
      for x in range(1,getWidth(picture)/2):
        for y in range(1,getHeight(picture)/2):
          setColor(getPixel(picture,x,y),white)
      for x in range(getWidth(picture)/2,getWidth(picture)):
        for y in range(getHeight(picture)/2,getHeight(picture)):
          setColor(getPixel(picture,x,y),black)
    
    (d)
    
    def mangle(picture):
      for x in range(1,getWidth(picture)/2):
        for y in range(1,getHeight(picture)/2):
          setColor(getPixel(picture,x,y),white)
      for x in range(1,getWidth(picture)):
        for y in range(1,getHeight(picture)):
          setColor(getPixel(picture,x,y),black)
    


  5. For each of the below programs, write a one sentence description of what it does, where each sentence must be 10 words or less.

    (a)
    
    def alley(aPicture):
      for num in range(1,100):
        setColor(getPixel(aPicture,num,num),red)
    
    (b)
    
    def jespart(aPicture):
      for x in range(1,getWidth(aPicture)/2):
        for y in range(1,getHeight(aPicture)/2):
          pixel = getPixel(aPicture,x,y)
          setRed(pixel,0)
    
    


  6. Write a function called changeRGB that takes four inputs: A picture, and an amount to change the red, green, and blue (in that order) pixels. Like before, each amount should be between -.99 and .99.

    Thus, changeRGB(picture, -.75, .25, -.25) would...

  7. Which of the functions below takes a picture and removes all the blue from every pixel of that picture that already has a blue value of more than 100?

    1. A only
    2. D only
    3. B and C
    4. C and D
    5. None
    6. All

    What do the other ones do?


    A

    def blueOneHundred(picture):
      for x in range(1,100):
        for y in range(1,100):
          pixel = getPixel(picture,x,y)
          setBlue(pixel,100)

    B

    def removeBlue(picture):
      for p in getPixels(picture):
        if getBlue(p) > 0:
          setBlue(p,100)

    C

    def noBlue(picture):
      blue = makeColor(0,0,100)
      for p in getPixels(picture):
        color = getColor(p)
        if distance(color,blue) > 100:     
          setBlue(p,0)

    D

    def byeByeBlue(picture):
      for p in getPixels(picture):
        if getBlue(p) > 100:
          setBlue(p,0)


  8. What does it mean for a function to "take-in" a value?

  9. What does it mean for a function to "return" a value?

  10. What is the difference between show() and return?

  11. If you digitized a recording of a mobile telephone conversation and a group of live musicians in a recording studio

    (a) Which would require a greater (i.e. faster) sampling rate for
    accurate reproduction?
    (i) The phone call
    (ii) The music recording
    (b) Why?

  12. Given that a sound is encoded as a sequence of two-byte samples, what is the range of values that a sample can have? (The abbreviation "k" means "1,024")

    (a) -11..+10
    (b) -128..+127
    (c) -256..+255
    (d) -32k..+32k-1
    (e) -64k..+64k-1

  13. > (a) The sounds we used in class are all two-byte WAV files. State the maximum and minimum sample values for such a sound. (You can give a value to the nearest thousand.)

    (b) Some of the WAV files you may have downloaded or heard demonstrated in class are one-byte sounds. What are the maximum and minimum values for samples in such a sound? (Hint: Answer is not +-11)

    (c) What is clipping?

  14. When we normalize a sound, we make it louder, but we have to be careful not to make it too loud. Explain in English the algorithm for normalizing a sound (Hint: It contains two loops, one after the other).

  15. Here is a code template for doing something to a sound:
    def loopThroughSound1(sound):
       for s in getSamples(sound):
         pass
    


    Suppose that there is a bug in the implementation of getSamples() so that you cannot use it. (In an earlier version of JES this was true.) Rewrite the code template using another way to go through all the samples in the sound. You can assume that getSample() still works correctly.

  16. White noise is the hissing sound that is often introduced into a recording by equipment, electrical conditions, etc. We can simulate the introduction of white noise into a digitized sound by changing its sample values by random amounts.

    Write a short function called makeNoisy that takes a sound as its input and modifies the sound by adding a random amount to every sample. The noise should vary randomly between -500 and +500 in value. Don't worry about the noise causing clipping. Just let that happen (this is noise, after all). You can start from the template below and fill in the details.
    import
    def makeNoisy(              ):
    
        for              in                                 :
    
    
    
    
    
    
    
    
    
    
    
    


Comments?
Last modified: Mon Apr 28 00:03:00 EDT 2008