DISC 3371 |
FINAL EXAM ANSWERS |
NAME: |
Parks |
FALL 1998 |
SSN: |
SIGNATURE:
|
1. (30 points) Using frames, write the VBScript and HTML necessary to produce the following page:
When the user clicks the "Show my Bean Bill" button:
- Calculate the total for the order (i.e., price of the Main Course item chosen + the price of the Side Order chosen + the price of the Dessert item chosen).
- Display this order total in the text box to the right of the "Show my Bean Bill" button.
ANSWER:
|
TOP LEVEL |
<html>
<frameset rows="*,*,*">
<frame src="row1.htm">
<frame src="row2.htm">
<frame src="row3.htm">
</frameset>
</html>
|
|
ROW 1 |
Alice's On-Line Beanery
|
|
ROW 2 |
<html>
<frameset cols="*,*,*>
<frame src="col21.htm">
<frame src="col22.htm">
<frame src="col23.htm">
</frameset>
</html>
|
|
Col21.htm |
<html>
<body>
<form name="c21form">
<b>Main Course</b>. Select One:
<br><input type="radio"
name="r1" checked value="1">
Beans ($6.00)
<br><input type="radio"
name="r1" value="2">
Beans and Beans ($7.00)
<br><input type="radio"
name="r1" value=-"3">
Beans, Beans & More Beans ($8.00)
</form>
</body>
</html>
|
|
Col22.htm |
<html>
<body>
<form name="c22form">
<b>Side Order</b>. Select One:
<br><input type="radio"
name="r1" checked value="1">
Beans ($4.00)
<br><input type="radio"
name="r1" value="2">
Beans and Beans ($5.00)
<br><input type="radio"
name="r1" value=-"3">
Beans, Beans & More Beans ($6.00)
</form>
</body>
</html>
|
|
Col23.htm |
<html>
<body>
<form name="c23form">
<b>Dessert</b>. Select One:
<br><input type="radio"
name="r1" checked value="1">
Beans ($0.80)
<br><input type="radio"
name="r1" value="2">
Beans and Beans ($1.60)
<br><input type="radio"
name="r1" value=-"3">
Beans, Beans & More Beans ($2.40)
</form>
</body>
</html>
|
|
ROW 3 |
<html>
<head>
<script language="vbscript">
<!-----
sub sbut_onClick
dim form1,form2,form3
set form1=top.frames(1).frames(0).c21form
set form2=top.frames(1).frames(1).c22form
set form3=top.frames(1).frames(2).c23form
'checks each radio button, if checked set the amount
if form1.elements(0).checked then main=6
if form1.elements(1).checked then main=7
if form1.elements(2).checked then main=8
if form2.elements(0).checked then side=4
if form2.elements(1).checked then side=5
if form2.elements(2).checked then side=6
if form3.elements(0).checked then des=.8
if form3.elements(1).checked then des=1.6
if form3.elements(2).checked then des=2.4
'*** add them up and shows the answer
document.bbill.value=main+side+des
end sub
---->
</script>
</head>
<body>
<center>
<input type="button"
value="Show my Bean Bill"
name="sbut">
<input type="text" name="bbill" size="10"></center>
</body>
</html>
|
|
2. (70 points) Given the following five visible frames:
The top righthand frame contains the following HTML file named "ack.htm":
<html><body><form name="toprightform">
<input type="hidden" name="ak" value="0.0,234.7,876.5,...2,496 more entries...945.7,0.0">
</form>This frame contains ack.htm</body></html>
The string named "ak" contains 2,500 mileage values separated by commas. Each mileage contains a decimal point and one digit to the right ot the decimal, Each mileage value is separated from the next by a comma. No blank spaces exist in the string. The first 50 mileages in the string are the distance from the center of the first state to the center of the rest of the states. Note that in the first fifty, the first entry is 0.0 (i.e., the distance from the center of state 1 to the center of state 1 is 0.0). The second fifty entries are the distances from the center of the second state to the center of the other fifty states, etc. Thus there are 2,500 entries (50 of them are 0.0). The two select boxes contain fifty two character codes for the state abbreviation (AL, AR, AK, AS,...etc.).
When the user clicks the "Show the Distance" button, the distance between the two states chosen in the select boxes is shown in the bottom right hand frame. The frame originally contains the phrase "Put the answer here". You are to rewrite this frame on-the-fly and print the following :
Distance from the center of the first state to the center of the second is: xxx.x miles
The xxx.x is to be the distance the first state to the second state as defined in the string ak.
ANSWER:
The general structure of the frameset is:
Top Level (source f9871f6.htm)
Click this to see it work! |
<html>
<frameset rows="*,*">
<frame src="ftop.htm">
<frame src="fbot.htm">
</frameset>
</html>
|
Then at the next level:
Top Row (source ftop.htm)
|
<html>
<frameset cols="*,*,*">
<frame src="f11.htm">
<frame src="f12.htm">
<frame src="f13.htm">
</frameset>
</html>
|
|
Upper Left Frame (source f11.htm) |
<html>
<body>
<form name="f11form">
<b>First State</b>
<p>
<select name="s1">
<option selected>AL
<option>AR
<option>AZ
<option>AK
<option>CA
.
.
.
<option>WV
<option>WY
</select>
<br>
</form>
</body>
</html>
|
|
Upper Center Frame (source f12.htm) |
<html>
<body>
<form name="f12form">
<b>Second State</b>
<p>
<select name="s2">
<option selected>AL
<option>AR
<option>AZ
<option>AK
<option>CA
.
.
.
<option>WV
<option>WY
</select>
<br>
</form>
</body>
</html>
|
|
Upper Right Frame (source f13.htm) Called either ack.htm or bld.htm on the exam |
<html><body>
<form name="toprightform">
<input type="hidden" name="ak"
value="0.0,234.7,876.5,...
...2,496 more entries
...945.7,0.0">
</form>
This frame contains ack.htm
</body></html>
|
|
Then the bottom row
Bottom Row
(source fbot.htm) |
<html>
<frameset cols="*,*">
<frame src="f21.htm">
<frame src="f22.htm">
</frameset>
</html>
|
|
Bottom Left Frame (source f21.htm) |
<html>
<head>
<script language="VBSCRIPT">
<!----
sub std_onClick
dim dist(2501)
dim frame11,frame12,frame13,targetframe
set frame11=top.frames(0).frames(0).f11form
set frame12=top.frames(0).frames(1).f12form
set frame13=top.frames(0).frames(2).toprightform
set targetframe=top.frames(1).frames(1).document
dist_string=frame13.ak.value
'*** this gets the distance string
'*** this is be called "bd"
'*** on some exams
lendist=len(dist_string)
'*** length of distance string
curdist=1
'*** start at position 1
dist(curdist)=""
'*** with an empty distance element
for i=1 to lendist
'*** examine each character
thischar=mid(dist_string,i,1)
'*** get next character
if thischar = "," then
'*** if comma, next distance
curdist=curdist+1
else
dist(curdist)=dist(curdist)+thischar
'*** else append the char
end if
next
'*** this loop has produced 2,500 distance elements
st1=frame11.s1.selectedindex
'**** this gets the index of selected first state
st2=frame12.s2.selectedindex
'**** this gets the index of selected second state
loc=st1*50+st2+1
'*** locate the position in the array
targetframe.clear '*** write it out
targetframe.open
targetframe.write "<html><body>"
targetframe.write "Distance from the center"
targetframe.write " from the first state to the"
targetframe.write " center of the second is: "
targetframe.write dist(loc)
targetframe.write " miles</body></html>"
targetframe.close
end sub
</script>
</head>
<body>
<center>
<form name="f12form">
<input type="button" name="std"
value="Show the Distance">
</form>
</body>
</html>
|
|
Bottom Right Frame
(source f22.htm) |
<html><body>
Put the Answer Here
</body></html>
|
|