CSC Lesson 2 Flashcards
What is an assignment statement?
Something that assigns a variable with a value (ex. x = 5)
Which side of assignment statement is the variable commonly on?
Which side of the assignment statement is the expression commonly on?
The variable is on the left side.
The expression is on the right side.
x = w + 2 (variable) (expression)
What is an identifier and what are the rules for how it must be named?
An identifier is a name created by a programmer for an item like a variable or a function.
An identifier must:
Be a sequence of letters (a-z, A-Z), underscores (_), and digits (0-9)
It also must start with a letter.
You cannot use a reserved word (keyword) for an identifier.
What is a reserved word (keyword)?
A reserved word is a word that is part of the language like “integer”, “get”, “put”, “to”, “from”, “input”, “output”, etc.
(common conventions for identifiers) Camel Case
numApples, pureLeaf, seaSalt, kobeYarnSeason
(common conventions for identifiers) Underscore Seperated
bring_that_here, jimmer_dropped_forty, we_like_speeding
Common Coral Identifiers
Get, Put, to, from, input, output
integer, float, array, and, or, not
RaiseToPower, SquareRoot, AbsoluteValue, RandomNumber, SeedRandomNumbers
What is an expression?
An expression is a combination of items like variables, literals, operators and parentheses that equates to a value.
Commonly on the right side of an assignment statement
What is a literal?
A literal is a specific value in code, (ex. 2)
What is an operator?
An operator is a symbol that performs a built in calculation, like the operator + which performs addition.
Common operators:
+ (addition)
- (subtraction)
* (multiplication)
/ (division)
(Evaluation of Expressions) Precedence
Items in parentheses get evaluated first.
“unary -“ used for negation is next (2* -x) “-x” is evaluated first then multiplied by 2
- and / have equal precedence
+ and - have equal precedence after * and /
If more than one operator of equal precedence is used evaluation is left to right
What is a floating-point number?
Floating-point refers to decimal point being able to float anywhere.
96.4, -66.7777, etc.
Always have an integer before decimal so number doesn’t get mistaken.
0.3, 0.643, etc.
Coral built-in math functions
SquareRoot(x) - SquareRoot(9.0) = 3.0
RaiseToPower(x,y) - x^y
AbsoluteValue(x) - AbsoluteValue(-99.5) = 99.5
RandomNumber() - RandomNumber(1,10) generates random
number between 1 and 10
SeedRandomNumber() - will produce the same sequence of
random numbers
What is a function?
A function is a list of statements executed by invoking the function’s name, with such invoking known as a function call.
Any function input values, or arguments, appear inside a pair of ()
and are separated by commas if more than one.
-ex. multiply(a,b)
explain Integer Division
When the operands of / are both integers the output will be an integer and not a fractional (float) number.
10 / 4 will output 2 and not 2.5
What is a type conversion?
A type conversion is a conversion of one data type to another.
(ex. and integer to a float)
What is an implicit conversion?
An automatic type conversion in Coral.
If any operand is a float it will output a float.
What is a modulo operator? (%)
A modulo operator evaluates to the remainder of the division of two integer operands.
(ex. 24 % 10 = 4) because 24 / 10 is 2 with a remainder of 4 left
(ex. 10 % 4.0 is not valid) because remainder only makes sense for integer operands
Different data types
Integer - A whole number value (1, 2, 3, etc.)
Float - Floating-Point number (-4.323, 0.663, 5.324, 12.453, etc.)
Character - A single letter (R, F, %, e, d, etc.)
String - A sequence of characters (Hello, Goodbye)
Boolean - A quantity that has only two possible values (true or false)
Array - An ordered list of items of a given data type
What is a constant?
A constant is a named value item that holds a value that cannot change. (pi, speed of light, kilograms per pound, etc.)
Can also be used for values that should not change during the programs execution
What is a variable declaration?
A variable declaration declares a new variable specifying the variable’s name and type