OCR AS Level F452: Data types and data structures Data types and data structures a. define different data types, eg numeric (integer, real), Boolean, character and string; select and use them appropriately in their solutions to problems; b. define and use arrays (one- and two dimensional) for solving simple problems, including initialising arrays, reading data into arrays and performing a simple serial search on a one-dimensional array;
a. define different data types, eg numeric (integer, real), Boolean, character and string; select and use them appropriately in their solutions to problems; OCR AS Level F452: Data types and data structures
Data types Variable typeExample Chara StringHello world BooleanTRUE Integer35 Float12.56 Some languages also support more obscure types like Date and Currency. OCR AS Level F452: Data types and data structures
b. define and use arrays (one- and two dimensional) for solving simple problems, including initializing arrays, reading data into arrays and performing a simple serial search on a one-dimensional array; OCR AS Level F452: Data types and data structures
Arrays Definition: A data structure made up of a series of variables all of the same type, grouped under one identifier. Elements are accessed using an index. playerNames = [“Bob”, ”Rich”, ”Steve”, ”Jo”] playerNames(0) = “Ted” print(playerNames(1)) OCR AS Level F452: Data types and data structures
Pete myNames Each section in the Array is called an Element. Each Element can be accessed by referencing its location in the Array. var myNames = new Array(6); myNames[2]=“Pete"; [0][1][2][3][4][5] Elements OCR AS Level F452: Data types and data structures
Serial search Serial search just means checking each element one after the other until you find the one that you want. The most efficient way to do this in a 1D array is using a loop. count = 0 strWanted = “Steve” playerNames = [“Bob”, ”Rich”, ”Steve”, ”Jo”] while count<length(playerNames) if playerNames(count)== strWanted: print(“Player is in element “ + count) else: count = count + 1 print(“Finished”) OCR AS Level F452: Data types and data structures