Scripting and Programming Foundations - D278 WGU

0.0(0)
studied byStudied by 1 person
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/63

flashcard set

Earn XP

Description and Tags

Flashcards for this course in WGU

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

64 Terms

1
New cards

Computer program basics

A computer program consists of instructions that execute one at a time.

2
New cards

Input

A program gets data, perhaps from a file, keyboard, touchscreen, network, etc.

3
New cards

Process

A program performs computations on that data, such as adding two values like x + y.

4
New cards

Output

A program puts that data somewhere, such as to a file, screen, network, etc.

5
New cards

Flowchart

Is a graphical language for creating or viewing computer programs.

6
New cards

Program

Is a list of statements, each statement carrying out some action and executing one at a time.

7
New cards

Interpreter

Runs a program's statements. Run and execute are words for carrying out a program's statements.

8
New cards

String literal

Consists of text (characters) within double quotes, as in "Go #57!".

9
New cards

Character

Includes any letter (a-z, A-Z), digit (0-9), or symbol (~, !, @, etc.).

10
New cards

Cursor

Indicates where the next output item will be placed in the output. The system automatically moves the cursor after the previously-output item.

11
New cards

Newline

Is a special two-character sequence \n whose appearance in an output string literal causes the cursor to move to the next output line. The newline exists invisibly in the output.

12
New cards

Comment

Is text a programmer adds to a program, to be read by humans to better understand the code, but ignored by the program when executing.

13
New cards

Whitespace

Refers to blank spaces (space and tab characters) between items within a statement, and to newlines. Whitespace helps improve readability for humans, but for execution purposes much whitespace is ignored.

14
New cards

Embedded computers

Is a computer inside another electrical device, like inside a TV, car, printer, thermostat, satellite, etc. Thus, beyond business and personal computing devices like PCs, tablets, and smartphones, computers exist invisibly in nearly anything electrical today too.

15
New cards

Pseudocode

Is text that resembles a program in a real programming language but is simplified to aid human understanding. "Code" is a term for a program written in text. "Pseudo" in this context means "similar to". Commonly, each pseudocode text line corresponds to a program statement.

16
New cards

Coral

A simple language for learning to program. Coral has two versions: flowchart and code. Coral code looks like pseudocode, but follows rules that allow execution.

17
New cards

Variable

Is a named item, such as x or numPeople, used to hold a value.

18
New cards

Assignment statement

Assigns a variable with a value, such as x = 5. That statement means x is assigned with 5, and x keeps that value during subsequent statements, until x is assigned again.

19
New cards

= is not equals

In programming, = is an assignment of a left-side variable with a right-side value. = is NOT equality as in mathematics. Thus, x = 5 is read as "x is assigned with 5", and not as "x equals 5". When one sees x = 5, one might think of a box labeled x having the value 5 put in.

20
New cards

Variable declaration

Declares a new variable, specifying the variable's name and type. When a statement that assigns a variable with a value executes, the program puts the value into the variable. The variable will hold that value until the variable is assigned with another value.

21
New cards

Expressions

May be a number like 80, a variable name like numApples, or a simple calculation like numApples + 1. Simple calculations can involve standard math operators like +, -, and , and parentheses as in 2 (numApples - 1).

22
New cards

Identifier

An identifier must:

  • be a sequence of letters (a-z, A-Z), underscores (_), and digits (0-9)

  • start with a letter

  • Identifiers are case sensitive, meaning upper and lower case letters differ. So numCats and NumCats are different.

23
New cards

Reserved word

Is a word that is part of the language, like integer, Get, or Put. A programmer cannot use a reserved word as an identifier. A list of reserved words appears at the end of this section.

24
New cards

Naming conventions

A set of style guidelines defined by a company, team, teacher, etc., for naming variables.

Two common conventions for distinguishing words in an identifier are:

  • Camel case: Lower camel case abuts multiple words, capitalizing each word except the first, as in numApples or peopleOnBus.

  • Underscore separated: Words are lowercase and separated by an underscore, as in num_apples or people_on_bus.

25
New cards

Literal

