Review the C++ programming concepts including:
Programs are all about the manipulation of data, converting some input data into the necessary output data. For games it is about taking audio, cursor movements, and commands and processing them generating movement within the game, actions within the game, updates to the screen and communications with partners. For autonomous robots it is about taking input from sensors and determining movements and new display outputs.
There are a number of pre-defined data types available for use, including:
Variables are user defined named memory locations that contain a value of a specific type. Definitions start with a type followed by the variable name followed by a semicolon. Examples:
Variable selection: Choose a variable with the range and precision to handle the values of interest. An example: Use an integer to represent money values instead of float or double. Performing math operations on floats and doubles can introduce small errors so that the values won't exactly match an integer value such as zero. This occurs because not all fractional value can be represented exactly with the float or double precision. An example: 1/9 is a decimal point followed by repeating 1. But the data representation has a limited space and truncates when this space is exhausted. Multiplying the variable by 9 generates a decimal point followed by a repeating 9. This value does not equal 1. With money its best to use representation in cents to prevent errors due to precision.
Always use constants instead of numbers in your programming! Define the constants at the top of the program or header file. Constants may take two forms:
Constant variables generate a memory referenced at runtime. With appropriate values, defines are integrated into the instructions and may prevent a memory reference. With defines the compiler chooses how to represent the data, whether to place it in one or more instructions or to use a memory reference. When a memory reference is used, the compiler and linker may not be able to reduce all the references to a single value in memory. This latter case is where a constant variable is best.
Always add constructors to initialize all data values! When allocating classes from the heap they are not initialized. As such, bad values in values can cause undesired behavior and bad pointer values can cause CPU crashes (access violations).
Classes that allocate any object from the heap should always use a destructor to free the object.