Written Response Question 1
Programs accept input to achieve their intended functionality. Describe at least one valid input to your program and what your program does with that input.
Example Response: One type of input is the user clicking on items to add them to their inventory. For example when the user clicks the "Key" button, the string "key" is added to a list representing the users inventory.
Written Response Question 2
2. Refer to your Personalized Project Reference when answering this question.
(a) Consider the first iteration statement included in the Procedure section of your Personalized Project Reference. Describe what is being accomplished by the code in the body of the iteration statement.
Example Response: The iteration statement loops through each element of the inventory and checks to see if it is equal to the "item" being searched for as determined by the function's parameter. If it is, then the "found" variable is changed to "true".
(b) Consider the procedure identified in part (i) of the Procedure section of your Personalized Project Reference. Write two calls to your procedure that each cause a different code segment in the procedure to execute. Describe the expected behavior of each call. If it is not possible for two calls to your procedure to cause different code segments to execute, explain why this is the case for your procedure.
Example Response
First Call: searchFor( ["key", "sword", "rope"], "key" );
This inventory does include the item "key", therefore the bolean expression in the if-statement will evaluate to true and the "found" variable will be changed to true.
Second Call: searchFor( ["sword", "rope"], "key" );
This inventory does not include the item "key", therefore the boolean expression in the if-statement will evaluate to false and the "found" variable is never changed to true.
(c) Suppose another programmer provides you with a procedure called checkValidity(value) that returns true if a value passed as an argument is considered valid by the other programmer and returns false otherwise. Using the list identified in the List section of your Personalized Project Reference, explain in detailed steps an algorithm that uses checkValidity to check whether all elements in your list are considered valid by the other programmer. Your explanation must be detailed enough for someone else to write the program code for the algorithm that uses checkValidity.
Example Responses:
Option 1: Using true/false
First, set a boolean variable called "allValid" to true. Then, using a loop, go through each element in currInventory. If checkValidity() returns false on the current inventory item, change the "allValid" variable to false. At the end of the loop, return the "allValid" variable.
Option 2: Using a Counter
First, create a counter variable called "validCount". Using a loop, to through each element of currInventory. If checkValidity returns true on the current inventory item, add one to the counter. If at the end of the loop, "validCount" is equal to the length of the list, we know that all of our elements are valid.