Appendix J
Algorithm Verification
Consider the following selection statement where X is an integer test score between 0 and 100.
input X
if (0 <= X and X < 49) output "you fail"
else if (50 <= X and X < 70) output "your grade is" X output "you did OK"
else if (70 <= X and X < 85) output "your grade is" X output "you did well"
else if (85 <= X and X < 100) output "your grade is" X output "you did great"
endif output "how did you do?"
What will be printed if the input is 0? * “you fail” * “how did you do?” *
What will be printed if the input is 100? * “how did you do?” *
What will be printed if the input is 51? * “your grade is 51” * “you did OK” * “how did you do?” *
What will be printed if the user enters “Wingding”?
The program will terminate because it is expecting an integer value and a “Wingding” will cause an error in the program which will cause it to crash. *
Is this design robust? If so, explain why. If not, explain what you can do to make it robust. * The design is not robust as there are no statements for error handling and handling exceptions. To make this code more robust I would add error handling statements like the user can only enter numbers that are between 0 and 100. Also the user cannot enter any strings like winding and other data types, for other numbers and data types the system will display "invalid input. Please enter a number between 0 and 100." Also notice that it doesn't handle the case of entering 49. You need <= 49, as it is now, when you enter 49 all it will say is "how did u do?" same thing with entering 100 and for anything over 100. *
How many levels of nesting are there in this design?
There is one level of nesting in the design. *
Provide a set of values that will test the normal operation of this program segment. Defend your choices. * Test Values
Input (X)