DISC 3371 Midterm Spring 2003 Parks - Answers

1. (50 Points) An questionnaire is presented on an HTML page that allows the user to measure their programming aptitude. The exam has ten multiple choice questions about programming. Each of the ten questions has five possible answers. The table below shows on the left side: (a) the beginning portion (the first three questions) and (b) the end of the page (a button, a hidden variable named answers that contains a ten character string that represents the correct answers to the questions and a <form> end tag. Questions 4 through 10 have been omitted for brevity. On the right side of the table is the HTML that generates the exam. Again only (a) the the beginning portion of the HTML (the title, and first three questions) and (b) the button, the hiddden answer object, and the <form> tag are shown). Again questions 4 through 10 have been omitted for brevity.

Programmer Apptitude Test
1. A conjuction is formed by two Boolean conditions and a...
1. XOR
2. OR
3. =
4. AND
5. ==
2. A test of equality for two real numbers ...
1. is never true
2. is always true
3. cannot always be made accurately
4. is always accurate
5. generates an error
3. An integer divided by an integer produces...
1. a real
2. an integer
3. a character
4. unpredictable results
5. causes an error
.
. next seven questions are similar
.
<center><b>Programmer Apptitude Test</b></center>
<form name="testform">
<b>1. A conjuction is formed by two Boolean conditions and a...</b><br>
1. <input type="radio" name="q1"> XOR <br>
2. <input type="radio" name="q1"> OR <br>
3. <input type="radio" name="q1"> = <br>
4. <input type="radio" name="q1"> AND <br>
5. <input type="radio" name="q1"> == <br>
<b>2. A test of equality for two real numbers ...</b><br>
1. <input type="radio" name="q2">is never true <br>
2. <input type="radio" name="q2">is always true <br>
3. <input type="radio" name="q2">cannot always be made accurately <br>
4. <input type="radio" name="q2">is always accurate <br>
5. <input type="radio" name="q2">generates an error <br>
<b>3. An integer divided by an integer produces...</b><br>
1. <input type="radio" name="q3">a real <br>
2. <input type="radio" name="q3">an integer <br>
3. <input type="radio" name="q3">a character <br>
4. <input type="radio" name="q3">unpredictable results <br>
5. <input type="radio" name="q3">causes an error <br>
.
. next seven questions are similar<br>
.
<p>
<input type="button" value="Grade My Exam" onClick="grade_it()">
<Input type="hidden" name="answers" value="4321542314">
</form>
When the button is clicked a function named grade_it is executed that grades the exam. The function compares the user's ten answers to the correct ten answers stored in the hidden variable answers. The function produces a new page on-the-fly that shows in order: (1) the number correct; (2) the number incorrect and (3) for each incorrect question: the question number (1,2,3, ... ,10), the user's answer (either: 1,2,3,4,5 or "NO ANSWER") and the correct answer (either: 1,2,3,4 or 5). Write only the Javascipt function grade_it. If the user fails to answer a question, the question is counted as incorrect (Note that the string "NO ANSWER" is used in reporting such occurences).

Click here to see the answer to this question

2. (50 points) An HTML page provides: (1) a form named dform; (2) a single textbox named user_digit of size="1"; (3) wg.gif that contains one white pixel; (4) bg.gif that contains one black pixel; and (5) and a button named labelled "GO". The user must enter a single digit (0,1,2,3, ... ,9) and then press the "GO" button that causes a sub named show_digit to be executed. This sub creates a new page on-the-fly with an expanded graphical representation of the digit. The sub contains a ten element array named digits. Each element of the array contains a 35 character string composed of the letters O and X that represents the pixels in a 7 pixel high by 5 pixel wide block letter presentation of each digit 0 through 9.
OXXXO
XOOOX
OOOOX
OOOXO
OOOOX
XOOOX
OXXXO
 For example, the fourth element of digits (i.e., digits(3)) is where the number 3's representation is stored. The string for 3 would be:
OXXXOXOOOXOOOOXOOOXOOOOOXXOOOXOXXXO
If we present this string in a 7 row and 5 column format (i.e., the first five characters make up the first row, the next five characters make up the second row, etc. we would get the arrangment shown to the left. If instead of X's and O's, we were to use 10 x 10 black or white gifs instead of X's and O's, we would get the representation shown to the right. Your program should create such a table on-the-fly with 7 rows and 5 columns. Each cell will contain a 10 x 10 gif image that is either black or white (white for an "O", black for an "X").
 
Write the VBScript for the sub named show_digit. Assume the array digits has been declared and the ten 35 character strings for the numbers 0,1,2, ... ,7,8,9 have already been stored in the array (i.e., Don't try to figure out these these ten strings). Do NOT edit the user's input.
Try it out:

Enter a single digit

Click "VIEW", the "SOURCE" to see the answer to this question