__CHAPTER THREE SUMMARY__

__Variables__

-a variable is a named memory location which stores a value

--to use a variable in a program, it must be defined by giving it a type and identifier

eg: double *Radius*

Once defined the variable must be given a value

eg: *Radius* = 12.3 ;

the **= **sign is similar to the **:=** in Pascal which means that the value is assigned to the variable

CIN -- used for input: see previous notes

__Using Named Constants__

-defined in a statement and begins with the word ** "const**"

--this is used to define a constant: in math Pi is a constant value (3.14159)...to represent this in C++, you do the following:

const double PI = 3.14 ;

--a constant is used to represent a value that does not change during the execution of a program

__Choosing Identifiers__

Rules for choosing identifiers:

- must start with a letter
- must contain only letters, digits and the underscore ( _ ) character
- can be of any length
- are case sensitive: Radius is different than radius

__Built in Data Types__

1. __double__

- used to store positive or negative real numbers (decimals)
- floating point numbers (decimals)
- when the number is very large, it will be stored in scientific notation: the computer stores
__1.23457 x 10__^{8}^{}^{ }as__1.23457e+08__ - the double value is rounded to six digits

2. __int ____and____ long__

- used to store positive and negative integers (no decimals!)
- only difference is the range of values :
__long____goes beyond 32767__

3. __char____:__

- used to store a single character
- can be used to store a single letter, digit or symbol like the % sign
- requires single quotation marks:

Example: char Ch:

Ch = 'A';

cout<

displays : A

__VARIABLE DEFINITIONS__

VARIABLES can be defined in single statements or in multiple variables in one line

example: int x,y,z

Char ch1,ch2

__Expressions and Operators__

-built in arithmetic operations include: (*) multiplication,

(+) addition, (-) subtraction, and ( / ) division

**Promotion**: numeric values of various types can be mixed in an expression: an expression involving two doubles, results
in a double, however, whenever an integer and a double are used, C++ promotes the value with the narrow range to the
value with the wider range: integer becomes a double: this avoids the problem known in Pascal as "type mismatch"

**Integer Division: **if you divide two integers, the resulting number will be truncated, or the decimals will be cut off!

**Type Casting: ** when real division is done, type casting converts one of the values into a real number

**Modulus Division: **represented by %, Modulus division returns the remainder....similar to MOD in Pascal

**Operator Precedence: ** same as order of operations in mathematics

__Output Formatting__

- use
**width ( )**to control your output: creates a field width, so width(10) will allow 10 digits - use
**setf( )**to change the alignment (see handout) - use
**precision ( )**to specify the number of decimals