Difference between revisions of "CSC231 Final Exam 12/08"
(10 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 25: | Line 27: | ||
"Really" you ask? "What does the code look like?" | "Really" you ask? "What does the code look like?" | ||
− | "Here. That's what we did in class the other day," says Jane, and she hands you a piece of paper with the C code for the | + | "Here. That's what we did in class the other day," says Jane, and she hands you a piece of paper with the C code for the '''moveDisk''' function: |
+ | |||
<code><pre> | <code><pre> | ||
− | |||
− | |||
main() { | main() { | ||
moveDisk( 64, 'A', 'B', 'C' ); | moveDisk( 64, 'A', 'B', 'C' ); | ||
Line 43: | Line 44: | ||
} | } | ||
</pre></code> | </pre></code> | ||
+ | |||
+ | (A python version of this code is available [[CSC231 hanoi.py | here]].) | ||
You take the code and sit for a while, scribbling some notes on the sheet... A few minutes later you get up and announce "Of course! ..." | You take the code and sit for a while, scribbling some notes on the sheet... A few minutes later you get up and announce "Of course! ..." | ||
Line 53: | 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 66: | 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. | + | 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. | ||
− | Store your | + | '''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 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 | ||
+ | |||
+ | =Grading= | ||
+ | |||
+ | The main rules that will be followed when testing and reading your programs: | ||
+ | # programs should run, and not crash | ||
+ | # programs that crash without outputting any result will be given at most a D+ | ||
+ | # programs should solve the problem given, but if they do not, they should come "close", and solve a simpler version of the problem, or only a few cases covered by the problem. | ||
+ | # the documentation should explain what the program does and does not do, and what assumptions have been taken that transform the original problem. | ||
+ | # the header of the program should contain | ||
+ | ## The name of the program | ||
+ | ## The name of the programmer | ||
+ | ## The date | ||
+ | ## The problem addressed by the program | ||
+ | ## How the program solves the problem, or a variation of the problem. | ||
+ | ## What limitations or special cases that the program either covers, or does not cover. | ||
+ | # Each function should have a header indicating what the function performs, and what registers it modifies, and eventually whether it uses global variables or not. | ||
+ | |||
+ | 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> |