Answers to DISC 3371 Midterm Spring 2002 Parks

1. (50 points) The server sends an HTML page that contains a form named iform. On this form the user enters the dollar amount of their seven annual household expenditures: Housing; Food; Apparel; Insurance-Pensions; Health Care; Transportation; and Other (store these category names in a seven element array named explabel). The initial page also provides a button labelled "Compare". A sample of the initial page is show to the left below with sample user data entered into the seven text boxes. When the user enters their seven expenditure amounts and clicks on the button, a function named income is executed. This function produces the page shown below to the right "on-the-fly". It is a graphical comparison of the national expenditure values and percentages against the user's amounts and percentages. The national percentages for these expenditures are: 33; 14; 5; 10; 5; 19; and 14 percent respectively (these are stored in a seven element array named npc). The 1998 average national total household expenditure is $35,535. The national amounts are obtained by multiplying the seven percentages above by the national total ($35,535) and dividing by 100. Store these in a seven values in an array named nexp. The expenditure amounts for the user are entered in the seven text boxes on the initial page. Store these in a seven element array named uexp. The user's percentages are calculated by summing the seven user values and calculating the percent of the user total for each category. Store these in a seven element array named upc. The bar graphs are produced by streching either a gray one-pixel-by-one-pixel gif named g1x1.gif for the national data OR a black one-pixel-by-one-pixel gif named b1x1.gif for the user data. The widest bar is 300 pixels. Every bar is 10 pixels tall. (i.e., the largest (maximum) expenditure will produce a bar 300 pixels wide; an expenditure of half that amount will produce a bar 150 pixels wide, etc.).

Initial User HTML Page
ExpenditureYour Annual $
Expenditure
Housing
Food
Apparel
Insurance-Pensions
Health Care
Transportaion
Other
Click the button above to see it work
Click VIEW, then SOURCE to see the code
 
Script HTML Page Output
Expenditure Gray: USA amount (percent) -- Black: your amount (percent)
Housing 11727 (33)
16850 (36)
Food 4975 (14)
7300 (16)
Apparel 1777 (5)
2850 (6)
Insurance-Pensions 3554 (10)
4900 (10)
Health Care 1777 (5)
2650 (6)
Transportation 6752 (19)
6550 (14)
Other 4975 (14)
5700 (12)

Write only the Javascript code for the function named income. Do not edit the user's data (i.e., do not check for numeric user values and do not test to see that a user has entered all seven values). Do not show the HTML for the initial page.

Click the States in
Increasing Population Order
California
Florida
Georgia
Illinois
Michigan
New Jersey
New York
Ohio
Pennsylvania
Texas
Try this table above-- it works
Click VIEW, then SOURCE to see the code
  2. (50 points) A ten row two column table is shown to the left. Each row contains: a checkbox; a state name; and a textbox that is initially blank. The states appear in alphabetical order. The user will attemp to place the states in increasing population order by clicking the checkboxes. When a checkbox is checked, the state name is placed in the next available (i.e., empty) textbox in column two. Thus as the user clicks checkboxes, the textboxes are filled with state names indicating the user's guess about the order of the state's population. When a state's checkbox is "unchecked" the state's name is removed from the textbox in column two and all other state names below that newly unchecked state are moved up one row.Two ten element arrays are used: (1) sn contains the state names in alphabetical order (as shown in the first column -- CA, FL, GA, etc.) and (2) correct contains the state names in the correct population size order (i.e., CA, TX, NY, etc.). After the user checks the tenth state (i.e., all checkboxes are checked), the program grades the list by comparing the contents of the ten textboxes to the array correct. If the user has ordered the textboxes correctly a message box appears that says"CORRECT" otherwise the message box says "WRONG". Use a hidden variable named nextavailable to store the location of the next available empty textbox. This variable is initialized to 1 and appears after the table. The HTML for the checkbox appears as:

  <input type="checkbox" onClick="rankit(0)"> California
  <input type="checkbox" onClick="rankit(1)"> Florida
  <input type="checkbox" onClick="rankit(2)"> Georgia  etc., etc.

The sub is named rankit. In this sub DO NOT write out the declaration and initialization of the sn or correct arrays (to save time). Show only the VBScript code for rankit.