Skip to content

Course home

Programming concepts

Programming concepts

EasyMediumHard
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
Question 27

Write a C# program to check if a logistics shipment contains a valid consecutive sequence of six packages within a delivery batch of 150 packages.

When writing your program you should assume:

  • there is an array called batchIDs that contains the integer IDs of the 150 packages
  • batchIDs[0] contains the ID of the first package and batchIDs[149] contains the ID of the last package
  • the IDs in batchIDs are stored in ascending numerical order
  • there is a Boolean variable called isValidSequence that has an initial value of false

Your program should set isValidSequence to true if there is a valid consecutive sequence of six packages (where each adjacent ID increases by exactly 1).

You should use meaningful variable name(s) and C# syntax in your answer.

Sequence Examples:

  • Valid run of six: ..., 12, 13, 14, 15, 16, 17, ...
  • Invalid run of six (gap): ..., 10, 11, 15, 16, 17, 18, ...
  • Invalid run of six (duplicate): ..., 30, 31, 31, 32, 33, 34, ... (The duplicate ID 31 breaks the continuous progression of six unique adjacent elements)
[6]
Markscheme

Programming concepts Questions

  1. GCSE
  2. /Computer Science
  3. /Programming concepts

298 exam-style questions on AQA GCSE Computer Science Programming concepts. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank