Difference between revisions of "CSC231 Final Exam 12/08"

From dftwiki3
Jump to: navigation, search
(Grading)
 
(7 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
----
 
----
  
 +
<onlydft>
 
=Take Home Exam=
 
=Take Home Exam=
  
This exam is due on Dec 19, at '''noon'''.
+
<font color="purple">This exam is due on Dec 19, at '''noon'''.
  
 
This exam is given under the rules of the ''honor code''. You have access to all your notes, to books, and to the Web. You cannot, however, discuss the details of the exam with anybody other than your instructor. Questions regarding the exam can only be asked in class, or via email. In case you send a question via email, the text of your question in its entirety and the answer to it will be broadcast back to the whole class, so be careful not to divulge too much in your questions. In this fashion, everybody will have access to the same information and same clarifications.
 
This exam is given under the rules of the ''honor code''. You have access to all your notes, to books, and to the Web. You cannot, however, discuss the details of the exam with anybody other than your instructor. Questions regarding the exam can only be asked in class, or via email. In case you send a question via email, the text of your question in its entirety and the answer to it will be broadcast back to the whole class, so be careful not to divulge too much in your questions. In this fashion, everybody will have access to the same information and same clarifications.
 +
</font>
  
 
=Problem #1 (2 points)=
 
=Problem #1 (2 points)=
Line 54: Line 56:
  
 
==Part 2 (1 point)==
 
==Part 2 (1 point)==
Write the Tower of Hanoi program in assembly.  Store your program in a file called hanoi.asm
+
Write the Tower of Hanoi program in assembly.  Store your program in a file called '''hanoi.asm'''.
 +
 
 +
Your program should display the number of disks ''N'' used, and then the series of moves that need to be taken to move all the disks from one peg to the other.  Here is an example:
 +
 
 +
<code><pre>
 +
Towers of Hanoi game
 +
Number of disks = 4
 +
move disk from A to C
 +
move disk from A to B
 +
move disk from C to B
 +
move disk from A to C
 +
move disk from B to A
 +
move disk from B to C
 +
move disk from A to C
 +
move disk from A to B
 +
move disk from C to B
 +
move disk from C to A
 +
move disk from B to A
 +
move disk from C to B
 +
move disk from A to C
 +
move disk from A to B
 +
move disk from C to B
 +
 
 +
</pre></code>
 +
 
 +
Make the program use a global variable that defines how many disks are used:
 +
 
 +
<code><pre>
 +
          section .data
 +
N        dd      4
 +
</pre></code>
 +
 
 +
Use 4 for N when you submit your program.  Of course your program should work for other values of N!  (Make sure that your program degrades gracefully, i.e. it shouldn't crash if N is set to 1, to 0, or to a negative number!
  
 
Store your answers to Part 1 in the header of the program and submit it as follows:
 
Store your answers to Part 1 in the header of the program and submit it as follows:
  
 
               submit exam hanoi.asm
 
               submit exam hanoi.asm
 
  
 
=Problem #2 (2 points)=
 
=Problem #2 (2 points)=
Line 67: Line 100:
 
Sometimes, however, it seems to behave in unexpected ways. To see an example of this, get the following Python program: [[CSC231 sum_of_floats.py | sum_of_floats.py]], and study it. It creates a list of 10 random floating-point numbers, each one the result of picking a random real number between 0 and 1.0, which is then multiplied by 10 raised to some other random integer in the range -40 to +40.
 
Sometimes, however, it seems to behave in unexpected ways. To see an example of this, get the following Python program: [[CSC231 sum_of_floats.py | sum_of_floats.py]], and study it. It creates a list of 10 random floating-point numbers, each one the result of picking a random real number between 0 and 1.0, which is then multiplied by 10 raised to some other random integer in the range -40 to +40.
  
The program then computes the sum of the ten numbers as stored in the list. That's sum1. Next it sorts the list in increasing order and computes the sum again, this time saving it into sum 2. Finally, it reverses the list so that it is sorted in decreasing order, and computes the sum of the numbers which it stores in sum3. It then compares sum1, sum2, and sum3, and displays the list and the sums if these are not equal. Explain why the 3 sums are sometimes not equal. What recommendations would you make when one has to compute the sum of several floating-point numb ers?
+
The program then computes the sum of the ten numbers as stored in the list. That's sum1. Next it sorts the list in increasing order and computes the sum again, this time saving it into sum 2. Finally, it reverses the list so that it is sorted in decreasing order, and computes the sum of the numbers which it stores in sum3. It then compares sum1, sum2, and sum3, and displays the list and the sums if these are not equal.  
 +
 
 +
'''Question 1''': Explain why the 3 sums are usually the same, but ''sometimes'' not equal. Base your explication on the 32-bit IEEE Floating-Point format which we saw in class.
 +
 
 +
'''Question 2''': What recommendations would you make when one has to compute the sum of several floating-point numbers?
 +
 
 +
'''Question 3''': What test could you use when you are given a list of numbers to figure out  whether the sum ''might'' not be correct when the addition is performed?
 +
 
 +
'''Question 4''': Do we have to be worried about incurring the same problem when computing the product of a series of real numbers?
  
Store your answer in a file called sumfloat.txt and submit it as follows:
+
Store your answers in a text file (not a Word doc file, please!) called '''sumfloat.txt''' and submit it as follows:
  
 
             submit exam sumfloat.txt
 
             submit exam sumfloat.txt
Line 90: Line 131:
  
 
For the written parts, you are allowed and encouraged to use the computer to generate your answer.  This means that you shouldn't hesitate to write programs, use programs (eXcel for example), or whatever other tool you have access to.  In this case, include copies of the programs or screen captures illustrating the data that help you make your case.
 
For the written parts, you are allowed and encouraged to use the computer to generate your answer.  This means that you shouldn't hesitate to write programs, use programs (eXcel for example), or whatever other tool you have access to.  In this case, include copies of the programs or screen captures illustrating the data that help you make your case.
 +
 +
</onlydft>

Latest revision as of 13:36, 11 December 2012

--D. Thiebaut 15:03, 1 December 2008 (UTC)



...