1/28
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
stream extraction operator
», used with cin
cmath header file
Allows for more complex math, like exponents (pow(x, y))
Type conversion
When two variable are different data types, they must be converted to the same to use them together
Type coercion
When a computer automatically uses type conversion
Overflow & Underflow
When a value is too big for its data type, it will automatically become the smallest number possible, and vice versa
Type casting
Manually promoting or demoting a variable’s data type like so:
static_cast<long int>(variableName)
Multiple assignment
Assigning multiple variables the same value like so:
a = b = c = 12
Combined assignment
When a variable’s previous value is used in its own assignment:
myFoo = myFoo + 1
setw()
Stands for set width. Determines the MINIMUM width of cout by adding whitespace IF NEEDED. Number goes in parentheses
<iomanip>
Header file, required for setw and setprecision.
Setprecision()
Controls how many digits of a int or float will be displayed.
Note that this does not round, it truncates
Fixed
Use after setprecision. This controls how many decimal digits will be displayed on a float or int. Note that 5.5 would turn into 4.70000 if you used setprecision(5)
used with setpre. or by itself also makes all numbers stay as digits and not scientific notation
Showpoint
Use after setprecison. Without showpoint, setprecision takes away numbers if needed. With showpoint, it will add zeroes if there are too few.
Left
Used with setw(), and will push the value to the left side, and not the right. This will continue throughout all of the code unless right is used.
getline()
cin function that takes as much data until [Enter] is pressed, including spaces.
Has two parameters. Input (cin), then the variable to store it to
getline(cin, myString)
Cin.get()
cin function that takes one input, no matter what, including a space or a enter key. One parameter, which is the variable to store the input to.
cin.ignore()
cin function that deletes a certain number of characters inputted, or leftover characters from past cin’s, like \n. Can take between 0 and 2 parameters
Deletes the next character
Use one number. Deletes that many characters
Use one character or something like \n. Either deletes all letters leading up to that character, including that character, or deletes the amount of characters specified in 1. Whichever comes first.
Random number engine
Creates a bunch of random binary. We use random_device engine in this class. Looks like the following:
random_device myEngineVariable
Now random_device has been set to the variable
Distribution object
Translates random binary from the random number engine into numbers.
We use uniform_int_distribution in this class. Looks like so:
uniform_int_distribution<int> myDistObj(0, 100)
Generating random numbers
Use pre-initialized distribution object and random number engines, then do the following
randomNumberOutput = myDistObj(myEngine)