Exam 1

advertisement
Computer Science 101
Survey of Computer Science
Exam 1
Name:
Fall 2010
Pledged:
1. (40 points) Complete the following:
a. A step by step procedure for solving a general class of problems is called a/an
b. The term for the formal grammatical rules for a programming language is
. The term
refers to the action that the computer would take when it executes the various
types of programming statements.
c. A computer program that converts a program written in some programming
language into the machine language for a specific type of computer is called a/an
d. Circle the items below that WOULD NOT be legal Python variable names:
i. R2D2
ii. pay Rate iii. 2BOr!2B iv. payRate v. else
e. Give the value of the following expressions as computed in Python:
37 * 8
37 / 8
37 - 8
37 % 8
f. Give a Python statement that stores in the variable price a value entered by the user.
g. Give a Python statement that displays the message “Too high!” if the value of price
is more than 100 and displays the message “Fair enough!” otherwise.
h. Circle the ones of the following that WOULD be legal in the given number system
decimal:
238
11011
463
2C4D
R2D2
binary:
238
11011
463
2C4D
R2D2
octal:
238
11011
463
2C4D
R2D2
hexadecimal: 238
11011
463
2C4D
R2D2
i. Suppose we have 3 computer files of sizes 100Kb, 100Mb, 1Gb. List these file
sizes in increasing order:
j. What is the decimal value of the largest number that can be expressed in binary
with 8 bits?
k. Give three pieces of information that can be found in the header section of a BMP
picture file.
l. How many bytes of data are required for each pixel in a BMP file?
2. (15 points) Do the following conversions:
a. Convert the decimal number 184 to binary
b. Convert the octal number 654 to binary
c. Convert the hexadecimal number B8 to decimal
3. (15 points) Convert the binary number 10110 to
a. Decimal:
b. Octal:
c. Hexadecimal:
4. (15 points) Write a Python function called addNums that lets the user input 50
numbers. The function should output the sum of the numbers and tell how many of
the numbers were larger than 100. Write your code neatly and make the exact syntax
(indentations, etc.) very clear. Partial credit if you just get the sum part correct.
5. (10 points) Below is the Python code for a function called perfect. For each part, you
should assume that the user inputs the given number and then step through the
execution of the function with that input. Keep careful track of the value of each
variable and give the exact output that would be produced by the function.
a. User inputs the number 8:
b. User inputs the number 6:
c. User inputs the number 28:
d. User inputs the number 26:
6. (5 points) Suppose the following picture is stored in a BMP file with width and
height both 100 pixels; so each of the maroon and blue squares is 50 pixels by 50
pixels.
Suppose we change the values in the header so that the width is doubled and the
height is cut in half, but all of the color data is left in place. Describe in terms of
maroon and blue rectangles what the picture would like when we viewed it with
JES or Paint.NET.
Download