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

This page removed for FERPA compliance
View this PageEdit this Page (locked)Uploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Midterm Exam 2 Review Spring 2004: Short Essay

Comments, answers, and questions go here:

(Link back to Sp2004 Midterm 2 Review)


a) you would write a program for a task that MAKES an webpage with html; you woulnd not write a program for a webpage with html.
d) red isn't used in chromakey because there's lots of red in people's skin tones. I can't answer the otehrs yet...are these correct?
Student1192

I don't grok your answer to (a) – both of them look like the same thing. Mark Guzdial

(a) Give me one example of a task for which you would not write a program, and give me another example of a task for which you would write a program.

You would write a program, for instance, when you are computing complicated math problems. You write programs so that others can change or tweak aspects of the program, so that they can use it for themselves.

You would not write a program for simple things, such as calculating a simple math problem.


(b) What's the differerence between an array, a matrix, and a tree? Give an example where we have used each to represent some data of interest to us.

An array is a sequence of elements, each with an index number associated with it.
A matrix is a collection of elements arranged in both a horizontal and vertical sequence, a two-dimensional array is a matrix. (page 40)

A complete description of what directories to visit to get to a particular file from the base directory is called a path. It starts with the root directory (ex: C:\) and continues with the other directories (ex: Documents and Settings\Owner\…) This entire structure is called a tree. (page 221)


(c) What is dot notation and when do you use it? (pages 216-218)

Keep in mind that Strings in Python are objects. They are not only sequences of characters—they also have methods that are not globally accessible, but are known only to strings.

To execute a method of a string, you used DOT NOTATION. You type object.method()

Some examples of DOT NOTATION are:

capitalize(): it capitalizes the string it’s called upon. It will not work on a function, nor on a number

startswith(): returns true (1 or greater) if the string starts with the given suffix. Or false (0) if the string does not start with the given suffix.

endswith(): same as above, but string that ends with given suffix

find(findstring) and find(findstring,start) and find(findstring,start,end): all find the findstring in the object string and returns the index number where the string starts. In the optional forms, you can tell it what index number to start from, and even where to stop looking. Keep in mind if it returns –1 then the FIND() method failed.

upper(): REMOVEDslates the string to uppercase
lower(): “”lowercase
swapcase(): makes all uppercase into lowercase, and vice versa
title(): makes first characters uppercase, and the rest lower

isalpha(): returns true if the string is not empty and is all letters—no numbers or punctuation
isdigit(): same as above, but for only numbers.
replace(search,replace): searches for the search string and replaces it with the replace string. IT returns the result, but doesn’t change the original string.

(d) Why is red a bad color to use for chromakey? (p123, 275)

You do not want to use red for a chromakey color because there is a lot of read in our faces. Instead, moviemakers and weather people use blue or green backgrounds. (p 126)

(e) What's the difference between a function and a method? (p. 216)

Methods are like functions, except that they are not globally accessible. You can’t just execute a method the way you can execute pickAFile() or makeSound(). A method is a function that can only be accessed through an object.


(f) Why is a tree a better representation for files on a disk than an array? Why do you have many directories on your disk, and not just one gigantic one?
A tree is a better representation for files on a disk than an array because it helps in organization. It would be very difficult to find a particular file if there was only one main folder, root, or base directory. In addition having many different directories makes it easier for programming. For instance, if we are creating a webpage and using pictures from our computer, it would be much easier to search for pictures in a given folder, rather than the entire computer.

(g) What are some advantages that Vector-Based graphics have over Bitmap Graphical representations (like JPEG, BMP, GIF)? (be sure to read p 130-131)

Bitmap graphical representations store every individual pixel, or some compressed representation of the pixels. Depending on the size of the image, vector-based representations may be smaller and easier to send through the Internet. (vector-based representations are essentially sending instructions on how to make the picture, rather than sending the picture itself.)

THE REAL BENEFIT of vector-based notations come when you want to change the image. When editing bitmap graphical representations you are editing individual pixels on the screen, whereas when you are working with vector-based graphics you are changing an underlying representation of the picture.

Student954

(a) Why would you not write a program for simple things? Who do we write programs for?
(c) I like your answer to C, but when and why would we use dot notation and objects?
(d) Yes, choosing red is a bad idea because it is such a dominant color.
Stephanie Weitzel

