Chapter 8.1 - Programming Concepts Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

five basic constructs and what is included in each

A

» 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Define a variable

A

a named data store than contains a value that may change during the execution of a program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Define a constant

A

a named data store than contains a value that does not change during the execution of a program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is it mean to ‘declare’

A

define the value and data type of a variable or constant

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to declare an a constant integer in psuedocode

A

CONSTANT FirstConst <— 500

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to declare a variable thats a string in pseudocode

A

DECLARE SecondVar : STRING
SecondVar <— “Neel”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does the use of data types enable

A

» data to be stored in an appropriate way
» data to be manipulated effectively
» automatic validation in some cases.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

List the basic data types and define each one

A

» 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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does the ‘sequence’ of a program refer to

A

the order in which the steps in a program are executed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does ‘selection’ of a program refer to

A

allowing the selection of different paths through the steps of a program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

2 types of selection statements

A

IF/ELSE statements
Case Statements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Syntax for IF statements for pseudocode

if variable number is greater than 17 print 50 otherwise print 51

A

IF number > 17
THEN
OUTPUT ‘50’
ELSE
OUTPUT ‘51’
ENDIF

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

When are case statements used

A

used when there are multiple choices to be made.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

syntax in psuedocode for caseof statements for addition and subtraction

A

CASE OF OpValue
“+” : Answer <— n1+ n2
“-“ : Answer <— n1 - n2
OTHERWISE OUTPUT “Please enter a valid choice”
ENDCASE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does ‘iteration’ enable a program to do

A

allows a section of programming code to be repeated under certain conditions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

3 types of loops

how many iterations does each have

A

» 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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is the count-controlled loop

pseudo code syntax

A

For loop

pseudocode - FOR …. TO …. NEXT

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What function is used with for loops in python

what does each parameter stand for
is the last value included or excluded

A

range (1, 10, 1)

first 1 = starting value
second 10 = end value (EXCLUDED)
last 1 = step value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is the pre-condition loop

pseudo syntax

A

While loops

WHILE ____ DO

ENDWHILE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is the post condition loop

pseudocode

A

repeat until loop

REPEAT
____
UNTIL ___

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

When is a condition controlled loop used vs when is a count controlled loop used

A

Count controlled - number of iterations is known

condition controlled - number of iterations is unknown

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What is ‘totalling’

A

keeping a total that values are added to

23
Q

What is ‘counting’

A

keeping track of the number of times an action is performed

eg number of times a loop is executed

24
Q

4 string functions and purpose

A

Length - finding the number of characters in the string

Substring - extracting part of a string

upper - converting all the letters in a string to uppercase.

lower - converting all the letters in a string to lowercase.

25
Q

How to use a length string function in

python
pseudocode

A

python -
len(“Computer Science”)

psueodo-
LENGTH(“Computer Science”)

26
Q

How to use a substring string function in

python
psuedo

A

python -
“Computer Science”[9:16]
or
MyString[9:16]

Pseudocode-
SUBSTRING(“Computer Science”, 10, 7)
or
SUBSTRING(MyString, 10, 7)

27
Q

First index of strings in
python
Pseudocode

A

python - 0
Pseudocode- 1

28
Q

How to use an upper string function in

python
psuedo

A

python -
“Computer Science”.upper()

Pseudocode -
UCASE(“Computer Science”)

29
Q

How to use a lower string function in

python
psuedo

A

python -
“Computer Science”.lower()

Pseudocode -
LCASE(“Computer Science”)

30
Q

3 diff types of operators

A

Arithmetic
Logical
Boolean

31
Q

What is an arithmetic operator used for

A

an operator that is used to perform calculations

32
Q

how to use exponent in python

A

3 ** 2

3 squared

33
Q

What is a logical operator used for

A

an operator that is used to decide the path to take through a program if the expression formed is true or false

34
Q

Not equal statement in

python
psuedo

A

python - !=

pseudocode - <>

35
Q

what is a boolean operator used for

A

an operator that is used with logical operators to form more complex expressions

36
Q

3 types of boolean operators in python
pseudo

A

and, or, not

AND, OR, NOT

37
Q

what does it mean to ‘nest’ code

A

the inclusion of one type of code construct inside another

38
Q

Define a procedure

A

set of programming statements grouped together under single name that can be called to perform a task at any point in a program.

39
Q

Define a function

A

set of programming statements grouped together under a single name that can be called to perform a task at any point in a program and will return a value back to the main program.

40
Q

Definition of a parameter

A

variables that store the values of the arguments passed to a procedure or function

41
Q

How to define a procedure in pseudocode

how to execute

procedure to output a number of stars based on input from user

A

PROCEDURE Stars (N : INTEGER)
DECLARE C : INTEGER
FOR C <— 1 TO N
OUTPUT”*”
NEXT C
ENDPROCEDURE

CALL Stars (7)

42
Q

What is a procedure known as in python

how to make one

A

Void function

define a function but with no return statement

43
Q

How to print without line break in python

A

print(“*”, end = “”)

44
Q

pseudocode syntax for functions

A

FUNCTION Celsius (Temperature : REAL) RETURNS REAL
RETURN (Temperature – 32) / 1.8
ENDFUNCTION

45
Q

How to call a function in pseudocode

A

Must be assigned to a variable since it always returns a value

eg

MyTemp ← Celsius(MyTemp)

46
Q

How to write a non-void function (a fruitful function) in python

A

Just use a return statement

47
Q

3 components of defining a function in pseudo

A

» the name of the procedure or function
» any parameters passed to the procedure or function, and their data type
» the data type of the return value for a function.

48
Q

Define a global variable

define a local variable

A

global variable - can be used by any part of a program. its scope covers the whole program.

local variable - can only be used by the part of the program it has been
declared in. Its scope is restricted to that part of the program.

49
Q

4 library routines and their purpose

A

» MOD – returns remainder of a division

» DIV – returns the quotient (i.e. the whole number part) of a division

» ROUND – returns a value rounded to a given number of decimal places

» RANDOM – returns a random number

50
Q

How to use each library routine in pseudocode

A

Value1 ← MOD(10,3)

Value2 ← DIV(10,3)

Value3 ← ROUND(6.97354, 2) returns the value rounded to 2 decimal places

Value4 ← RANDOM()
returns a random number between 0 and 1 inclusive

51
Q

How to use library routines in python

A

% - mod operator
// - floor division
round(6.97354, 2) {rounds to 2 dp}

import random
random.randint(3, 9)

52
Q

What is divmod in python

A

divmod(x,y) provides both answers where the first answer is DIV and the second answer is MOD

53
Q

How to comment in
python
pseudo

A

#

psuedo - //