Final Exam, COSI2a, Autumn 2003
open book, open notes, no computer, 3 hours
(2 pts) I. Binary, Decimal, and Hexadecimal Numbers
- Convert 129.64.9.127 to hex
- Convert FADECAFE from hex to binary
(20 pts) II. Servlets - ANSWER
You are to write the code for
exam03.servlet which is described below:
-
When you first visit this servlet it generates the following page, with all fields
initially blank.
This page asks for your first name, your email, a
URL of your picture, your age in years, and then asks you to select one of three options.

-
If you click on the first option -- "compute retirement year" --
it will determine the year you retire (assuming you retire at age 65) and will
generate the following page.

-
If you click on "create Holiday card" it will generate the following page.
Notice that the URL of the two pictures on the card is the web address appearing
in the middle of the card, which is the address you typed into the form:

-
Finally, if you click on "send link to this Holiday card", it will send you an email
and generate a response page (as shown below), both of which contain a link.
Clicking on the link brings you to this servlet with these particular parameters!

(15 pts) III. Applets - ANSWER
Write the Scheme code for the applet that appears below:
-
It prompts the user for four numbers (x1,y1,x2,y2)
-
When the user presses the button it draws a triangle
on the screen where the three vertices are (0,0), (x1,y1), and (x2,y2)
-
Then it computes the number of pixels in that triangle using the following formula:
area = (x1*y2 - x2*y1)/2
and it write the area in the label at the bottom of the window.
(1 pts) IV. Tracing Logic Circuits
Draw a logic circuit with two inputs A,B two outputs C,D and which contains
one AND gate, one XOR gate, and one NOT gate. Determine what the outputs C and D will
be when the inputs are A=0 and B=1. Also compute the values on all intermediate wires
that connect one component to another.
Note: you can draw any type of a circuit you want, but it must have those three
components, two inputs, and two outputs.
(2 pts)V. Tracing Scheme Procedures
- Trace every step of the evolution of the following process:
(+ (sqrt (+ (* (- 10 6) (- 10 6)) (* (- 8 5) (- 8 5)))) 10)
- Trace through every procedure call in the evolution of the following process:
(define (f x y)
(if (< x 1)
1
(if (odd? x)
(* y (f (- x 1) y ))
(f (/ x 2) (* y y)))))
(f 11 2)
(1 pt) Extra Credit
Write a Scheme procedure mysched that can be called as follows:
(mysched '(
(time M T W T F S S)
(9:00 cs2a - cs2a cs2a - - -)
(9:30 cs2a - cs2a cs2a - - -)
(10:00 - - - - - - -)
(10:30 - ec2a - - ec2a - -)
(11:00 - ec2a - - ec2a - -)
(11:30 - ec2a - - ec2a - -)
(12:00 - - - - - - -)
))
and which will generate an HTML table where the "cs2a's"
are in "td" elements with a yellow background and
"ec2a's" have a blue background, and the "cs2a's"
all have a link to the CS2a web page, while the
ec2a's have a link to the Econ2a web page (just make it up!)
The "-" elements should have a white background.