MIS 3371 EXAM 1 SUMMER 2016 PARKS ANSWERS (view source)

Top 100 US Cities
From www.baruch.cuny.edu

1. (50 points) The Top 100 US Cities are shown to the left in a form named f1 in a textarea named t1. For each of the 100 cities downloads, the following data is shown:
   1. rank (from 1 → 100) followed by a ";"
   2. city name followed by a ";"
   3. state name followed by a ";"
   4. population followed by a ";"
   5. website URL followed by a ";"
   6. text for website link followed by a "*"
      (except the last one which does NOT end with a "*")

1. Create 100 row, 5 column table that contains:
   1. in column 1 the rank
   2. in column 2 the city name
   3. in column 3 the state name
   4. in column 4 the population
   5. in column 5 a link using the website URL (#5 above) and link text (#6 above), like this:
      <a href='"+website URL value+"'>"+text for website link value+"</a>"
2. Accumulate the total population in the 100 cities.
3. Accumulate the total population of all cities in the state of "Texas".
Note: When performing arithmetic with the population values you must first remove ALL the commas in the population field

When completed, place: (1) the 100 row 5 column table; (2) the total population count; and (3) the total Texas population in the DIV block with id="p1out". When the user clicks the "Execute p1" button, the javascript function named "p1" is executed. Show NO HTML. Write only the javascript for p1. Do NOT write a table heading row.

This is the DIV with id="p1out"

 
2. (50 points) The textarea named t2 shown to the left is in a form named f2. It contains the relative frequency of the 26 letters a → z in 14 different languages. For each of the 26 letters, there are 15 data items:

      the letter followed by a ";"
      the % frequency of letter in French followed by a ";"
      the % frequency of letter in German followed by a ";"
      the % frequency of letter in Spanish followed by a ";"
      ...
      the % frequency of letter in Czech followed by a "*" (except the last one)

The languages abbreviations are stored in a 14 element array named lname. Assume this array is available in your code (DO NOT write this array).
  var lname=["Fre","Ger","Spa","Por","Esp","Ita","Tur","Swe","Pol","Dut","Dan","Ice","Fin","Cze"];
The function p2 produces 26 tables (one for each letter a→z) showing a vertical bar graph and other data about the frequency of the letter in each of the 14 languages. For each of the 26 letters (a→z) create a 4-row by 14-column table:
1. The first row contains the letter centered in bold that spans all 14 columns
2. Each of the 14 cells of the second row contains a gif image whose height is
   determined by the frequency of the letter in the language: Calculate the bar graph height by:
      h = parseInt( letter_frequency_for_the_language * 10 );
   Then define the cell as:
      "<td valign='bottom'><img src='black1x1.gif' width='20' height='"+h+"'></td>"
3. Each of the 14 cells the third row contains the letter frequency like this:
      "<td>"+parseFloat(letter_frequency_for_the_language).toFixed(1)+"</td>"
4. Each of the 14 cells of the 14 fourth row contains the language abbreviation from the lname array.
Place the 26 tables in the DIV block with id="p2out". Show NO HTML. Show only the javascript for p2.

This is the DIV block with id="p2out"