 |  |

 |
 |  |  |
 | Welcome to CS1315. Click on the python to add comments.
|  |
 |  |  |
|
This page removed for FERPA compliance
|
        |
Sp2003 Final Exam Review
Below are questions like those I plan to ask on the Final Exam (May 2, 2:50-5:40). I may also ask questions from Sp2003 Midterm Review 2. The exam will consist of 5-8 questions like these.
Specific Sp2003 Midterm Review 2 questions to review:
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.
- 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!
- I will try to always point out if an
answer is wrong. I won't always point out when the answer is right.
- I am glad to work with you toward the right answer. I will give
hints, and I'm glad to respond to partial guesses.
FINAL EXAM REVIEW IN CLASS ON FRIDAY APRIL 25!
Questions on Objects
- What's the difference between an instance and a class?
- How are functions and methods different?
- How is object-oriented programming different from procedural programming and functional programming?
- What is Polymorphism?
- What is encapsulation?
- What is aggregation?
- How did biological cells influence the development of the ideas of objects?
Questions, comments, and answers for Final Exam Review Spring 2003: Questions on Objects
Questions on Functional Programming
- What's the difference between map, filter, and reduce?
- Why would anyone want to use functional programming?
- Give me an example of when people do use functional programming?
- Identify three reasons why someone should use multiple functions
rather than one big function in their programs.
- Identify three reasons why someone should use multiple functions
rather than one big function in their programs.
Questions, comments, and answers for Final Exam Review Spring 2003: Questions on Functional Programming
Recursion
Remember this example:
>>> downUp("Hello")
Hello
ello
llo
lo
o
lo
llo
ello
Hello
Here's the code that we wrote that did it:
def downUp(word):
if len(word)==1:
print word #Print #1
return
print word #Print #2
downUp(word[1:])
print word #Print #3
a. Which print statement prints the ever-shortening ("on the way
down") words? Which print statement prints the single letter in the
middle? Which print statement prints the longer-growing words?
b. At most, how many copies of downUp are running at once with the
input "Hello"?
c. How would you modify downUp to create upDown that works like
this:
>>> upDown("Hello")
Hello
Hell
Hel
He
H
He
Hel
Hell
Hello
Questions, comments, and answers for Final Exam Review Spring 2003: Recursion
Questions on Functions
- Identify three reasons why someone should use multiple functions
rather than one big function in their programs.
- What is procedural abstraction?
- What is good modularity?
Questions, comments, and answers for Final Exam Review Spring 2003: Questions on Functions
Name that algorithm!
a. Consider these two programs.
def half(filename):
source = makeSound(filename)
target = makeSound(filename)
sourceIndex = 1
for targetIndex in range(1, getREMOVEDngth( target)+1):
setSampleValueAt( target, targetIndex, getSampleValueAt( source,
int(sourceIndex)))
sourceIndex = sourceIndex + 0.5
play(target)
return target
and
def copyBarbsFaceLarger():
# 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+((200-45)*2)):
sourceY = 25
for targetY in range(100,100+((200-25)*2)):
color = getColor(
getPixel(barb,int(sourceX),int(sourceY)))
setColor(getPixel(canvas,targetX,targetY), color)
sourceY = sourceY + 0.5
sourceX = sourceX + 0.5
show(barb)
show(canvas)
return canvas
What algorithm is being implemented in these two examples? Explain
the algorithm in English.
B. Consider these two programs:
def findInSortedList(something, alist):
for item in alist:
if item == something:
return "Found it!"
return "Not found"
and
def turnRed():
brown = makeColor(57,16,8)
file = r"C:\Documents and Settings\Mark Guzdial\My Documents\\mediasources\barbara.jpg"
picture=makePicture(file)
for px in getPixels(picture):
color = getColor(px)
if distance(color,brown)<100.0:
reREMOVEDss=getRed(px)*1.5
setRed(px,reREMOVEDss)
show(picture)
return(picture)
What algorithm is being implemented in these two examples? Explain
the algorithm in English.
Questions, comments, and answers for Final Exam Review Spring 2003: Name that Algorithm!
Questions on Complexity
- Who's Alan Turing and what did he do of interest to us?
- Is optimization (e.g., the ``song'' problem) class P or
intractable? What does intractable mean?
- Is the Traveling Salesman problem impossible to solve in
reasonable amounts of time?
Questions, comments, and answers for Final Exam Review Spring 2003: Questions on Complexity
Converting to Methods
Recall this example from the objects lecture:
def makeREMOVEDnset(picture):
for p in getPixels(picture):
p.setBlue(p.getBlue()* 0.7)
p.setGreen(p.getGreen() * 0.7)
Rewrite each of the below functions to use methods and dot notation.
(a)
def clearRed(picture):
for pixel in getPixels(picture):
setRed(pixel,0)
(b)
def greyscale(picture):
for p in getPixels(picture):
reREMOVEDss=getRed(p)
greenness=getGreen(p)
blueness=getBlue(p)
luminance=(reREMOVEDss+blueness+greenness)/3
setColor(p,makeColor(luminance,luminance,luminance))
(c)
def negative(picture):
for px in getPixels(picture):
red=getRed(px)
green=getGreen(px)
blue=getBlue(px)
negColor=makeColor(255-red,255-green,255-blue)
setColor(px,negColor)
Questions, comments, and answers for Final Exam Review Spring 2003: Converting to Methods
Defining a Class
Remember this example from class:
class slide:
def __init__(self, pictureFile,soundFile):
self.picture = makePicture(pictureFile)
self.sound = makeSound(soundFile)
def show(self):
show(self.picture)
blockingPlay(self.sound)
Define an address class:
- It initializes with a name, a phone number, and address strings.
- It has getName(), getAddress(), and getPhone() methods that return the appropriate strings.
Questions, comments, and answers for Final Exam Review Spring 2003: Defining a Class
Movie Variations
In class, we played with this function:
def movingRectangle(directory):
for frame in range(0,100): #99 frames
canvas = makePicture(getMediaPath("640x480.jpg"))
if frame < 50: #REMOVEDss than 50, move down
# Generate new positions each frame number
addRectFilled(canvas,frame*10,frame*5, 50,50,red)
if frame >= 50: #Greater than 50, move up
addRectFilled(canvas,(50-(frame-50))*10,(50-(frame-50))*5, 50,50,red)
# Now, write out the frame
# Have to deal with single digit vs. double digit frame numbers differently
framenum=str(frame)
if frame < 10:
writePictureTo(canvas,directory+"//frame0"+framenum+".jpg")
if frame >= 10:
writePictureTo(canvas,directory+"//frame"+framenum+".jpg")
What do each of these variations do?
(a)
def movingRectangle(directory):
for frame in range(0,100): #99 frames
canvas = makePicture(getMediaPath("640x480.jpg"))
# Generate new positions each frame number
addRectFilled(canvas,frame*10,frame*5, frame,frame*2,red)
# Have to deal with single digit vs. double digit frame numbers differently
framenum=str(frame)
if frame < 10:
writePictureTo(canvas,directory+"//frame0"+framenum+".jpg")
if frame >= 10:
writePictureTo(canvas,directory+"//frame"+framenum+".jpg")
(b)
def movingRectangle(directory):
for frame in range(0,100): #99 frames
canvas = makePicture(getMediaPath("640x480.jpg"))
# Generate new positions each frame number
addRectFilled(canvas,frame*10,frame*5, 50,50,makeColor(frame,frame,frame))
# Now, write out the frame
# Have to deal with single digit vs. double digit frame numbers differently
framenum=str(frame)
if frame < 10:
writePictureTo(canvas,directory+"//frame0"+framenum+".jpg")
if frame >= 10:
writePictureTo(canvas,directory+"//frame"+framenum+".jpg")
(c)
def movingLine(directory):
for frame in range(0,100): #99 frames
canvas = makePicture(getMediaPath("640x480.jpg"))
# Generate new positions each frame number
addLine(canvas,frame*10,frame*5, frame*2,frame*3)
# Now, write out the frame
# Have to deal with single digit vs. double digit frame numbers differently
framenum=str(frame)
if frame < 10:
writePictureTo(canvas,directory+"//frame0"+framenum+".jpg")
if frame >= 10:
writePictureTo(canvas,directory+"//frame"+framenum+".jpg")
Questions, comments, and answers for Final Exam Review Spring 2003: Movie Variations
Database Ideas
- What is SQL?
- When should you use a database rather than plain files?
- What does a database have to do with how a large news website
like CNN.com is built?
- How is a news site like http://news.google.com made? Hint:
They have no reporters.
Questions, comments, and answers for Final Exam Review Spring 2003: Database Ideas
Network Ideas
- What's an IP address?
- What is the Internet?
- What is HyperText and what does it have to do with the Web?
- What is a protocol, and where does it appear in a URL?
Questions, comments, and answers for Final Exam Review Spring 2003: Network Ideas
Links to this Page