8.2 Programming techniques Flashcards
Data types
A data type is a classifi cation of data into groups according to the kind of data they represent.
Computers use di fferent data types to represent di fferent types of data in a program.
The basic data types include:
Integer - whole number, real - numbers with fractional parts, character - single character, string - sequence of characters and boolean - true or false values.
Casting is when you convert one data type to another data type.
String manipulation
String manipulation is the use of programming techniques to modify, analyse or extract information from a string.
Examples of string manipulation include:
Case conversion (modify) - The ability to change a string from one case to another.
Length (analyse) - The ability to count the number of characters in a string.
Substrings (extract) - The ability to extract a sequence of characters from a larger string in order to be used by another function in the program.
Concatenation (modify) - The ability to join two or more strings together to form a single string.
ASCII conversion (analyse) - The ability to return an ASCII character from a numerical value and vice versa
File handling
File handling is the use of programming techniques to work with information stored in text files.
Examples of le handing techniques are:
Opening text fi les
Reading text fi les
Writing text fi les
Closing text fi les
Database
A database is an organised collection of data.
It allows easy storage, retrieval and management of information.
A database is useful when working with large amounts of data, databases are stored on secondary storage.
A database is often stored on remote servers so multiple users can access it at the same time, useful for online systems.
Data can be sorted and searched e fficiently, making use of more advanced structures.
They are more secure than text files.
A database uses fi elds and records to organise how it stores data.
Files and records
A field is one piece of information relating to one person, item or object.
A field is represented in a database by a column.
A record is a collection of fields relating to one person, item or object.
A record is a represented in a database by a row.
Text files
A text fi le is useful when working with small amounts of data, text files are stored on secondary storage and ‘read’ in to a program when being used.
They are used to store information when the application is closed.
Each entry is stored on a new line or separated with a special identifier.
It can be difficult in text files to know where a record begins and ends.
Arrays
An array is useful when working with small amounts of data, arrays are stored in main memory (RAM).
They are used to store information when the application is in use.
Can be more efficient can much faster to search than working with text files.
SQL
SQL (Structured Query Language) is a programming language used to interact with a DBMS.
SQL allows users to locate specific information in a database table using these
basic SQL commands:
Select - retrieve data from a database table.
From - specifies the tables to retrieve data from.
Where - Filters the data based on a specified condition.
1D array
An array is an ordered, static set of elements in a fixed size memory location.
An array can only store 1 data type.
A 1D array is a linear array.
Indexes start at 0, known as zero indexed.
2D array
A 2D array extends the concept on a 1D array by adding another dimension.
A 2D array can be visualised as a table with rows and columns.
When navigating through a 2D array you first have to go down the rows and then across the columns to find a position within the array.
Sub programs
Functions and procedures are a type of sub program, a sequence of instructions that perform a speci fic task or set of tasks.
Sub programs are often used to simplify a program by breaking it into smaller, more manageable parts.
Sub programs can be used to:
Avoid duplicating code and can be reused throughout a program.
Improve the readability and maintainability of code.
Perform calculations, to retrieve data, or to make decisions based on input.
Parameters
Parameters are values that are passed into a sub program
Parameters can be variables or values and they are located in brackets after the name of the sub program.
Sub programs can have multiple parameters.
To use a sub program you ‘call’ it from the main program.
Global variable
A global variable is a variable declared at the outermost level of a program. This means that they are declared outside any modules such as functions or procedures.
Global variables have a global scope, which means they can be accessed and modified from any part of the program.
Local variable
A local variable is a variable declared within a specifi c scope, such as a function or a code block.
Local variables are accessible only within the block in which they are defined, and their lifetime is limited to that particular block.
Once the execution of the block ends, the local variable is destroyed, and its memory is released.
Random number generation
Random number generation is a programming concept that involves a computer generating a random number to be used within a program to add an element of unpredictability.
Examples of where this concept could be used include:
Simulating the roll of a dice
Selecting a random question (from a numbered list)
National lottery
Cryptography