Chapter 8.1 - Programming Concepts Flashcards
five basic constructs and what is included in each
» data use – variables, constants and arrays
» sequence – order of steps in a task
» selection – choosing a path through a program
» iteration – repetition of a sequence of steps in a program
» operator use – arithmetic for calculations, logical and Boolean for decisions
Define a variable
a named data store than contains a value that may change during the execution of a program
Define a constant
a named data store than contains a value that does not change during the execution of a program.
What is it mean to ‘declare’
define the value and data type of a variable or constant
How to declare an a constant integer in psuedocode
CONSTANT FirstConst <— 500
How to declare a variable thats a string in pseudocode
DECLARE SecondVar : STRING
SecondVar <— “Neel”
What does the use of data types enable
» data to be stored in an appropriate way
» data to be manipulated effectively
» automatic validation in some cases.
List the basic data types and define each one
» integer – a positive or negative whole number that can be used with mathematical operators
real – a positive or negative number with a fractional part.
char – a variable or constant that is a single character
string – a variable or constant that is several characters in length. Can also be an empty string
Boolean - variable or constant that can have only two values TRUE or FALSE.
What does the ‘sequence’ of a program refer to
the order in which the steps in a program are executed
What does ‘selection’ of a program refer to
allowing the selection of different paths through the steps of a program
2 types of selection statements
IF/ELSE statements
Case Statements
Syntax for IF statements for pseudocode
if variable number is greater than 17 print 50 otherwise print 51
IF number > 17
THEN
OUTPUT ‘50’
ELSE
OUTPUT ‘51’
ENDIF
When are case statements used
used when there are multiple choices to be made.
syntax in psuedocode for caseof statements for addition and subtraction
CASE OF OpValue
“+” : Answer <— n1+ n2
“-“ : Answer <— n1 - n2
OTHERWISE OUTPUT “Please enter a valid choice”
ENDCASE
What does ‘iteration’ enable a program to do
allows a section of programming code to be repeated under certain conditions
3 types of loops
how many iterations does each have
» Count-controlled loops (for a set number of iterations)
» Pre-condition loops – may have no iterations
» Post-condition loops – always has at least one iteration.
What is the count-controlled loop
pseudo code syntax
For loop
pseudocode - FOR …. TO …. NEXT
What function is used with for loops in python
what does each parameter stand for
is the last value included or excluded
range (1, 10, 1)
first 1 = starting value
second 10 = end value (EXCLUDED)
last 1 = step value
What is the pre-condition loop
pseudo syntax
While loops
WHILE ____ DO
ENDWHILE
What is the post condition loop
pseudocode
repeat until loop
REPEAT
____
UNTIL ___
When is a condition controlled loop used vs when is a count controlled loop used
Count controlled - number of iterations is known
condition controlled - number of iterations is unknown