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

Midterm Exam 2 Review Fall 2003: Short Essay

Answers? Comments? Questions on Answers? Questions on Comments?

(Back to Fall2003 Midterm Review 2)

Question 1
Short Essay


1. 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.
2. 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.
3. What is dot notation and when do you use it?
4. Why is red a bad color to use for chromakey?
5. What's the difference between a function and a method?
6. 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?



I have an idea what array, matrix, and tree mean. But I am a little unsure about the examples. So here are my guesses. Array- sound. Matrix- picture. Tree- Lists(?), directories in the computer.
NIFTY! Mark Guzdial

Could you please give a hint on #1? Do you want a situation when we have an easy task so we don't need a program and an example with a very complicated task that would certainly need a program?
Yes. Think about a program that can be helpful for a difficult task. Also, think about what can be easily done in JES. Angela Liang

  1. 6 Is it because it is easier to find the files and manipulate them? And having many directories allows to narrow down to the specific type of file and makes searching and manipulating it easier? Is that somewhat close?
Think about how your hard drive is organized. Do you have a list of everything on your drive in one place or is it separated into folders? Angela Liang
Yes, you have the basic idea. Spell it out a bit. How many files do you have on your disk? Imagine that they were all in one great big folder (like an array instead of a tree). What would you do to find a file? Now, think about your disk today, with multiple directories. What do you do to find a file? Why is one faster than the other? Mark Guzdial


An array is a continuous line of elements that we have used to represent data in the form of sound and text. A matrix is a two-dimensional array, containing both width and height that we have used to represnt pictures. Trees are elements that being with one "root" and "branch" out into different directories which eventually end in "leaves" or files. Each path on the tree leads to a different file.
Nina Barlin

Dot notation is used to access certain capabilities of a file (module) that have been imported to a computer and contain additional functions and objects that JES originally did not. It is written as "module"."function"? (I'm not sure about that last part)
Nina
Not just "modules" – check out the string methods. Mark Guzdial

We write programs when we want to illustrate the process of the task being completed. That way, others can open up the program both to see what how we accomplished the task and to be able to tweak the program for their own use. Writing a program might be useful when one wants to take a bunch of numerical data and run it through a lengthy series of mathematical operations. So instead of using the existing calculator application to divide x by y, take the integer of the outcome, add five, etcetera, you just write a program that will do the task over and over again in one easy step. If illustrating process and facilitating mimicability isn't important, like for shrinking an image for a website, then photoshop or another existing application are fine alternatives.
Nina
Nice answer! Can anyone come up with a media-related example? Mark Guzdial


With an array, your computer would have to search through every file you have on one directory to find what you are looking to access. This would take forever, especially when you are trying to write programs trying to access certain files. A "tree" system of setting up a disk allows you to have a specific path from the directory into folders and eventually into individual files. This way, the computer can easily (and quickly) access a certain file, and the user can see a specific path to that file, without going through every single file on his directory first.It also allows you to group certain types of files together in folders for easier and more organized access. You could not do this with an array.trees allow for faster access under some conditions, and are useful for organizing.\
Nina




1) You do not need to write a program to save a picture outside JES, you can simply use the writePictureTo command. You do need to write a program to create a collage for a picture in JES.
That's not what we meant. When would you create a picture in, say, Photoshop, vs. writing a program in JES to create a picture? Mark Guzdial
2) An array is a sequence of elements. A sound is an array with a sample value at each index. A matrix is a 2-dimensional array, similar to a grid with rows and columns. A picture is a matrix of pixels with a red, green, and blue value at each index of the matrix. A tree is information stored as a root and branching elements. Directories are a tree made up of a drive as the root, folders as branches, and files as leaves.
Good explanation of each - Jack DeBussey
3) Dot notation is similar to using ‘s in that it says “call the method to the right of the dot which belongs to the object to the left of the dot.” You use dot notation whenever you are executing a method on an object.
4) Red is a bad color to use for chromakey when dealing with people because most people have a lot of red in the color of their skin. Therefore when you subtract the red background, you end up subtracting part of the person as well.
5) Methods are functions known only to certain objects.
6) Directories are not stored in a linear fashion (linearly didn’t sound like a word). Because arrays are a linear collection of elements, it would not be efficient to store files on a disk as an array.

im not sure about #5, i just copied my answer verbatim from the powerpoint slides. i dont really understand the question because i though 'method' and 'function' could be used interchangeably.
No – makePicture is a function, reverse and find are methods. Mark Guzdial

I remember object-oriented programming from C++.

Modules are classes of data types that just happened not to be integrated into the direct JES library. The programs (.py) which they reference are accessed to define their properties. For instance, a picture is a data type; the only difference being that JES already runs the programs that define what a picture is and what functions apply to it whenever it compiles the interpreter.
Whoa! Lots of hiccups here: Modules are the JES library. There is no compiling of interpreters going on in here. What programs does JES run? I'm confused. Mark Guzdial

Do you also use dot notation for modules, ie os.listdir()? I'm a little confused because methods seem to use variable.method while as I understand it, modules use module.function - am I about right or totally off?
You're right. In Python, modules are very much like objects. Think of it as always being object.partOfTheObject Thus string.find("fred") is saying to call the method find (which is part of that object) on the string object. module.function() is another form of the same thing. As we'll see in a few weeks, we'll also have object.variable. Mark Guzdial


5. a function is a recipie that tells the computer how to do something. a method is a speical function that only objects of the same type understand. methods are already built into the system, but you have to use dot notation to execute them, telling the computer exactly which object and method to change.

What's this notion of "built in"? Both methods and functions are "built in" the same way. "Modules" are "add ins," but modules can add both methods and functions. Mark Guzdial


So, we still do nt know the difference between a function and a method. Any help here?

Well (a) it's in the book, (b) it's in the slides, (c) I've explained it several times in class, and (d) there are several answers above, including some that I gave. I'd say that that's "any help." Basic idea: Functions are accessible anywhere – from Command Area, from Program Area, just by using their name. Methods are functions that are known only to certain kinds of objects. Their names only make sense to those objects, and you have to use dot notation to execute them. Mark Guzdial




Link to this Page