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.
![The report splits into read data, calculate gaps, find greatest gap and output; calculate gaps is refined into FOR I ← 2 TO NumberOfReadings with Gap ← Reading[I] - Reading[I - 1]](/static/code/as-pseudocode/refine-gaps.png)
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.
Dificuldade 4/5 · Moedas 280 + pequeno bônus na primeira conclusão hoje
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.
Clique em Executar para ver a saída aqui.
Dificuldade 4/5 · Moedas 280 + pequeno bônus na primeira conclusão hoje
Valid integers are 1 to 6. Choose one normal, one boundary and one invalid value, in that order, from: 3, 6, 7.
Dificuldade 4/5 · Moedas 280 + pequeno bônus na primeira conclusão hoje
Ler NumberOfReadings (2 to 6), then NumberOfReadings non-decreasing integer readings. Store them in an array. Output the largest gap between adjacent readings.
Clique em Executar para ver a saída aqui.
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.
Salvo para esta sessão neste navegador. Revise isso sozinho ou com seu professor; essas explicações não são marcadas automaticamente.
Revise sua explicação contra estes critérios
- 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.