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 in my program is the user typing in their grade and pressing the “add grade” button. After the button is pressed, the grade is added to a list of grades in the program for later use.
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 list of grades. If it identifies an item in the list that is below 60, it adds one to a counter variable.
(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: countFailing( [0, 0, 0] );
Since this list includes failing grades, the boolean expression in the if-statement will evaluate to true adding 1 to the counter variable three times.
Second Call: countPassing( [100, 100, 100] );
This list does not include any failing grades, therefore the boolean expression in the if-statement will evaluate to false and the counter variables is not changed from zero.
(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:
First, set a boolean variable called "allValid" to true. Then, using a loop, go through each grade in gradeList. If checkValidity() returns false on the current grade, change the "allValid" variable to false. At the end of the loop, return the "allValid" variable.
Option 2:
First, create a counter variable called "validCount". Using a loop, to through each element of gradesList. If checkValidity returns true on the current grade, 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.