Lecture 2 Flashcards
Cin
Streams user input from the console to the computer.»_space; stream operator is used after to denote information is streamed from console. Info is input in the order it is typed (first thing user types goes into first input, etc.)
++ and +=
Increment operator increments by one. ++ is placed before or after the variable; before the variable increments before other parts on the line of code are executed and after does it after. += is placed after the variable and increments by whatever is placed after the +=
Computations
Mathematical calculations.
Handled by the processor.
Variable Declaration
Type and name of a variable followed by a semicolon.
Tells the computer to reserve a type of memory for a variable of a specific name. Whenever that variable is referred to in the code, it will use the information stored in the part of the memory designated for that variable. You can declare all variables of a certain type on one line.
Variable assignment
Variable name followed by an equal sign, the initial information assigned to that variable, and a semiclon at the end.
Variables can be reassigned different information and can be assigned on the same line as variable declaration. It is good to set an initial value when declaring a variable. Equal sign in variable assignment is assignment operator, not equal operator.
Variable name rules
- Name can include numbers, letters, and the underscore symbol.
- Names must start with a letter
- Names must not use other names reserved for commands or other parts of code
For main parts of code and their corresponding computer hardware
Input and output -> user interface
Variables -> memory
Computations -> computer processor
Variable
A section of memory that a computer program allows you to use to store information. When a variable name is referenced in a program, the program uses the information stored in that variable “box”
Tips for naming a variable
Choose something that gives you a clear idea of what the variable is and is not too long or too short. It is also helpful to format your variables similarly.
Float
Floating point variable type. Is a number with a decimal because the decimal can move/float around.
Int
Integer type variable. Is an integer/whole number.
+
Addition operator
-
Subtraction operator
*
Multiplication operator
/
Division operator