SPRING 09 The following is a list of topics and sample questions. Being able to answer the sample questions will help you answer the midterm questions. Review these questions, course notes and in-class assignments, and practice answering and coding with pencil and paper.Iteration, Lists, and Matrices
What is the template code for processing a list?
Write a function to find the minimum value in a list.
What is the template code for processing a matrix or two-dimensional data set?
Write a program to find the sum of all values in a matrix.
What is the template for drawing one image on another, using JES?
Write a function that determines whether a string is a number (all digits). Write using a boolean variable as the loop condition.
Write a function that determines whether a string is a valid color in the Mastermind game. Write this without using 'in'Functions, Parameters, and Modular Programming
The function copyPic, as suggested by your instructor, does not return a value. The function to scale an image does. Explain why. Could we have defined either one differently?
What are the ways in which a function can affect data in the caller (client)?
When a parameter is sent to a function, what is actually sent? For a scalar? For a list? For an object?
Trace the following code, using boxes and arrows:
def computeExactMatches(secret,guess,exacts): i=0 while i<4: if secret[i]==guess[i]: exacts=exacts+1 secret[i]=99 guess[i]=88 i=i+1 #main list1 = [3,5,2,6] list2= [3,5,5,1] exacts=0 computeExactMatches(list1,list2,exacts) computeExactMatches(list2,list1,exacts) # note params are different
It is considered poor programming practice to refer to global variables
directly within functions. Explain why, and explain how one can avoid
referring to global variables within functions.
Provide an example,
from the Mastermind program, where a global is referred to in a
function, and show how the code can be rewritten so that the global is
not referred to ( you need not show an entire function, just
the illustrative parts).Object-Oriented Programming
What are the components of a class?
What are the key bookkeeping methods for a class? What are the special ways in which they are called?
How is calling an object-oriented function different from calling a non-object-oriented function.
Write a class Student that tracks a student's grades. What data members should the class have? Should there be other classes involved? The class should have a function for inputting grades and for computing GPA.
Write Mastermind in an object oriented way. What classes would you define?The Hash Table and Big-O Algorithm AnalysisSuppose you had a class Person with data members name, ssn, and address. Show how you would put person objects into a hashable using Python's built-in hashtables (Dictionaries). How would you retrieve person objects from the hashtable?
Describe how hashtables are implemented and how a well designed one can provide an efficient search. Show understanding of Big-O analysis in your answer.
Beneath the HoodWhat's the largest number that can be stored in 4 bits? In N bits?
What is the base-10 equivalent to 10101. What is the base-2 equivalent to 83?
What is really stored for: s = "abc"
Address 77 refers to what bit in memory?
How is the memory of a computer organized? What are the main sections? Assume that variables are stored beginning at memory address 0. Show the main memory and symbol table after execution of the following: name="joe" x= 92 y = x+77 Be sure and specify any assumptions you make.Programming Terms Be able to identify and define the following:
local variable global variable variable scope scalar formal parameter actual parameter pass-by-reference parameter
| pass-by-value parameter object class data member field instance variable object-oriented function self |
|
|