CSC 104 exam questions and solutions, April 2010

University of Toronto
Faculty of Arts and Science

April 2010 Examinations

CSC 104H1S

Duration: 3 hours

No aids allowed

Make sure you have all 12 pages (including this page). (Don't panic about the page count -- there's lots of space for answers.)

Answer all questions. Answer questions in the space provided. Answers not in the correct space will not be graded unless a note in the correct space says "see page ..." and the answer on that page is clearly labelled with the question number.

Be careful not to get stuck on some questions to the complete exclusion of others. The amount of marks or answer-space allotted does not indicate how long it will take you to complete the question, nor does the size of the answer-space indicate the size of the correct answer.


1. [8 marks]
Consider the algorithm "walk down the street until you see a white building on the left".

(a) In Computer Science we generally require algorithms to "terminate when followed". Under what circumstances would the above algorithm not terminate when followed?

(b) How could you change the statement of the algorithm so that it meets this requirement?

[solution]


2. [4 marks]
(a) The ASCII character code mentions letters (lower-case and upper case), digits, and some other characters. Give two examples of other characters which are included in the ASCII character code (other than letters and digits).

(b) Give one example of a character which is not included in the ASCII character code.

[solution]


3. [5 marks]
You have a user name and password for the CDF computers.

(a) What is the purpose of the user name?

(b) What is the purpose of the password?

[solution]


4. [5 marks]
(a) State one advantage of the modern "desktop" graphical user interface over a command-line interface (e.g. the terminal window).

(b) State one advantage of a command-line interface over the graphical user interface.

[solution]


5. [8 marks]
State the output from each of these Python programs:

(a)

	x = 3
	y = 5
	print 'x'

(b)

	sum = 0
	for i in range(2,5):
	    sum = sum + i
	print sum

(c)

	sum = 0
	for i in range(2,5):
	    sum = sum + i
	    print sum

(d)

	x = 2
	while x < 10:
	    x = x * 2
	print x

[Solutions: Just run the thing and see! But as with all of these problems, please try working it out before you look at the answer.]


6. [10 marks]
Write a Python program to print the following output, using a loop. Note that you "square" a number by multiplying it by itself, and note that the "6" line is missing below.

	1 squared is 1
	2 squared is 4
	3 squared is 9
	4 squared is 16
	5 squared is 25
	7 squared is 49
	8 squared is 64
	9 squared is 81
	10 squared is 100

[solution]


7. [16 marks]
Here is a spreadsheet modelling the growth of bacteria in a confined space:

The table in the first four lines is entered manually. After that, each row represents the progress within one hour. We list the bacteria count at the start of the hour, the number of new bacteria created, the number of bacteria which die, and the bacteria count at the end of the hour (which is the bacteria count at the beginning of the next hour).

The new-bacteria value is the start amount times the creation rate, using the ROUND built-in function to make this an integer (there's no such thing as a live fractional bacterium).

Similarly there is a death rate. At least this many bacteria will die. However, there is also a crowding limit. The most bacteria which can survive at once is the crowding limit in cell B2. Thus, the "end" column will never show a value greater than the B2 value.

Write the formulas for these cells as directed below, in the style of a spreadsheet program such as Gnumeric.

A7:
B7:
C7 (to be copied down):
D7 (to be copied down):
E7 (to be copied down):
A8 (to be copied down):
B8 (to be copied down):

[solution]


8. [6 marks]
In this course we have limited ourselves to the "structural" HTML tags, avoiding the "appearance-oriented" HTML tags.

(a) What is an advantage of using only the structural tags?

(b) What is a disadvantage of using only the structural tags?

(c) Imagine using none of the structural tags, and specifying everything only by font name and size, etc. What would be the consequence?

[solution]


9. [12 marks]
Write HTML code to produce a web page which looks like the following. There is no available character for "[one third]" but there is a small picture file you can use (just as was done in assignment three for the fancy letter O) at http://www.dgp.toronto.edu/~ajr/gen/13.gif
(You can skip copying out all of the words below so long as your intention is clear.)


Vinyl Records

Vinyl records were recorded at different speeds. Standard speeds were 16, 33 1/3, 45, and 78 RPM.

Some people miss them, but I like my MP3 player better.


[solution]


10. [8 marks]
Convert the following base ten numbers to base two (binary):

(a) 30

(b) 28

Convert the following base two numbers to base ten:

(c) 100101

(d) 101100

[solution]


11. [8 marks]
Assignment four involved sorting the array containing the piles of sticks.

(a) Describe the sorting algorithm briefly.

(b) We then got rid of zeroes at the beginning of the array. Suppose the array is named "gamestate". Write Python code to check whether the first element of gamestate is zero, and if so, to remove that item from the array.

[solution]


12. [10 marks]
Write a Python program to prompt for and input two positive numbers (integers). Add together all of the integers from 1 to the first number, and multiply together all of the integers from 1 to the second number, and tell the user which one is larger.

(For example, if the first number were 5, you would compute 1+2+3+4+5, which is 15; and if the second number were 4, you would compute 1*2*3*4, which is 24.)

[solution]


End of exam. Total marks: 100. Total pages: 12.


[main course page]