Input & Output: Console. Console – term is left over from days of mainframes and refers to the monitor display and keyboard entry Input from the keyboard (console input) cin >> marked_price ; (Note: input goes INTO the memory storage location defined as marked_price )
The \ (backslash) character has a special significance. It is used to ‘escape’ or change the meaning of the character that follows it. The combination of the \ and the following character is called an ‘escape sequence’
Note: Never put a space in the middle of an escape sequence
//This is an example of a program that utilizes the console out object and escape sequences
using namespace std;
cout<< "Some Common Escape Sequences";
cout<< "Single Quote\t\\\'";
cout << "Double Quote\t\\\"";
body_weight_pounds or body_weight_lbs
Program variables must be defined not only by a name but also by a data type. The type declaration statement determines how the value of the variable is stored. Below are typical storage sizes and ranges for different types.
short 2 bytes -32,768 to +32,767
unsigned short 2 bytes 0 to 65,535
int 4 bytes -2,147,483,648 to +2,147,483,647
unsigned int 4 bytes 0 to 4,294,967,295
long 4 bytes -2,147,483,648 to +2, 147,483,647
unsigned long 4 bytes 0 to 4,294,967,295
What storage size is guaranteed on all systems?
int is at least as large as short int
long int is as least as large as int
unsigned short is the same size as short
unsigned int is the same size as int
unsigned long is the same size as long
The sizeofspecial operator can be used to determine the storage size on any given computing platform.
Real numbers (floating point numbers) are stored in a format similar to scientific notation.
2,498,230.668 is 2.498231668 x 106 where 2.498231 is called the mantissa and 6 is the exponent
.0034459 is 3.4459 x 10-3 where 3.4459 is the mantissa and -3 is the exponent
For computer storage purposes these numbers would be written as 2498231668E6 and 34459E-3
A designated part of the allocated memory space is used for the mantissa and the rest for the exponent. One bit is used for the sign.
Below are the data types with storage sizes typically found on PCs.
float 4 bytes 3.4E-38 to 3.4E38
double 8 bytes 1.7E-308 to 1.7E308
long double 8 bytes 1.7E-308 to 1.7E308
Note: Remember the computer actually stores both the mantissa and exponent in binary. Although the exponent being an integer can be stored exactly, the mantissa may not be able to be stored exactly and at some point will be truncated.
Ex. .1 or 1/10 decimal = 0.0001100110011... (binary) where … means the pattern repeats.
Characters are internally represented by numbers and thus can be thought of as a type of integer. Most systems use the ASCII (American Standard Code for Information Interchange) convention for the storage of characters.
Strings are a sequence of characters stored in consecutive memory locations. We will be talking more about this later.
ASCII characters 0 to 127Code 0 to 31 (and # 127) are non-printing, mostly obsolete control charactersthat affect how text is processed. There are 95 printable characters.To print one, press the ALT key (hold it down) and type the decimal number.
an extended ASCII set
A string is a sequence of characters and is stored using the string ‘class’. You must include a preprocessor directive (#include <string>) if you want to use a string type variable. “”s must be around the literal assigned to a string variable.
The sequence of char that make up a string is stored in consecutive memory locations and the end is marked with a null (ASCII 0) character.
Note: The ASCII code for the char 0 (zero) is 48. We use \0 to represent
the null character.
Also Note: char literals use single quotes. string literals use double quotes.
‘T’ takes up one byte of memory but “T” requires two bytes.
bool (boolean) data have values of either ‘true’ or ‘false’
Needless to say this value is represented numerically where true is represented by 1 and false by 0
Literals that may need to be changed in the future can be given a name.
const float PI = 3.1415;
constint MAX_VACATION_HRS = 120;
As a programmer you should know how the computer stores numerical data in memory.
EVERYTHING is stored using 0’s and 1’s.
Binary representation of numbers is essential to understanding data types and some of the nuances resulting from binary representation.
Let’s look at binary vs. decimal and how integers are stored in memory.