Calling Procedures

Help Questions

AP Computer Science Principles › Calling Procedures

Questions 1 - 4
1

In the context of the program described, in what order are procedures called to compute each student’s final grade?​

ComputeAverage, then ApplyLatePenalty, then PrintGrade.

ApplyLatePenalty, then ComputeAverage, then PrintGrade.

PrintGrade, then ApplyLatePenalty, then ComputeAverage.

ComputeAverage, then PrintGrade, then ApplyLatePenalty.

Explanation

This question tests AP Computer Science Principles skills: understanding and calling procedures. In programming, procedures are blocks of code designed to perform a specific task; they are called within a program to execute their defined operations. In the provided scenario, procedures such as ComputeAverage, ApplyLatePenalty, and PrintGrade are defined to handle tasks like calculating averages, applying penalties, and outputting final grades. Data flows through these procedures via parameters and return values in a logical sequence. Choice C is correct because it accurately reflects the logical order: first compute the average score, then apply any late penalties to that average, and finally print the resulting grade. Choice A is incorrect because it suggests printing the grade before calculating it, which would be impossible as PrintGrade needs the final computed value to display. To help students: Emphasize understanding the role of each procedure within the program and practice tracing data flow through parameters and return values. Encourage students to create flowcharts showing the logical sequence of procedure calls to visualize dependencies.

2

In the context of the program described, identify an error in the procedure call sequence for inventory removal.​

Calling TrackItem after RemoveItem prevents any output.

Calling AddItem before RemoveItem always duplicates item IDs.

Calling RemoveItem before CheckStock can allow negative inventory.

Calling PrintReceipt before TrackItem deletes the item list.

Explanation

This question tests AP Computer Science Principles skills: understanding and calling procedures. In programming, procedures are blocks of code designed to perform a specific task; they are called within a program to execute their defined operations. In the provided scenario, procedures such as RemoveItem and CheckStock are defined to handle inventory management tasks. Data flows through these procedures via parameters and return values, and the order of calls is critical for maintaining data integrity. Choice A is correct because it accurately identifies a logical error: removing an item before checking if sufficient stock exists could result in negative inventory values, which is typically an error condition. Choice B is incorrect because calling TrackItem after RemoveItem would not prevent output - it would simply track the removal that already occurred. To help students: Emphasize understanding the role of each procedure within the program and practice tracing data flow through parameters and return values. Encourage students to consider the logical dependencies between procedures and identify potential error conditions when procedures are called in the wrong order.

3

Based on the provided scenario, in what order are procedures called to produce the weather report?​

ComputeAverages, then FilterByDate, then GenerateReport.

GenerateReport, then ComputeAverages, then FilterByDate.

FilterByDate, then GenerateReport, then ComputeAverages.

FilterByDate, then ComputeAverages, then GenerateReport.

Explanation

This question tests AP Computer Science Principles skills: understanding and calling procedures. In programming, procedures are blocks of code designed to perform a specific task; they are called within a program to execute their defined operations. In the provided scenario, procedures FilterByDate, ComputeAverages, and GenerateReport work together to produce a weather report. Data flows through these procedures via parameters and return values in a logical sequence. Choice B is correct because it accurately reflects the logical order: first filter the data to the relevant date range, then compute averages on that filtered subset, and finally generate the report from those computed values. Choice C is incorrect because computing averages before filtering would waste resources calculating values for data that will be discarded, and could produce incorrect results. To help students: Emphasize understanding the role of each procedure within the program and practice tracing data flow through parameters and return values. Encourage students to think about efficiency and logical dependencies when determining the correct order of procedure calls.

4

Based on the provided scenario, identify an error in the banking procedure call sequence when withdrawing funds.​

Calling Deposit after Withdraw always doubles the account balance.

Calling Withdraw before CheckSufficientFunds can create a negative balance.

Calling PrintStatement after Withdraw prevents the withdrawal from occurring.

Calling CheckBalance before Withdraw deletes the transaction history.

Explanation

This question tests AP Computer Science Principles skills: understanding and calling procedures. In programming, procedures are blocks of code designed to perform a specific task; they are called within a program to execute their defined operations. In the provided scenario, procedures Withdraw and CheckSufficientFunds are defined to handle banking withdrawal operations safely. Data flows through these procedures via parameters and return values, and proper sequencing is critical for maintaining data integrity. Choice A is correct because it accurately identifies a critical error: withdrawing funds before checking if sufficient funds exist could result in a negative balance, which violates basic banking constraints and data integrity. Choice B is incorrect because printing a statement after a withdrawal would not prevent the withdrawal - it would simply document the transaction that already occurred. To help students: Emphasize understanding the role of each procedure within the program and practice tracing data flow through parameters and return values. Encourage students to identify validation procedures and ensure they are called before operations that modify data.