Refine designs and choose test data
Refine before writing statements
For a largest-gap report, start with read data → calculate gaps → find greatest gap → output. Refine calculate gaps to compare indices I and I - 1 for I from 2 to NumberOfReadings. This avoids reading before the lower bound.
Translate a flow into control structures
A decision that returns to an earlier input step is repetition, not a single IF. Write the continuation condition carefully. Make an identifier table with each name, type and purpose before coding.
Common mistakes
- Starting the gap loop at 1.
Data[I - 1]then readsData[0], which is outside[1:6]: a runtime error. - Turning a back edge into an
IF. The input is checked only once, so a second bad value gets through. - A test plan with an input but no expected result. Without a prediction, the output cannot be judged.
- Refining every box into statements at once. Refine one step, check it, then refine the next.
Test with expected outcomes
A test plan must state input, reason and expected result. For largest adjacent gap, [2, 2] should produce 0; [-3, 5] should produce 8. Include the smallest permitted list and a maximum gap at the last pair. Compare the observed output with the prediction; merely running a program is not evidence of correctness.
On paper, draw a flowchart for the validation task and explain how its back edge becomes a loop. The structured checks below assess the algorithm and chosen values; your diagram and explanation need self-review or teacher review.
Dificultad 4/5 · 280 monedas + un pequeño bono en el primer intento de hoy
Translate this flow into pseudocode: 1 read Value; 2 if Value < 1 OR Value > 6, return to step 1; 3 output Value * 5; 4 stop.
Haz clic en Ejecutar para ver la salida aquí.
Dificultad 4/5 · 280 monedas + un pequeño bono en el primer intento de hoy
Valid integers are 1 to 6. Choose one normal, one boundary and one invalid value, in that order, from: 3, 6, 7.
Dificultad 4/5 · 280 monedas + un pequeño bono en el primer intento de hoy
Read NumberOfReadings (2 to 6), then NumberOfReadings non-decreasing integer readings. Store them in an array. Output the largest gap between adjacent readings.
Haz clic en Ejecutar para ver la salida aquí.
Explain your choice of data structure and loop. Identify one boundary case and predict its result. For a subroutine, explain what is returned or changed in the caller.
Guardado para esta sesión en este navegador. Revíselo usted mismo o con su profesor; estas explicaciones no se califican automáticamente.
Revise su explicación contra estos criterios
- My types and data structure match the data and the question.
- I justified the loop and checked its first and last iterations.
- Initial values and rejected operations preserve the intended state.
- My test includes input, purpose and expected result.
- I distinguished returning a value from printing and changing caller state.