lecture3

# lecture3 - 1 © Janice Regan CMPT 128 Jan 2007 CMPT 128...

This preview shows pages 1–8. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 © Janice Regan, CMPT 128, Jan 2007 CMPT 128: Introduction to Computing Science for Engineering Students More components of a C++ program Data representation and Data Types Basic IO © Janice Regan, CMPT 128, Sept 2007 2 Components of a C++ Program More types of tokens (smallest individual units of a program) include: String Literal Constants or constant labels used in expressions Bob in expression Name = ” Bob”; Literal Constants or fixed numbers used in expressions 3 in expression y = x + 3; Variables and Constants © Janice Regan, CMPT 128, Sept 2007 3 Constants and Variables Each constant or variable represents a specific item in the problem the program solves and is associated with a memory cell used to hold its value a unique identifier or name a data type The value of a constant does not change during execution of the program The value of a variable may be changed during the execution of a program. © Janice Regan, CMPT 128, Sept 2007 4 Types of Constants and Variables A Data Type is A set of values plus a set of operations on those values A crucial concept on modern programming The data type of a variable or constant also determines how the variable’s value will be represented in memory Variables of several types can have numerical values Variables of other types have values that are characters, or logical values. © Janice Regan, CMPT 128, Sept 2007 5 Types with Numerical Values Two classes of numerical values Integer and floating point Integer values are whole numbers No fractional part 1, 12354, 68, -123 C++ Types: int, unsigned int, long int, short int, long unsigned int, … Floating point values have a fractional part 987.4, -0.332, 0.123, 3.14159 C++ types: float, double, long double Integers and floating point numbers are represented differently inside the computer © Janice Regan, CMPT 128, Sept 2007 6 Representations of Integers Integers are represented by a string of binary digits. signed integer unsigned integer Binary digits are 0’s and 1’s An unsigned integer has values between 0 and 2 N-1. 1 1 1 1 1 1 1 1 8 digits N=8 2 7 + 2 6 +2 5 + 2 4 + 2 3 + 2 2 + 2 1 + 2 128 + 64 + 32 + 16+ 8 + 4 + 2 + 1 = 255 A signed integer has values between -2 N-1 and 2 N-1-1 Converting from a unsigned integer with M bits to a signed integer may require a signed integer of M+1 bits long int variables usually represent numbers with twice as many binary digits as int variables N-1 Binary Digits Sign bit N Binary Digits © Janice Regan, CMPT 128, Sept 2007 7 Floating point numbers A floating point number is represented by a mantissa and an exponent For example 1.23456 * 10 12 The mantissa will be represented by N binary digits. It can take the 2 N-1 values. These values will be at equal intervals between 0 and 0.99999999. These 2 N-1 values are the representable values of the floating point representation. Other values are not representable and are approximated by the nearest representable...
View Full Document

{[ snackBarMessage ]}

### Page1 / 32

lecture3 - 1 © Janice Regan CMPT 128 Jan 2007 CMPT 128...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online