Pretty amazing answers, Gigi! Folks, you wouldn't have to write THAT much to get full credit! If you want to trial shorter answers to see if that's enough, we'll give you feedback on those, too. Mark Guzdial


You would not write a program for simple things because programs are written for HUMANS, not computers, therefore, the human brain would probabl be REMOVED efficient in calculating a simple math problem. And thanks for writing down page numbers, Gigi, you're great :)
Student1003

Here are my answers...they aren't as in-depth, but would they suffice?

2A) You would not write programs for simple math problems because programs are written for humans, and in this case, humans may be REMOVED efficient than a computer program (p.17). You would write programs for complicated math problems however, and programs that allow humans to tweak them and perfect them to their satisfaction.

B) An array is literally a sequence of bytes next to one another in memory (p.146).A matrix is a two dimensional array (p.40). A tree is a structure that tells users how to go from the root directory (the “root” of the tree) to different sub-directories (p.221). Data of interest can be stored in all. The samples that make up a sound can be stored in an array, pixels that make up pictures can be stored in matrixes (matrices?), and trees display complex relationships between directories.

C) Dot notation is a convention used to execute a method of a string (p.216). (maybe I need to expand on this...I’m confused on the difference between the definition and when you use it?)

D) Red is a bad color to use for Chromakey because it’s a color commonly found in skin tones, so green or blue would be a better choice.

E) Methods are like functions except they are not globally accessible. A method is function that can only be accessed through an object. (P.216).

F) A tree is REMOVED organized and REMOVED easy to read than an array. Additionally, having one gigantic directory would make it difficult to find sub-directories and files.

G) Sending a picture using vector-based representation is much smaller than sending all the pixels. Also, vector-based notations are much REMOVED beneficial in terms of changing pictures because the drawing isnt just pixels, like with bitmap graphical, but is a specification of the lines and their relationships (p.131).
Student1003

A) you wouldn't write a program for something you are doing once.
but you write one if: you do it lots of times, if someone else might want to do it.

We write programs for replication, for tailorability, and for communicating process. Now, try turning those into examples. Mark Guzdial


(a) You would not write a program when doing a computation that you will only need to compute one time. You would write a program if you will be using the same computation to compute data where you would only want to change the inputs and not the formula used.

(f) Trees help define the actual location of a file usign sub-directories. If everything was all in the same directory there is no way to tell one thing apart from another other than its name.




(a) You would write a program for any task in which you want to communicate a process, for example, if you wanted to teach someone how to increase the red in a photograph. If you just wanted to increase the red in a picture so you can hang it on your wall, you wouldn't write a program, you'd just use photoshop.
(b)An array is a sequence of elements, each with an index number associated with it. We use arrays to store an ordered list of items.
A matrix is a two dimensional array with elements ranging both vertically and horizontally. Pixels are arranged in matrices, so we deal with matrices when we manipulate picture images.
WHAT IS A GOOD, SIMPLE DEFINITION FOR TREE?
c)You use dot notation to execute a method on an object. It executes a command that is known to that object, but not necessarily anything else. For example, you can do: test="tests stink" print test.capitalize and end up with TESTS STINK.
(d)Red is a bad color for chromakey because there is so much red in your skin, thus your new background would end up on your skin as well when you replaced the red pixels. REMOVED and Blue are better.
(e) A function is globally accessible and a method is not. Methods can only be used with specific objects.
(f)A tree is a better representation for files than an array because a tree allows you to trace the complete path to the file through whatever directories orfolders it may be stored it.
(g)The benefits of vector based representations to Bit-map representations are: 1) much smaller to REMOVEDsfer over the internet because you are not sending pixels. 2) You are sending instructions on how to make the picture, rather than the picture. 3) When you are changing images, you are changing the underlying representation of the picture, instead of just overlapping the pixels.

Will these answers work?
Kelli Webb


A tree is a representation for data where each data point can have multiple child data, the way that a directory can have sub-directories or files. Mark Guzdial


Wouldn't it just print Tests stink? and not TESTS STINK? Cause in the book it only capitalized the first letter of the example...?? Jennifer Garrett

Right, capitalize only capitalizes the beginning. Mark Guzdial




Link to this Page