Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

Looking for the book? They have it at the Engineer's Bookstore at 748 Marietta St NW. Here is there website: http://www.engrbookstore.com/ - Monica

Hotspots: Slides and CodeTA CornerComments?AnnouncementsFAQStatic Webspace
View this PageEdit this Page (locked)Uploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Fall2003 Midterm Review 1

Below are questions like those I plan to ask on Midterm #1 (Sept. 17). The exam will consist of 4 or 5 questions like these.

Please do try these questions! Post your answers, questions, comments, concerns, and criticisms on the pages for each question. Those comments, questions, etc. can also be about each others' answers! If someone posts an answer that you don't understand, ask about it! If you see a question here that you know the answer to, don't keep it to yourself – help your fellow students!

I will be reading your answers. Here are the ground rules for the interaction.
  1. If you don't post, neither will I. I will not be posting official solutions to these problems at all! If one of you gets it right, terrific!
  2. I will try to always point out if an answer is wrong. I won't always point out when the answer is right.
  3. I am glad to work with you toward the right answer. I will give hints, and I'm glad to respond to partial guesses.



Generalized changeColor


Write a new version of the function increaseRed and decreaseRed (and blue and green) called changeColor that takes as input a picture AND an amount to increase or decrease a color by AND a number 1 (for red), 2 (for green), or 3 (for blue). The amount will be a number between -.99 and .99.


def increaseRed(pict):
  for p in getPixels(pict):
    setRed(p,getRed(p)*1.2)
    
def decreaseRed(pict):
  for p in getPixels(pict):
     setRed(p,getRed(p)*.80)


Questions, comments, and answers for Midterm Exam 1 Review Fall 2003: Generalized changeColor

Generalized image filter


Now go one step further. Write a function changeRGB that takes four inputs: A picture, and an amount to change the red, green, and blue (in that order) pixels. Each amount should be between -.99 and +.99.

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


Questions, comments, and answers for Midterm Exam 1 Review Fall 2003: Generalized image filter


What does it mean?


  1. What does def mean? What does the statement def someFunction(x,y): do?
  2. What does for mean? What does the statement for x in range(1,5): do?
  3. What does print mean? What does the statement print a do?

Questions, comments, and answers for Midterm Exam 1 Review Fall 2003: What does it mean?



Which does which?


Which of the recipes 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)


Questions, comments, and answers for Midterm Exam 1 Review Fall 2003: Which does which

Check your luminance


Write a program checkLuminance that will input red, green, and blue values, and compute the luminance using the weighted average (as below). But then, print out a warning to the user based on the computed luminance:

If the luminance is...Print out the statment...
Less then 10"That's going to be awfully dark"
Between 50 and 200"Looks like a good range"
Over 250"That's going to be nearly white"

def greyScaleNew(picture):
  for px in getPixels(picture):
    newRed = getRed(px) * 0.299
    newGreen = getGreen(px) * 0.587
    newBlue = getBlue(px) * 0.114
    luminance = newRed+newGreen+newBlue
    setColor(px,makeColor(luminance,luminance,luminance))


Questions, comments, and answers for Midterm Exam 1 Review Fall 2003: Check your luminance


Picture concepts


  1. Why don't we see red, green, and blue spots at each position in our picture?

  2. What is luminance?

  3. Assume an RGB color model with 8 bits per each color component. How much more memory is required to display a 1024x768 monitor image compared to a 320x240 cheap digital picture image?

Questions, comments, and answers for Midterm Exam 1 Review Fall 2003: Picture concepts

Sound concepts


  1. What does a fourier transform (FFT) show you?

  2. What is the Nyquist theorem? Why can't you hear CD music well over a telephone?

  3. How does the amplitude of the sound impact our sensation of the sound?

Questions, comments, and answers for Midterm Exam 1 Review Fall 2003: Sound concepts


CS concepts


  1. What is an algorithm?
  2. What is hierarchical decomposition? What is it good for?
  3. Why would you want to put comments in a program?
  4. What's an encoding?
  5. What is Moore's Law?

Questions, comments, and answers for Midterm Exam 1 Review Fall 2003: CS concepts

Increase the volume, stepped


Write a function increaseVolumeStepped that takes a sound as input:

Questions, comments, and answers for Midterm Exam 1 Review Fall 2003: Increase the volume, stepped #2


What gets printed?


Consider the below program:

def testme(p,q,r):
  if q > 50:
    print r
  value = 10
  for i in range(1,p):
    print "Hello"
    value = value - 1
  print value
  print r


If we execute testme(5,51,"Hello back to you!"), what will print?

Hint: DON'T TRY IT IN JES! Try to figure it out by walking through the code. On the exam, you will NOT have access to JES.