Is a specific value in code, like 2.

26
New cards

Operator

Is a symbol that performs a built-in calculation, like the operator + which performs addition. Common programming operators are shown below.

27
New cards

Evaluates

To a value, which replaces the expression. Ex: If x is 5, then x + 1 evaluates to 6, and y = x + 1 assigns y with 6.

28
New cards

Precedence rules

Convention

Description

Explanation

( )

Items within parentheses are evaluated first.

In 2 * (x + 1), the x + 1 is evaluated first, with the result then multiplied by 2.

unary -

- used for negation (unary minus) is next.

In 2 * -x, the -x is computed first, with the result then multiplied by 2.

* /

Next to be evaluated are * and /, with each having equal precedence.

+ -

Finally, the + and - operators have equal precedence.

In y = 3 + 2 x, the 2 x is evaluated first, with the result then added to 3, because has higher precedence than +. Spacing doesn't matter: y = 3+2 x would still evaluate 2 * x first.

left to right

If more than one operator of equal precedence is evaluated, evaluation occurs left to right.

In y = x 2 / 3, the x 2 is first evaluated, with the result divided by 3.

29
New cards

Unary minus

An exception is minus used as negative, as in: xCoord = -yCoord. Minus (-) used as negative is known as.

30
New cards

Incremental development

Is the process of writing, compiling, and testing a small amount of code, then writing, compiling, and testing a small amount more (an incremental amount), and so on.

31
New cards

Floating-point number

Is a real number, like 98.6, 0.0001, or -666.667. The term "floating-point" refers to the decimal point being able to appear anywhere ("float") in the number. A variable declared as type float stores a floating-point number.

32
New cards

Floating-point literal

Is a number with a fractional part, even if that fraction is 0, as in 1.0, 0.0, or 99.573. Good practice is to always have a digit before the decimal point, as in 0.5, since .5 might mistakenly be viewed as 5.

33
New cards

Floating-point dividing by zero

Many programming languages produce an error when performing floating-point division by 0, but Coral does not. Coral handles this operation by producing infinity or -infinity, depending on the signs of the operands. Printing a floating-point variable that holds infinity or -infinity outputs Infinity or -Infinity.

34
New cards

RandomNumber()

Function is a built-in Coral function that takes two arguments, lowValue and highValue, and returns a random integer in the range lowValue to highValue. Ex: RandomNumber(1, 10) returns a random integer in the range 1 to 10.

35
New cards

Divide-by-zero error

For integer division, the second operand of / or % must never be 0, because division by 0 is mathematically undefined. A error occurs at runtime if a divisor is 0, causing a program to terminate.

36
New cards

Type conversion

Is a conversion of one data type to another, such as an integer to a float.

37
New cards

Implicit conversion

Coral automatically performs several common conversions between integer and float types, and such automatic conversion is known as.

38
New cards

Integer-to-float conversion

Is straightforward: 25 becomes 25.0.

39
New cards

float-to-integer conversion

Just drops the fraction: 4.9 becomes 4.

40
New cards

Type cast

Converts a value of one type to another type. A programmer can type cast an integer to float by multiplying the integer by the float literal 1.0. Ex: If myIntVar is 7, then myIntVar * 1.0 converts integer 7 to float 7.0.

41
New cards

Modulo operator (%)

Evaluates to the remainder of the division of two integer operands. Ex: 23 % 10 is 3. 70 % 7 is 0. Reason: 70 / 7 is 10 with remainder 0.

42
New cards

Common data types

Data type

Description

Integer

An integer is a whole number value, like 1, 999, 0, or -25.

Float

A float is a floating-point number, which is a real number, like 98.6, 0.0001, or -666.667.

Character

A character is a single letter, like 'A', 'p', or '%'.

String

A string is a sequence of characters, like "Hello" or "The forecast for today is sunny with highs of 75F.".

Boolean

A Boolean refers to a quantity that has only two possible values, true or false.

Array

An array is an ordered list of items of a given data type, like an array of integers or an array of floats.

43
New cards

Constant

