- input/output stream int - integer cout<<”Message: ”; - Output Message cin - input A true statement is one that evaluates to a nonzero number. 2 == 2 evaluates to a 1 A false statement evaluates to zero. 0 == 2 evaluates to 0 “If” statements allow the flow of the program to be changed and so they allow algorithms. For example, by using an if statement to check a user entered password, your program can decide whether a user is allowed access to the program. NOT: The NOT operator accepts one input. If that input is TRUE, it returns FALSE, and if that input is FALSE, it returns TRUE. NOT is written as ! AND: AND returns TRUE if both inputs are TRUE. AND operator is written &&. OR: If either (or both) of the two values it checks are TRUE then it returns TRUE. For example, (1) OR (0) evaluates to 1. (0) OR (0) evaluates to 0. The OR is written as || There can be more than one argument passed to a function or none at all (where the parentheses are empty) Functions that do not return values have a return type of void a function can be used even if there is no definition. However, the code cannot be run without a definition even though it will compile Return is the keyword used to force the function to return a value The general format for a prototype is simple: (*function): return-type function_name ( arg_type arg1, ..., arg_type argN ); int mult ( int x, int y ); Switch case statements are a substitute for long if statements that compare a variable to several "integral" values ("integral" values are simply values that can be expressed as an integer, such as the value of a char). Switch case statements are a substitute for long if statements that compare a variable to several "integral" values The value of the variable given into switch is compared to the value following each of the cases, and when one value matches the value of the variable, the computer continues executing the program from that point. The condition of a switch statement is a value. The case says that if it has the value of whatever is after that case then do whatever follows the colon. The break is used to break out of the case statements. Break is a keyword that breaks out of the code block, usually surrounded by braces default case is optional, but it is wise to include it as it handles any unexpected cases using pointers is one way to have a function modify a variable passed to it Pointers "point" to locations in memory Pointers are just variables that store memory addresses, usually the addresses of other variables Pointer Syntax: *; int *int_points_to_integer; if you declare multiple pointers on the same line, you must precede each of them with an asterisk: to use the pointer to access information simply use the name of the pointer without the * However, to access the actual memory location, use the * call_to_function_expecting_memory_address(pointer); To get the memory address of a variable (its location in memory), put the & sign in front of the variable name (int x; int *p; p = &x; ) The delete operator frees up the memory allocated through new ( delete ptr ) After deleting a pointer, it is a good idea to reset it to point to 0 then the pointer becomes a null pointer (points to nothing) New is the proper keyword to allocate memory Delete is the proper keyword to deallocate memory Array Syntax: int arrayname [100 ]; This would make an integer array with 100 slots, or places to store values(also called elements) Two-Dimensional Array Syntax: int 2dimensionalarray [8][8]; You can modify one Array value in it by putting: arrayname [arraynumber] = whatever; Arrays do not require reference operators to have a pointer to a string like other variables. char *ptr; int *ptr; char str[40]; VS. int num; ptr = str; ptr = # foo; gives the memory address of the first element in an array foo (an array with 100 elements. Foo[6]; accesses the 7th element in an array foo. (First is always 0 in any array) char string [50]; in a fifty char array you could only hold 49 letters and one null character at the end to terminate the string. char *array; can also be used as a string (old syntax from C programming) ‘\n’ lets the complier know to start a new line. strcmp will accept 2 strings. (Case sensitive) int strcmp (const char *sl, const char *s2); strcmp passes the address of the character array to the function strcat short for string concatenate. Means add to the end or append. Adds the 2nd string to the first string strcpy short for string copy. strlen will return the length of a string minus the terminating character (‘\0’) fstream - header file for I/O, use to include ifstream and ofstream ifstream Syntax: ifstream a_file; or ifstream a_file ( “filename” ); both of the above classes have an open and close command. Close files are not required. Open and Close Syntax: (a_file.open()) (a_file.close()) default mode for opening a file with ofstream's constructor is to create it if it does not exist, or delete everything in it if something does exist in it ios::app - Append to the file ios::ate - Set the current position to the end ios::trunc - Delete everything in the file Syntax: ofstream a_file ( “test.txt”, ios::app ); Typecasting is making a variable of one type, such as an int, act like another type. Classes?Functions?Variables? Classes must always contain two functions: a constructor and a destructor class name denotes a constructor, a ~ before the class name is a destructor destructors are always called when the class is no longer usable Neither constructors nor Destructors return arguments or values.