click below
click below
Normal Size Small Size show me how
COMPUTER SCIENCE 2.2
Unit 2.2 Programming techniques Pseudo code and vocabulary
Term | Definition |
---|---|
DIV (floor division, quotient) | Integer division |
MOD | Provides the remainder |
Concatenation | Joining strings together PS: string_1 + string_2 etc. |
Length of string | PS: string_name.length P: Len(string_name) |
Substring | PS: string_name.subString(start pos, no. characters) |
Declaring an array | PS: array_name(items separated by commas) |
accessing an item in an array | PS: print(array[position]) |
length of an array | PS: array_length=array_name.length |
Declaring a 2D array | PS: array array_name(rows, columns) |
Accessing data in a record | PS: array_records[index].filename |
Changing data in a record | PS: array_records[index].filename = data (what to overwrite) |
SQL | Structured Query Language |
SELECT | Which record or row to take data from |
FROM | Which array/ field to take data from |
WHERE | Under what conditions should the record be chosen/returned? |
Random number generation | PS: num <-- RANDOM_INT(1,6) P: import random dice = random.randint(1,6) |
Sub programs | Smaller sections of code embedded into the main program |
Procedures | Carry out a task and provide structure to code. |
Functions | Carry out a task and return values to be used in the main program. Can be used to create re useable program components. |
Array | A variable with a single identifier that can store multiple items of data (of the same data type), and includes an index (position). |
Variable | Items of data that can change while the program is running. (reserves an area of memory to store its contents) |
Constant | a value that cannot change while the program is running but still uses an identifier name. |
Decleration | Stating the names of the variable to be used. Need to identify the data type. |
Assignment | setting the value of a variable/constant |
Programming construct | a way of building/ constructing code. |
Sequence | The order that things happen, running the program from start to finish |
Selection | choosing between possible actions through 'if' statements |
Iteration | repeating actions using loops (FOR or WHILE) |
Counter controlled iteration | set number of repeats using a FOR loop. |
Condition controlled iteration | repeats a set of actions while the condition is true using WHILE loops. |
Operator | a character/ characters that determine the action or process. |
Exponentiation | indices (using ^) |
Casting | converting from one data type to another |
Text file | contains plain text with no formatting to store data. can be read from and put into RAM. |
Delimiter | Separates data (usually with a comma) in a line. |
Line numbers | start at one but not stored in the text file |
Procedure code | PS: procedure name (...) ... end procedure |
Calling a procedure | PS: procedure(parameters) |
Function code | PS: function name(...) ... return ... end function |
Calling a function | PS: function(parameters) |
Functions in python | def function_name(): ... |
Reading text files | myFile = openRead(filename) file data = myFile.readLine() myFile.close() |
Why do you always have to close a file? | So other users can access it and to save RAM space. |
Reading files into an array | for line = 1 to 6 array_name[line -1] = myFile.readLine() next line myFile.close() |
reading a whole file | for line 1 to 41 filedata = myFile.readLine() print(file data) nextline myFile.close() |
writing to a text file | myfile = openWrite(filename) myFile = writeLine(data) myFile.close() |
write a line into CSV | data_for_file = ''...,'' + variable + etc. filename.writeLine(data_for_file) |
Creating files | createFile(filename) |
Open file | myFile = openRead() myFile = openWrite() |
close file | myFile.close() |