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 N. 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.
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.
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.
Valid integers are 1 to 6. Choose one normal, one boundary and one invalid value, in that order, from: 3, 6, 7.
Read N (2 to 6), then N 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.
Saved for this sitting on this browser. Review this yourself or with your teacher; these explanations are not automatically marked.
Review your explanation against these criteria
- 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.