CS chapter 2
Integer and Long Integer Constants
If you need to change the way something is stored in memory, example if you have an integer constant but you need it to be stored in memory as a long integer, place an L at the end of the number int floors = 15; int floors = 15L;
String Class
#include <string> Next step in using the string class is to define a string type variable, called a string object. string movieTitle; you can assign a string literal to the object movieTitle = "All Anal Final Chapter" used like a regular variable
Multi-line comments
/* and *\ when using these to make comments, just pretend the start marks the beginning and end.
char Data Type
A variable of the char data type only holds a single character and one byte of memory. Similar to integers because they are stored internally as integers char letter = 'A' notice how the character literal is enclosed in single quotation marks.
Fundamental Operators
Addition operator Subtraction operator Multiplication operator Division operator Modulus operator computes the remainder of an integer divided
ASCII
American Standard Code for Information Interchange. When a character is stored in memory, it is actually its numeric code that is stored. ASCII has a set of character sets to see which integer value is used to store a character
bool Data Type
Boolean variables are either set to True or False. Expressions that have a true or false value are called Boolean expressions, nameed in honor of English mathematician George Boole An integer variable which stores 0 for false and 1 for true. int main() { bool boolValue; boolValue = true cout << boolValue << endl; boolValue = 0 cout << boolValue << endl; output is: 1 0
Floating-Point Data Types
Floating-point data types are used to define variables that can hold real numbers (fractional values). Stored in a manner similar to scientific notation, called E notation. float double long double
key words
Key Words make up the "core" of a language and have specific purposes
C++ basic data types
Numeric and character.
Character and Literal Strings
Printable characters are internally represented by numeric codes. Most computers use ASCII codes for this purpose Characters normally occupy a single byte of memory Strings are consecutive sequences of characters that occupy consecutive bytes of memory String literals have a null terminator at the end. This marks the end of a string Character literals are enclosed in double quotation marks String literals are enclosed in double quotation marks Escape sequences such as "\n" are stored internally as a single character
Hexadecimal and Octal Constants( enrichment)
Programmers often express values in numbering systems other than decimal (or base 10). Hexadecimal (base 16) and octal (base 8). You express a Hexadecimal by placing an 0x in front of them. Octal numbers must be preceded by 0 0xF4 0F4
C++ string class
Standard C++ provides a special data type for storing and working with strings. Using string class is used to make string type varibles.
Legal Identifiers
The first character must be one of the letters a through z, A through Z, or an underscore character ( _ ) After the first character you may use the letters a through z or A through Z, the digits 0 through 9, or underscores Uppercase and lowercase characters are distinct. This means ItemsOrdered is no the same as itemsordered
Arithmetic Operators
There are many operators for manipulating numeric values and performing arithmetic operations. Three types of operators are unary, binary, and ternary. These depend on the number of operands required
Variables, Literals, and the Assignment Statement
Variables represent storage locations in the computer's memory. Literals are constant values that can be assigned to variables
<<
When used to send the string "Programming is fcking awesome" to cout, it is called the stream-insertion operator
Pseudocode
a computer programming language that resembles plain English that cannot be compiled or executed, but explains a resolution to a problem
Range Bit Patterns
a data type that stores data in two bytes of memory can hold 16 bits of information. This means it can store 2^16 bit patterns, which is 65,536 different combinations of zeros and ones. The short data type, stores both positive and negative numbers, so it uses its 16 bits to represent the values from -32,768 to +32,767
Assigning floating-point values to integer variables
a floating-point variable shouldn't be assigned to an integer variable since the value after the decimal will be discarded or truncated floating-point variables can hold much larger numbers than integers can
Identifiers
a programmer-defined variable name that should indicate what the variable is used for.
Determining the size of a data type
a special operator called sizeof will report the number of bytes of memory used by any data type or variable. cout << "The size of an integer is " << sizeof(int);
endl or end-line
a stream manipulator to instruct cout to start a new line
Literal
a value that cannot change during the program's execution. Literals are also called constants for this reason. Many programmers refer to them as literals when they hold strings or characters and as constants when they hold numbers, such as integers. Referred to as a literal or literals, a literal string is a series of characters enclosed in double or single quotes depending on the programming language or command line being utilized
Scope
a variable's scope is the part of a program that has access to the variable. A rule of scope is that a variable cannot be used in any part of the program before it is defined
Stream Object
an object that works with streams of data
float, double, long double
are three data types that can represent float-point numbers (positive and negative) The float data is a single precision. Double is twice as big as a float which is a double precision. A long double is twice as big as a double.
Numerica Data Types
broken into two categories: integers and floating-point
Preprocessor Directives
commands to the preprocessor which runs prior to the compiler. Do not use semicolons at end of this because they are not C++ statements
cout Object
cout is used to display information on the computer's screen. Classified as a stream object meaning it works with streams of data. To print a message on the screen you need to send a stream of characters to cout.
\n
example of an escape sequence. Can be used to skip a line just like endl
Integer Data Type
there are many different types of data. Variables are classified according to their data type, which determines the kind of information that may be stored in them. Integer variables can only hold whole numbers
Term website
http://www.computerhope.com/
Operators
is an object that is capable of manipulating a value or operator. For example, in "1 + 2", the "1" and "2" are the operands and the plus symbol is the operator.
Variable
named storage location for holding data. Allow you to store and work with data in the computer's memory
Floating-Point Constants
normally stored in memory as doubles. In case you need to force a constant to be stored as a float, you can append the letter F or f to the end of it 1.2F 45.907f Append an L to be stored as a long double. The compiler won't confuse this because
Comments
notes of explanation that document lines or sections of a program
Assignment Statement
number = 9
C++ doesn't allow commas in _______
numbers An 19,000 cannot be used. 19000 C++ doesn't allow commas inside numeric constants
Data types
short unsigned short int unsigned int long unsigned long
Placing quotation marks around a variable makes it a _______
string literal cout << "Hey dick face" << ;
Variable Defintition
tells the compiler the variable's name and the type of data it will hold. Definition gives the data type first, then the name of the variable, and ends with a semicolon int number;
#include Directive
the #include directive causes the contents of another file to be inserted into the program. Must contain the name of the file you wish to include in the program #include < >
Operands
the data that operators work on. The assignment operator has two operands unitsSold = 13 operands : unitsSold, 13
Assignment Operator
the equal sign = This operator copies the value on its right into the variable named on its left. number = 9
Stream-insertion operator
the item is immediately to the right of the operator is inserted into the output stream that is sent to cout to be displayed on the screen
E Notation
the number 47,281.97 would be 4.728197E4. The first part of the number is called the mantissa. The part of the number before the E is the mantissa, and the part after the E is the power of 10. When a floating-point number is stored in memory, it is stored as the mantissa and the power of 10.
Size
the number of bytes a data type can hold. The larger the size of a data type the greater range of values it can hold
lvalue
the right side of an assignment operator must be an lvalue. An lvalue is any expression that has value. Could be a number or just a calculation.
Determining the size of a Data type
the sizeof operator may be used to determine the size of a data type on any system. A special operator called sizeof will report the number of bytes of memory used by any data type or variable. cout << "hey hey hey! " << sizeof(int);
Initialization
when a value is assigned to a variable as part of the variable's definition or assigning values to variables when they are defined
Considerations for numeric variable
whether the variable needs to hold integers or floating-point variables the largest and smallest numbers needs to be able to store whether the variable needs to hold signed (both positive and negative) or only unsigned (just zero and positive) number the number of decimal places of precision needed for values stored in the variable