APCSP Written Responses Compiled
APCSP Written Responses Compiled
2(b). A sample call to the procedure could be: filter("Division", "AFC East"). This would cause the
program to filter all teams in the 'AFC East' division and display their respective information. The
function would return new filtered lists that are then displayed on the interface using
displayTeamInfo().
2(c). If the list (e.g., teamList) was not included in the code, the program would be unable to
retrieve, store, or iterate through the team data. To adjust the program, one would need to
hardcode each team’s data or use another method of data retrieval, such as manual user input
or a database. This would significantly reduce the efficiency and scalability of the program.
2(a). An equivalent Boolean expression for the conditional statement in the filter procedure
could be:
(filterType == "Team" && teamList[i] == filterValue)
This condition checks whether the current item in the teamList matches the provided filter value
when the filter type is "Team".
2(b). A strategy other than test cases to verify the correctness of the procedure would be code
tracing. This involves stepping through the code manually or using print statements (e.g.,
console.log) to monitor variable values and ensure that the correct branches of code are
executed based on different filterType and filterValue inputs.
2(c). The filter procedure solves the subproblem of extracting relevant team information based
on a specific filter. By isolating this logic, the procedure simplifies the main program flow and
allows modular handling of different filter types. This supports the overall goal of dynamically
displaying team data based on user selections.
2(a). The code segment using the list is a for-loop that checks multiple conditions:
for(var i=0; i < teamList.length; i++) {
if(filterType == "Team" && teamList[i] == filterValue) {
appendItems(i);
}
}
This code iterates through teamList and compares each item to the filterValue. If the condition
matches, it calls appendItems(i), which adds the corresponding data from all related lists into
the filtered lists.
2(b). To test whether a specific block of code is executed based on arguments, output
statements like console.log("Team matched") can be inserted inside each conditional branch in
the filter procedure. For example, after 'if(filterType == "Team" && teamList[i] == filterValue)',
you could log to confirm it was executed. This confirms that passing different arguments results
in different branches of code executing.
2(c). If the 'filterType' parameter was removed from the filter procedure, the code would need
to be rewritten to only handle one specific type of filtering (e.g., only filter by team). This would
reduce the procedure’s flexibility and require multiple separate functions for each filter type,
making the program less efficient and harder to maintain.