CS460/CS565 Languages Midterm 1

Fall 2010

  1. This exam is a take home exam. It is due Thursday, Sept. 23 at 5:00pm.
  2. Submit your answers using the 460_submit or 565_submit scripts. When prompted for a number, enter "midterm1" instead.
  3. Each problem tells you the name of the file in which you should place your answer. Questions 1 and 7 ask you to put your answer in a file named answer.txt. Please just make this file be an ascii text file. You can create such a file using vi, emacs, notepad, etc.
  4. I will test your answer with sample input so try to make sure your answer works. I will award partial credit if your answer does not work.
  5. You must answer all of the questions.
  6. Don't waste time trying to come up with the most elegant answer possible. Remember that the point of using a scripting language is to write a program as quickly as possible.
  7. Good luck!

  1. (14 points, answer.txt) Suppose you are designing a driver's license renewal web-site for the state of Tennessee. For each of the following scenarios, pick the most appropriate form element to use from the list below:

    textboxpassword boxtext area
    hidden fieldsubmitreset

    1. The user should select the county in which they reside. There are about 95 counties in Tennessee, but you do not want the user to be able to enter an incorrect county.
    2. The user should enter their zip-code.
    3. The user should select a private keyword that they can use to log back into the site and edit their information
    4. The user is asked to select any of the following options that apply: wears corrective lenses, has disabilities that could affect their driving, is over the age of 65, had a traffic ticket in the past year, had an accident in the past year, drives a car built before 1960.
    5. The user should have an area where they are asked to enter any additional information that they think would be useful for the case officer to know when weighing whether to renew the person's license, such as the nature of any disabilities, or the circumstances surrounding an accident or traffic ticket.
    6. The person enters their eye color as one of blue, green, brown, or hazel.
    7. The person enters their height in feet (4-7) and inches (1-12). If using more than one form element, then choose the same form element for both feet and inches.

  2. (12 points, table.html) Create an html table that displays the following stylized (and not chemically correct) periodic table of elements:
    The html table should have the following characteristics:

    1. The table headers (I-VII) should be bold-faced.
    2. The atomic elements should be left-aligned and vertically centered
    3. The table title (Periodic Table of Elements) should be vertically top-aligned.
    4. The H (hydrogen) element should be colored light green and the VII column should be colored gold
    5. The cells should have a cellpadding of 10.

    Your html table must not use a stylesheet.

  3. (12 points, table3.html, table.css) Now you are going to improve the look of your html table from the previous problem using a style sheet. You should take your html from the previous problem, put it in table3.html, strip out the visual formatting attributes, and link in table.css. table.css should contain a external style sheet that creates the following visual characteristics:

    1. The headings (I-VII) are colored red.
    2. The table title (Periodic table of elements) is colored green, bold-faced, is vertically aligned with the top of the table, and starts 20 pixels from the top of the table (hint: you do not need absolute positioning to get this 20 pixels of separation).
    3. The table elements should have a width of 100 pixels, a height of 60 pixels, and the labels should be both horizontally and vertically centered (note that the table headers retain their previous size).
    4. The elements in the first column should be light green, the elements in the second column should be cyan, and the elements in the last column should be gold.
    5. In the first row, the right border of the left empty cell should be removed and the left border of the right empty cell should be removed.
    The end result should look something as follows:

  4. (12 points, legend.html) Create an html file with an internal style sheet that duplicates the appearance of the legend for a periodic table of elements that is shown below:
    You are free to re-create this legend using either an html table or div blocks. In either event you will need to use style sheets to achieve some of the desired visual effects. The visual characteristics of this legend should include:

    1. There must be a border around the legend with the label "Legend" inset in the border.
    2. The "Legend" label should have a padding of 5 pixels around it. It should appear near the left of the legend block (30 pixels if using a style sheet) and should be roughly centered in the boundary.
    3. The columns of color chips should be left aligned.
    4. The color chips should be 60 pixels wide and 20 pixels high
    5. The 4 columns should be equal sized, but it is up to you to come up with a way to make them equally sized.
    6. Don't worry about resizing the browser--just make the layout be a 2x4 layout for a sufficiently wide browser.
    7. The labels do not have to be vertically centered with respect to the color chips--it is okay if they are top aligned or bottom aligned.
    8. There should be a few pixels of separation between the color chips and the labels.
    9. The color chips should use the following colors:
      • non-metals LightGreen
      • transition DarkTurquoise
      • rare-earth LightBlue
      • halogens yellow
      • alkali orange
      • alkali-earth aqua
      • other MediumPurple
      • inert DarkRed

  5. (12 points, periodic-cell.html): Write an html document with an internal stylesheet that creates the periodic cell element shown below:
    The specifications for this problem are as follows:

  6. (12 points, paper.css) Create an external style sheet for the page layout shown below:
    The visual characteristics of the document are as follows:

    Here is a sample html file to work with.

  7. (8 points, answer.txt) What is the similarity between the keywords local and my in Perl. What is the difference between them?

  8. (6 points, fox.pl) Use a foreach loop to iterate through the lines of stdin and print those lines that contain the word "fox". For example, if stdin contains the lines:
    the quick brown fox jumped
    over the fence
    and then the fox eluded the fox
    pursuing dogs.
    your output would look like:
    the quick brown fox jumped
    and then the fox eluded the fox
    Do not worry about cases where fox is contained as a subpart of another word (e.g., "fox." or "mefoxin") or where parts of fox might be capitalized (e.g., "FOX" or "Fox"). My test data will not contain either of the above two patterns. In case you are interested, the pattern I am asking for would match strings where fox was a subpart of another word but would not match strings in which part of fox was capitalized.

  9. (12 points, count.pl) Copy the file ~bvz/scripting/exams/midterm1/count.pl. count.pl counts the frequency with which words occur in standard input. In order to make it work, add to count.pl a Perl function named incrementCount that takes a key and a reference to a hash as parameters. If the key is in the hash, then incrementCount increments the key's value field by 1. If the key is not in the hash, then incrementCount inserts the key into the hash and assigns it a value of 1. Words with different capitalizations ("Quick" and "quick") should be considered as separate words, as should words that end with punctutation (e.g., "quick" and "quick." should be considered as separate words).