2.2 Programming Fundamentals
No description yet. This curated deck is ready for daily study.
Card preview (24)
What is variable?
Variable - A variable is a value stored in memory that can change while the program is running.
What is Casting and why might it be useful?
CAsting - Converting data types This process is known as casting. The following examples convert a string to an integer and an integer to a string: str(68) returns “68” int(“54”) returns 54 float(“5.4”) returns 5.4
What are the five main data types?
Each data type is allocated a different amount of memory Integer - A positive or negative whole number used when arithmetic will be required Real / Float - A positive or negative decimal number Character - A single alphanumeric String - Multiple characters joined together [n.b. use this for credit card numbers] Boolean - two inputs(true and false)
What is string manipulation?
word = “Hello World” length = len(word) = 10 • *word[0:3]** = “Hel” • *word[-3:] = “rld”** • *print word[3:] = “lo World”** • *print word[:-3] #get all but the three last character** • *word.upper() = “HELLO WORLD”** • *word.lower() = “hello world”**
What is a constant?
Constant - A value which remains fixed as does not change whilst the program is running. It must be set at design time when the program is first written.
What is a sequence
Sequence is executing one instruction after another
What is Selection
Selection is program branching depending on a condition.
What is Iteration? What are the 3 types of loops?
Iteration, sometimes called looping, is repeating sections of code.
What are the three common Boolean Operators?
What does casting allow for?
It allow Sub-programs to recieve data in the format they were expecting.
What is ASCII conversion?
What are the stages to write data to a file?
• Open the file for creating/overwriting or appending to a file My • Write the data to a file • Close the file
What are the stages to read data from a file?
• Open the file for reading data • Assign a boolean variable to “false” to indicate the end of file is not reached. • While the end of the file is false and the search item is not found: • Read data from the file • If the data matches what is being searched for, assign the data to variables or output. • Check if the end of the file has been reached and assign the Boolean variable to “true” • Close the file
What are records?
Data in data bases are stored as records. Each records contains a number of fields and each field has its own data type
What is a record structure
A record structure: • A collection of related fields • Each field is a variable • Each field in a record can have a different data type.
How are records stored in text files?
• Stored on the secondary storage • Used to store data when the application is closed. • Useful for small volumes of data. E.g. configuration files. • Each entry is stored on a new line or separated with an identifier such as a comma or tab. • Can require a linear search to find/read data which is slow (if there is no order to the data or record structure). • Structured text files E.g. CSV, XML & JSON are popular for storing and exchanging data between applications
How are records stored in Arrayas and Lists
• Stored in RAM. • Used to store data when a program is running. • Useful for small volumes of data an algorithm is using. • Can be single or multi-dimensional allowing for tables of data to be stored. • Uses indexes to refer to data items. • Efficient algorithms or linear searches can be used to find data
How are records stored in databases? What is the records structure?
• Often stored on remote servers. • Often used to store data shared by many users, e.g. ticket booking system. • Data is stored in records and fields. • Uses advanced data structures to store data efficiently. • Uses very efficient algorithms to search and sort data executed on the servers. • More secure than text files. • The order of the fields in the database in independent of the code
What is SQL
There are three commands you need to know: SQL is used to create, delete, modify and manipulate records in a database The basic commands include: • SELECT which fields to be returned. * can be used to indicate all fields. • *- FROM which table. Databases can have more than one table, each with their own unique name.** • WHERE records meet a condition. Like can be used as a wildcard.
What is an Array?
An array is a series of memory locations – each of which holds a single item of data, but with each location sharing the same name. All data in an array must be of the same data type We can do that by allocating a contiguous part of memory to storing that data. Our program will know where in memory out array starts. It uses a index relative to this start point to allow us to easily access the arrays contents.
What are 1-dimensional Arrays?
What are two-dimensional Arrays?
You can visualise a two dimensional array as looking like a table with two sets of indexes. One index for the rows, another for the columns. print(countries[0][0]) creates “Angola” and 1246700
What are the two types of sub programs
Procedures • Carry out a task & DO NOT RETURN A VALUE • Provide structure to code making it easier to read Functions • Carry out a task AND Return a value • Create reusable program components
What do sub-routines look like in flowcharts?