7. Programming Flashcards
What is an algorithm?
A series of steps to solve a problem.
In what ways can an algorithm be expressed?
- Structured English
- Pseudocode
- Flowchart
What is another name for a flowchart?
Flow diagram
Describe the process by which a program is developed in terms of planning.
- User requirement
- Flowchart
- Pseudocode
- Actual program code
Remember to revise flowchart shapes.
Pg 113 of revision guide.
What is a flowchart?
A diagram using commonly defined symbols to express an algorithm.
What is structured English?
- A way of writing an algorithm in natural language using some basic programming constructs such as IF…THEN…ELSE and loops.
- More structured than just natural language/prose.
What is pseudocode?
A way of writing an algorithm that is close to actual programming language, using coding-style constructs such as IF…THEN…ELSE, loops and array notation as appropriate.
What is sequence?
Where instructions are executed one after another in series.
Is an “End if” needed after a selection statement in algorithms?
Yes, they are usually used just to be really clear.
What is selection?
Where the program will execute certain instructions based on conditions. (e.g. “If” statements)
Give some examples of selection statements.
- IF…THEN…ELSE
* CASE…OF
Why are the different ways of coding a menu system where the user can choose between 3 options?
- Multiple IF statements
- Multiple nested IF statements
- CASE…OF statements
(See Pg 116 of textbook)
What is a CASE…OF statement?
A statement designed for coding multiple choices in a program, such as a menu of several options where the user enters one choice.
(See pg 116 of textbook)
What is iteration?
Where a program will execute certain instructions zero or more times based on a condition.
Remember to revise loops.
Pg 117 of textbook
Can statements like “If EmailAddress does not contain @” be used in pseudocode?
Yes
What is indentation and capitalisation in pseudocode like?
- Should be indented like a normal program
* PascalCase format used for item (all words capitalised but no spaces)
What is Hungarian notation?
- The convention of prefixing identifiers to indicate what type of object they are. Commonly used with forms. e.g. “txt” and “lst”
- Conventionally in lowercase
What is camel case?
The use of capital letters in an identifier to make it more readable. The first word is not capitalised.
e.g. camelCase
What is Pascal case?
The use of capital letters in an identifier to make it more readable. Especially with variables and procedures.
e.g. PascalCase
What is a condition?
A Boolean expression that controls an iteration or selection statement.
What is a Boolean expression?
An expression that is true or false.
e.g. continue=”y”
What is a high level programming language?
A programming language where programming constructs are written in a way that is close to natural language, instead of in mnemonics or machine code.
Give an example of a high level programming language.
- Java
- C++
- Visual Basic
What is machine code?
First generation code - binary instructions where some bits are used to define the operation (opcode) and some bits define the data to be used.
What is assembly language?
Second generation programming language where instructions are in the form of mnemonics.
What is an imperative language?
A programming language such as Python or Delphi which uses a sequence of statements to determine how to reach a certain goal or solve a problem.
What are mnemonics?
Abbreviations representing commands used in assembly language programming.
E.g. LDA, STO, ADX
How many assembly languages are there?
Many - one for each different processor architecture.
Describe the relationship between the language generation system and its link to the hardware.
1st and 2nd generation - Language is processor specific
3rd generation - Independent of hardware (portable)
Describe the language generation system.
1st gen - Machine code - Binary
2nd gen - Assembly language - Mnemonics
3rd gen - High level languages - Statements
(See pg 119 of textbook)
Compare machine code with high level languages.
MACHINE CODE • Processor specific • Designed with hardware in mind • One-to-one relationship with assembly language HIGH LEVEL LANGUAGES • Portable • Designed with type of problem in mind • On height level program instruction translated into several machine code instructions
(See Pg 120 of textbook)
What must be done before a high level language is run?
The program must be translated into machine code.
What type of software are translators?
System software
What are the different types of translator?
- Assemblers
* Compliers and Interpreters
What do different translators do?
- Assemblers - Convert assembly language into machine code
* Compilers and Interpreters - Convert a high level programming language into machine code
Remember to revise the translator diagram.
Pg 120 of textbook
What is an interpreter and how does it work?
A translator that converts high level languages into machine code one line at a time, checking syntax, converting to machine code and executing the code.
What is a compiler and how does it work?
- A translator that converts high level languages into machine code.
- Works through the whole program (source code) checking the syntax, then converting to machine code and creating the executable object code, which can be saved. The object code is executed, not the source code.
What is source code?
The original high level program.
What is object code?
The executable version of the program after it has been compiled.
What is an assembler?
The translator that converts assembly language programs into machine code.
What are mnemonics?
Abbreviations representing commands used in assembly language programming.
e.g. LDA, STO, ADX
What are the advantages and disadvantages of the use of compilers in business?
ADV
• The object code created can be easily distributed without giving the source code to the customers. This prevents illegal copies being made.
DIS
• Software problems in object code harder to diagnose
When are compilers and interpreters used most commonly?
Interpreters - In development of a program
Compilers - When distributing a program
How often does an interpreter have to translate code?
Every time it is run - this makes it slow to run.
What are the advantages and disadvantages of interpreters?
ADV • Easy to use in development DIS • Slow -> Program has to be translated every time it is run • Users can see code
Compare compilers and interpreters.
COMPILER • Translates while program to produce executable object code • Computer runs object code • Faster run time • Customers can't see source code • Used for distributed software INTERPRETER • Translates and executes one line at a time • Computer runs source code • Slower run time • Customers can see source code • Used in development
Why are constants used (rather than typing out the number)?
- If it needs to be changed, it only has to be changed in one place
- It might be faster to just write the constant name than to type a long number
- Code is easier to read and understand
What is an identifier?
A unique name for something (variable, constant, program, procedure, etc.) within the program.
What is a constant?
A named value within a program that has a specific value. Its value does not change while the program is running.
What does a data type define?
- The type of data that will be stored at the memory location and therefore the operations that can be performed on the data item
- How much space will be needed for that data item
Why are variables usually declared at the start of the program?
- Organisation
* The appropriate memory can be reserved to store the data
What is a variable?
An identifier associated with a particular memory location, used to store data. Its value may change as the program is run and new values are assigned to it.
What is a data type?
A formal description of a the type of data being stored in a variable.
Can a high level programming language store anything in less than a byte?
No
What are some common data types?
- Integer
- Real
- Char
- String
- Boolean
What is an integer?
Data type for whole numbers.
What is a real?
Data type for fractional numbers.
What is a char?
Data type for a single character.
What is a string?
Data type for text - zero or more characters.
What is a Boolean?
True or false.
What are operations?
Actions that can be performed on a variable.
How much memory does storing an integer take?
2 bytes
How much memory does storing a real take?
4 bytes
How much memory does storing a char take?
1 byte
How much memory does storing a string take?
1 byte per character
How much memory does storing a Boolean take?
1 byte
Is the memory taken by a data type the same with every programming language?
No, it can vary from language to language.
Remember to revise operations.
Pg 124
When can DIV and MOD be used?
When the numbers are integers.
What is DIV?
Integer division. It works like normal division, except it returns the whole number of times one number goes into another.
e.g. 13 DIV 3 = 4
What is MOD short for?
Modulus
What does MOD do?
Gives the remainder of integer division.
e.g. 13 MOD 3 = 1
305 DIV 30 =
10
305 MOD 30 =
5
What are the arithmetic operations?
Add, subtract, multiply, divide, DIV, MOD
What are the comparison operations?
=, , <=, >=, <>
What are the logical operators?
NOT, AND, OR
What are Boolean expressions?
Expressions that resolve to true or false, such as X <= 20.
What operations can be performed on integers?
- Arithmetic operations
* Comparison operations
What operations can be performed on reals?
- Arithmetic operations (except DIV and MOD)
* Comparison operations
What operations can be performed on Booleans?
• Logical operations
What is an array?
A group of data items of the same data type that use a single identifier. Individual data items are accessed using an subscript.
What are the advantages of an array?
- Code is easier to follow, debug and maintain
* A group of data can easily be processed by a FOR loop
What is syntax?
A set of rules that defines how program statements must be written in order for the translator to understand them.
What is a syntax error?
An error in the format of the program statements, such as a missing semicolon or keywords spelt incorrectly.
What is a logic error?
An error in the algorithm that means the outcome is not as expected, even though the program will run.
Give some common examples of syntax errors.
- Mistyping a key word
- Missing out key words (such as END IFs)
- Opening brackets but not closing them
- Not having the right number of parameters in brackets
What are the main types of error when developing a program?
- Syntax errors
* Logic errors
What is the difference in the effects of syntax and logic errors?
Syntax errors generally prevent the program from compiling, whereas a logic error may just give an unexpected output.
Give some common examples of logic errors.
- Missing brackets from mathematical calculations
* Loops that execute the wrong number of time because a “
Describe the structure of a typical testing table.
Headings: • Test purpose • Test data • Expected outcome • Actual outcome
When testing a program with number inputs, what inputs should be used?
- Check numbers at both ends of the allowed range of inputs
- Check numbers just outside allowed range at both ends
- Check a typical value in the middle of the range
- Check a non-number input
What is valid data?
Data that should be allowed by the program.
e.g. If a range of 1 to 10 is allowed, then valid data will be any number between 1 and 10 inclusive.
What is invalid data?
Data that is not valid and should be rejected by the program.
e.g. If a range of 1 to 10 is allowed, then invalid data will include abc, -251, 0, 11, etc.
What is boundary data?
Data either side of the range extremes.
e.g. In a range of 1 to 10, boundary data will include 0, 1, 10 and 11.
What does IDE stand for?
Integrated Development Environment
What is an integrated development environment?
A software package that helps you write code more easily, allowing writing and testing of code.
What are the common tools and facilities available in an integrated development environment?
- Editors
- Error Diagnostics
- Run-time Environment
- Translators
- Auto-documentation
Describe how a common IDE provides an editor and error diagnostics.
The IDE may provide:
• Colour-coding of words
• Numbering the lines
• Auto-correcting of constructs
Describe how a common IDE provides a run-time environment.
The run-time environment provides:
• The screen which you see when running the program
• The feedback you see when running the program (error messages)
• Other debugging tools (e.g. breakpoint)
Give an example of an IDE.
Visual Basic IDE
What is a breakpoint?
A tool that allows the program to be stopped at a certain line and the values of variables to be checked.
Describe how a common IDE provides a translator.
The translator:
• Either compiles or interprets the code
• The compiler will check the syntax, report any errors, and once these have been corrected, will convert the program to machine code
Describe how a common IDE provides auto-documentation.
The compiler recognises code comments and takes note of all the variables, modules and sub-routines as the project is developed. This is used to generate a text file that can be the basis of the programmer’s technical documentation.