Is a named value item that holds a value that cannot change. Constants are commonly used in programs to hold the value of mathematical or physical constants, such as pi, the speed of light, or kilograms per pound. Constants can also be used for any value that should not change during the program's execution.

44
New cards

Constant

Is a named value item that holds a value that cannot change. Constants are commonly used in programs to hold the value of mathematical or physical constants, such as pi, the speed of light, or kilograms per pound. Constants can also be used for any value that should not change during the program's execution.

45
New cards

Branches

In a program, a branch is a sequence of statements only executed under a certain condition. In Coral flowcharts, a decision creates two branches: If the decision's expression is true, the first branch executes, else the second branch executes. Afterwards, the branches rejoin. Coral flowcharts use a diamond symbol for a decision.

46
New cards

If-else branches

A decision and its two branches are often called if-else branches, because IF the decision's expression is true then the first branch executes, ELSE the second branch executes.

47
New cards

if-elseif branches

A branch may itself contain a decision and branches. Commonly, a series of decisions appear cascaded in each decision's false branch, known as if-elseif branches, to detect specific values of a variable. The example below detects values of 1, 25, or 50 for variable numYears. if-elseif branches are typically drawn with the decision boxes stacked vertically.

48
New cards

Equality operator

== evaluates to true if the left and right sides are equal. Ex: If numYears is 10, then numYears == 10 evaluates to true. Note the equality operator is ==, not =.

49
New cards

Nested if-else branches

If-else branches have two branches. A branch's statements can include any valid statements, including another if-else branch, known as nested branches. The nested branches can take on various forms, and the if-else branches may even use different variables.

50
New cards

Multiple if branches

If-else branches have two branches. A branch's statements can include any valid statements, including another if-else branch, known as nested branches. The nested branches can take on various forms, and the if-else branches may even use different variables.

51
New cards

Equality operator IE

Equality operators

Description

Example (assume x is 3)

==

a == b means a is equal to b

x 3 is true
x
4 is false

!=

a != b means a is not equal to b

x != 3 is false
x != 4 is true

52
New cards

Relational operator

Relational operators

Description

Example (assume x is 3)

<

a < b means a is less-than b

x < 4 is true
x < 3 is false

>

a > b means a is greater-than b

x > 2 is true
x > 3 is false

<=

a <= b means a is less-than-or-equal to b

x <= 4 is true
x <= 3 is true
x <= 2 is false

>=

a >= b means a is greater-than-or-equal to b

x >= 2 is true
x >= 3 is true
x >= 4 is false

53
New cards

Logical operator

Treats operands as being true or false, and evaluates to true or false. Logical operators include and, or, not.

54
New cards

Logical operators IE

Logical operator

Description

(a) and (b)

Logical and: true when both operands are true

(a) or (b)

Logical or: true when at least one of the two operands is true

not(a)

Logical not: true when the one operand is false, and vice-versa

55
New cards

Precedence rules

Operator/Convention

Description

Explanation

( )

Items within parentheses are evaluated first

In (a * (b + c)) - d, the + is evaluated first, then *, then -.

not

Logical not is next

not(x == 1) or y is evaluated as (not(x == 1)) or y

* / % + -

Arithmetic operators (using their precedence rules; see earlier section)

z - 45 * y < 53 evaluates * first, then -, then <.

<   <=   >   >=

Relational operators

x < 2 or x >= 10 is evaluated as (x < 2) or (x >= 10) because < and >= have precedence over the or operator.

==   !=

Equality and inequality operators

x == 0 and x >= 10 is evaluated as (x == 0) and (x >= 10) because == and >= have precedence over the and operator.

and

Logical and

x == 5 or y == 10 and z != 10 is evaluated as (x == 5) or ((y == 10) and (z != 10)) because the and operator has precedence over the or operator.

or

Logical OR

or has the lowest precedence of the listed arithmetic, logical, and relational operators.

56
New cards

If statements

Is an if decision expression followed by sub-statements, with no else part.

57
New cards
58
New cards
59
New cards
60
New cards
61
New cards
62
New cards
63
New cards
64
New cards