DISC 3371 FALL 2004
Parks Midterm Answers

1. (50 points) An HTML page is designed to draw the flags of the three Scandinavian countries. The initial page is shown below at the left side. When the page is loaded there is: a form named flagform; a select box named csel, with three options: Denmark; Finland; and Sweden; and a button labelled "GO". The "Finland" option is initial selected. All three flags are formed with two colors: a background color and foreground color that creates a vertical and horizontal cross. The user (1) chooses a Country; and (2) clicks the "GO" button. This event cause a sub named three_flags to be executed.
1. Pick a
   Country

2. Click
    
     a demo.
     See caution
     below
3 2 4 All three country flags have specific ratios of height to width and specify the placement of the centered cross. A sample is shown to the left. Here the ratios are demonstrated for a 3:2:4 horizontal ration and a 3:2:3 vertical ratio. The resulting example flag is 9 units wide (3+2+4=9) and 8 units tall (3+2+3=8). The cross is 2 units wide (fourth and fifth columns AND four and fifth rows). For the three flags in this problem the ratios are:
Country Horizontal
Ratio
Vertical
Ratio
Background
Color
Foreground Color
(i.e., the cross)
Denmark 6 : 2 : 9 6 : 2 : 6 red white
Finland 6 : 3 : 10 4 : 3 : 4 white blue
Sweden 5 : 2 : 9 4 : 2 : 4 blue yellow
The 4 1x1 pixel gif files are: blue1.gif, red1.gif, white1.gif and yellow1.gif.
 
 
3
 
 
2
 
 
 
3
                                            
                                            
                                            
                                            
                                            
                                            
                                            
                                            
When the sub three_flags is executed, a new page is created on-the-fly that contains the image of the country's flag chosen in the select box. Assume the following 8 arrays are dimensioned in the sub three_flags: dhr(3),fhr(3),shr(3),dvr(3),fvr(3),svr(3),hr(3),vr(3). The first six arrays are initialized as:
  dhr(0)=6: dhr(1)=2: dhr(2)=9: dvr(0)=6: dvr(1)=2: dvr(2)=6
  fhr(0)=6: fhr(1)=3: fhr(2)=10: fvr(0)=4: fvr(1)=3: fvr(2)=4
  shr(0)=5: shr(1)=2: shr(2)=9: svr(0)=4: svr(1)=2: svr(2)=4

to store the 3 horizontal and 3 vertical ratios (as shown above) for the three countries (Denmark 's are dhr and dvr; Finland's are fhr and fvr; Sweden's are: shr and svr). Once the country is determined, copy the appropriate country's ratios to the arrays hr and vr, respectively. Create the flag using these ratio arrays (hr and vr) and square color blocks obtained by stretching the 1 pixel by 1 pixel images to be 20 pixels by 20 pixels.
For example, the Finnish flag would contain:
  1. four rows each with 6 white 20x20 images, then 3 blue 20x20 images, then 10 white 20x20 images, then
  2. three rows each with 19 (6+3+10) blue (typo -- original said white) 20x20 images, then
  3. four rows each with 6 white 20x20 images, then 3 blue 20x20 images, then 10 white 20x20 images
Set the new page's background color to a shade of gray. Be sure to use the appropriate color for the foreground cross and background for each country. Use NO tables. Using VBScript write ONLY the sub named three_flags. Show NO HTML.

Click "VIEW", then "SOURCE" to see the answer code
CAUTION: Some "popup blockers" will prevent the demo from working. Turn it off to see the 3 flags demo

2. (50 points) A famous secret code by Thomas Jefferson Beale used a unique method to encrypt a secret message. The method involved numbering the words to the U.S.A.'s Declaration of Independence. Then he would take each alphabetic letter in the message to be enciphered and substitute the letter with a number that represented a word in the Declaration that began with that same letter. Below is: a textarea named di that contains the entire Declaration of Independence (each word is separated by a comma); a second textarea named secret that contains a secret message (53 integers separated by commas); and an empty textarea named answer.
Declaration of Independence Secret Message Answer
Click to see the code work
The textareas are contained in a form named dform. When the "GO" button is clicked: call a function named beale(); create an array named d and store the all words of the Declaration in d (there are 1,322 words). Store the first word in the d array element one -- i.e, the second element. Thus "When" is d[1]; "in" is d[2]; "the" is d[3], etc.); using the numbers in the textarea named secret (53 integers separated by commas) decode the message by using each integer in the secret textarea to locate a word in the d array, then append the FIRST letter of the word to your answer. Place the final decoded message in the textarea named answer. Write the javascript function beale(). Show NO HTML.

Click "VIEW", then "SOURCE" to see the answer code