Developing software (chapter 4) Flashcards
(21 cards)
Varibles
Variables are methods of storing data so that they can be retrieved later within a program. e.g. strfruit = apple
Operators
Used in code to perform tasks
Operators - Arithmetic
Arithmetic operators are used to perform mathematical operations. They are similar to the operations performed in basic mathematics and are used to manipulate numerical values. e.g. +,-,*,/,%
Conditional operators - Logical
Logical operators are used to perform logical operations, primarily in selection statements, to determine the truthfulness of an expression. They are used to combine or invert Boolean values (true or false). e.g. AND, OR
Conditional operators - conditional
Conditional operators are used to compare two values or expressions. e.g. <, >, ==, !=
Control structures
There are three fundamental control structures in programming: sequences, conditional statements and iterations. They run a program.
Control structures - Sequence
A sequence is a set of instructions that executes line by line, a little bit like a recipe; every line of code in the sequence is run in the order that it is written.
e.g:
ALGORITHM askName()
BEGIN
PRINT “What is your name?”
INPUT name
PRINT “Hello, “ + name + “. Nice to meet you.”
END
Control structures - Selection
Selective control structures (selections) allow the application to make decisions during runtime, dependent on given conditions. Based on the result of a condition in true or false.
e.g.
ALGORITHM printPositive()
BEGIN
INPUT intNumber
IF intNumber > 0 THEN PRINT “The number is positive.” ENDIF END
Control structures - Statements and iterations
A iteration is another name for a loop, which runs code until a condition is met. There are 4 main types of loops: WHILE, DO/WHILE, FOR, REPEAT UNTIL
e.g.
ALGORITHM readFromFile()
BEGIN
INPUT fileName
fileObject ← open filename for reading WHILE end of file is not reached DO nextLine ← read one line from fileObject PRINT nextLine ENDWHILE END
Functions
A function is a block of code that is intended to be used repeatedly within an application. The code within a function executes an algorithm, and typically provides a return value as a result.
OOP
Stands for object oriented programing. A way of organizing code that uses objects and classes to represent real world entities and their behavior.
OOP - abstraction
Abstraction is the process of hiding complex internal details (code), and only showing essential features of a object or method.
OOP - encapsulation
Encapsulation is the bundling of data (attributes) and method (functions) within a class, restricting access to some component to control interactions. e.g.
Public Members = self.strName, Accessible from anywhere
Protected Members = self._strName, Accessible from within a class and subclasses
Private Members = self.__strName, Accessible from only within the class
OOP - class
Classes are blueprints/templates for creating objects.
OOP - object
An object represents a real world entity. e.g. a dog or cat. They have properties/attributes linked to them
OOP - method
A method is the same as a function, when called it will print something related to its original code with a user input variable
Naming convection
A naming convention is a set of rules that is used when creating variables, subroutines, functions, methods, objects, classes. e.g. Hungarian notation, camel case
Internal documentation benefits
Internal documentation are just footnotes in code. They provide context and understanding for what code does
Validation techniques
Validation is the process of checking that input data is reasonable. Validation does not and cannot check that inputs are accurate.
Existence check: an existence checks if the user has put in any data at all. This is useful to ensure all feild have been filled.
Type checking: Checks to see if the correct data type has been input. e.g. checks if a integer has been put into a string format textbox
Range checking: Checks if the input value is between acceptable limits. e.g. IF intNum > 0, the input number must be greater than zero, if below or equal to zero there would be an error
Testing and debugging
When coding and running a program errors can appear. The main errors are: syntax errors, runtime errors or logic errors.
Syntax errors: If a character in a variable that does not follow that programs syntax rules, missing brackets or quotes and this error will appear
Runtime errors: No syntax errors but something unexpected happened, that caused the program to crash. e.g. Dividing by zero, using a variable that doesn’t exist
Logic errors: When syntax is correct and the programs runs well, but the outcome is unexpected or wrong.
Testing tables
A table that shows the expected results and real results: Test Case, Test data, Expected result, Actual result, Pass/fail. class notes -> Ex8 Home loan calculator -> bottom of page