CS 180 Exam One Terms and Concepts
Chapter 1
- hardware components: main memory, secondary memory, central
processing unit (CPU)
- main memory: random-access memory (RAM), address
- kinds of values stored in memory: integers, real numbers
(floats), characters (using ASCII/Unicode), strings, program instructions
- secondary memory: hard disk, floppy disk, CD, flash drive
- programming languages: machine language, assembly language,
high-level languages, syntax vs. semantics
Chapter 2
- Components of a program (for now): explanatory comment,
preprocessor includes, namespace statement, main function
- use of the
cout
statement,
including <<
and endl
- variables: programmer-defined named storage locations in
memory
- must be declared
- must have a type
- must have a name that follows valid identifier
rules
- may be inititalized with a value at declaration time
- data types: A data type is a set of values and a
set of operations defined on those values. Data types so far include:
- integer: meaning short, int, long, long long, possibly
unsigned
- know which of these is appropriate for various kinds of
data
- know about hex (base 16) and octal (base 8) including
literals
- char: character data type for single characters using
single quotes for literals
- string: old-fashioned C-strings that we will use for
string literals and the string Class that we will use later for
variables
- floating-point: meaning float, double, long double
- literals can use scientific notation 1.4959E11 for
example
- typically always use
double
- bool: meaning a Boolean type, either true or false
- operations:
- assignment:uses the = sign
- distinguish left-hand
side (lhs, resolves to lvalue aka address) from right-hand side (rhs, resolves
to rvalue aka a value)
- scope: is the regions of the program in which the
variable exists and its name can be legally used
- one form is initialization, can only be done once per
variable
- declaration should be close to where the variable is
first used
- unary minus negates a numeric value
- addition subtraction multiplication: + - * work the
way you would expect
- division modulus: division is straightforward for
floats and works like on your calculator
- with integer types, does integer division
- division gives you the quotient
- modulus gives you the integer remainder
- modulus can distinguish even from odd, pick out digits,
etc. . .
- parentheses work as you would expect and are useful
Chapter 3
cin
reads data from standard input and converts
it to the type of the variable.
- Mathematical operators use precedence and associativity the way
you learned in your algebra class.
- Many more mathematical operations are available from
the
<cmath>
library, including pow
- Overflow and underflow can result from arithmetic operations.
Mostly they just wrap around without causing errors.
- Mixed type arithmetic operations are possible, but discouraged.
Use type casting instead:
static_cast<double>(a)
casts integer a to a double
- Combined assignment:
x += 1; y *= 5;
- Formatting Output:
setw(x), fixed, setprecision(x),
showpoint