An algorithm is designed to calculate the total path length for an autonomous drone using waypoint coordinates.
1 # ----- Global variables -----
2 waypointCoordinates = [(0, 0), (12, 5), (24, -3), (30, 10)]
3
4 # ----- Subprograms -----
5 def computeTotalDistance(coordinates):
6 total_dist = 0.0
7 for i in range(len(coordinates) - 1):
8 x1, y1 = coordinates[i]
9 x2, y2 = coordinates[i+1]
10 total_dist += ((x2 - x1)**2 + (y2 - y1)**2)**0.5
11 return total_dist
12
13 # ----- Main Program -----
14 calculateChoice = input("Compute autonomous trajectory distance? (Y/N) ")
15 if calculateChoice.strip().upper() == "Y":
16 distance = computeTotalDistance(waypointCoordinates)
17 print("Total path length:", distance, "meters")
18 else:
19 print("Navigation standby")
Identify the computational thinking technique demonstrated by encapsulating the mathematical details of the multi-coordinate Euclidean distance formula inside the subprogram computeTotalDistance(), allowing the main program to obtain the total path length without interacting directly with the coordinate structures and loop index arithmetic.
19 exam-style questions on Edexcel GCSE Computer Science Decomposition and abstraction, covering Benefits of decomposition and abstraction and Benefits of subprograms. Each one has a worked solution and a mark scheme showing where the marks go.