Publications: 84 | Followers: 1

Container Classes & Exception Handling

Publish on Category: Birds 0

Variable Declarations
input valuesoutput valuesstore valuesmodify values
C++ Variable Syntax
declare variables before you use themvariable names must contain only alpha-numeric characters and the underscorevariable names must not begin with a numeric character
Example Names
Legalx, y,xyz_Hello, bob, joe12Illegal12joe, hi-there, go!
Good Practices
Declare variables at the inside top of the main functionGive the variables meaningful namesGood: age,tirePressure, andlateral_distortionNot so good: xUse comments to add further meaningintage; // how long the tire has been installed on the car
Integer Types: short
example declaration:shortshoeSize;shortshoeSize= 5;memory allocation:2 bytesrange of values-215to +215or ~-32k to ~32k
Integer Types: integer
example declaration:intnumCarsOnHwy;intnumBoatsOnLake= 5001;memory allocation:2 or 4 bytes depending on the systemMissouri S&T’s systems use 4 bytesrange of values:-231to +231or ~-2billion to ~2billion
Integer Types: long
example declaration:longdesk_length= 123;longnumKeys;memory allocation:4 bytesrange of values:-231to +231or ~-2billion to ~2billion
Floating Point Types: float
example declaration:floatbodyTemp= 98.6;floatshoeSize;memory allocation:4 bytesprecision:6 significant figures (decimal)
Floating Point Types: double
example declaration:doubleweight_of_mountain= 746538433.55; // tonsmemory allocation:8 bytesprecision:15 significant figures (decimal)
Floating Point Types: long double
example declaration:long doublefeather_wt= 0.000000000000032; // lbsmemory allocation:Not standardizedprecision:Very!
Non-Numeric Types: character
example declaration:charcontinueResponse= ‘y’;memory allocation:1 byterange of values:a char type can take on the 256 possible values of the ASCII character set
Non-Numeric Types: string
example declaration:stringfirstName= “Clayton”;memory allocation:varies on string sizenote:you must use the double quotes for string variable initializations and the single quotes (or ticks) for characters
Non-Numeric Types:boolean
example declaration:boolquit = false;boolpassed = true;memory allocation:1 bytenote:The words true and false are reserved in C++.
Used when a variables value should never be alteredExamplesconst float PI = 3.14159;const double DISTORTION_COEFFICIENT = 5.662398;const float TAX_RATE = 0.023;PI = 4; // NO, will not compile
Const Examples
const short TWO = 2; //badfloat val1, val2, average;average = (val1 + val2) / TWO;const short TWO = 3; // even worsefloat val1, val2, val3, average;average = (val1 + val2 + val3) / TWO;const short DIVISOR = 2; // better
End of Session





Make amazing presentation for free
Container Classes & Exception Handling