Questions, comments, and answers for Midterm Exam 1 Review Fall 2003: What gets printed

Compute pay rates


Write a function called pay that takes in as input a number of hours worked and the hourly rate to be paid. Compute the gross pay as the hours * the rate. But then compute a tax.

If the pay is...Charge a tax of...
< 100 .25
>= 200 and <300 .35
>=300 and <400 .45
>=400.50

Compute the taxed amount as tax rate * gross pay.
Print the gross pay and the net pay (gross - tax).


Questions, comments, and answers for Midterm Exam 1 Review Fall 2003: Compute the pay rate

Tracing the printing


def newFunction(a, b, c):
    print a
    list1 = range(1,5)
    value = 0
    for x in list1:
        print b
        value = value +1
    print c
    print value


If you call the function above by typing:

newFunction("I", "you", "walrus")

what will the computer print?

Questions, comments, and answers for Midterm Exam 1 Review Fall 2003



Match the meaning to the program


Here are four possible outcomes of programs:
  1. Mirror the input picture's leftmost 20 pixels to pixels 21 to 40.
  2. Copy the good part of the temple pediment to the broken part.
  3. Copy the broken part of the temple pediment to the working part.
  4. Mirror the input picture left to right
  5. Mirror the input picture left to right

Which of the below programs does which of the above outcomes?

A.
def mirrorTemple():
  source = makePicture(getMediaPath("temple.jpg"))
  mirrorpoint = 277
  lengthToCopy = mirrorpoint - 14
  for x in range(1,lengthToCopy):
    for y in range(28,98):
      p = getPixel(source,mirrorpoint-x,y)
      p2 = getPixel(source,mirrorpoint+x,y)
      setColor(p2,getColor(p))
  show(source)
  return source


B.
def mirrorTemple():
  source = makePicture(getMediaPath("temple.jpg"))
  mirrorpoint = 277
  lengthToCopy = mirrorpoint - 14
  for x in range(1,lengthToCopy):
    for y in range(28,98):
      p = getPixel(source,mirrorpoint-x,y)
      p2 = getPixel(source,mirrorpoint+x,y)
      setColor(p,getColor(p2))
  show(source)
  return source


C.
def mirrorVertical(source):
  mirrorpoint = int(getWidth(source)/2) Tracing the printing
  for y in range(1,getHeight(source)):
    for xOffset in range(1,mirrorpoint):
      pright = getPixel(source, xOffset+mirrorpoint,y)
      pleft = getPixel(source, mirrorpoint-xOffset,y)
      c = getColor(pleft)
      setColor(pright,c)


D.
def mirrorVertical(source):
  mirrorpoint = int(getWidth(source)/2)
  for y in range(1,getHeight(source)):
    for xOffset in range(1,mirrorpoint):
      pright = getPixel(source, xOffset+mirrorpoint,y)
      pleft = getPixel(source, mirrorpoint-xOffset,y)
      c = getColor(pright)
      setColor(pleft,c)


E.
def mirrorVertical(source):
  mirrorpoint = 20
  for y in range(1,getHeight(source)):
    for xOffset in range(1,mirrorpoint):
      pright = getPixel(source, xOffset+mirrorpoint,y)
      pleft = getPixel(source, mirrorpoint-xOffset,y)
      c = getColor(pleft)
      setColor(pright,c)


Questions, comments, and answers for Midterm Exam 1 Review Fall 2003: Match the meaning to the program


Scaling with input


Consider the below program:
def copyBarbsFaceScaled(factor):
  # Set up the source and target pictures
  barbf=getMediaPath("barbara.jpg")
  barb = makePicture(barbf)
  canvasf = getMediaPath("7inX95in.jpg")
  canvas = makePicture(canvasf)
  # Now, do the actual copying
  sourceX = 45
  for targetX in range(100,100+int((200-45)*factor)):
    sourceY = 25
    for targetY in range(100,100+int((200-25)*factor)):
      print "Copying from ",sourceX,sourceY," to ",targetX,targetY
      color = getColor(getPixel(barb,int(sourceX),int(sourceY)))
      setColor(getPixel(canvas,targetX,targetY), color)
      sourceY = sourceY + (1.0/factor)
    sourceX = sourceX + (1.0/factor)
  show(barb)
  show(canvas)
  return canvas


A. What pictures will appear when you execute copyBarbsFaceScaled(0.5)? What will be the first four lines printed?

B. What pictures will appear when you execute copyBarbsFaceScaled(2.0)? What will be the first four lines printed?

C. What pictures will appear when you execute copyBarbsFaceScaled(1.5)? What will be the first four lines printed?

Questions, comments, and answers for Midterm Exam 1 Review Fall 2003: Scaling with input

Links to this Page