大象传媒

Data structures - records

allow data values of different types that relate to each other to be stored together instead of in different arrays. For example, a record could be declared to hold the information about a board game:

RECORD Boardgame
title
genre
numPlayers
minAge
maxAge
ENDRECORD

This would create a record that stores the title and genre as and the number of players, minimum age, and maximum age as . Each board game would be created as a separate record which could then be held in an array, creating an array of records:

game1 鈫 Boardgame(鈥榮nap!鈥,鈥檆ard鈥,2,4,99)
game2 鈫 Boardgame(鈥榤onopoly鈥,鈥檉amily鈥,4,5,70)

This would create two separate records holding the related values for each game. To make this more efficient, an array could be used:

myGames[0] 鈫 Boardgame(鈥榮nap!鈥,鈥檆ard鈥,2,4,99)
myGames[1] 鈫 Boardgame(鈥榤onopoly鈥,鈥檉amily鈥,4,5,70)