COSC-1337 Chapter 3 Flashcards
“Prompt”
Lets the user know that input is expected and prompts them as to what they must enter.
A cin object must always be preceded by a “prompt”
What symbol is this? - “»”
Stream-extraction Operator
Gathering input from a users requires what process?
- “Prompting” the user to enter input
2. Using cin object to read input from the keyboard
“Input Buffer” or “Keyboard Buffer”
This is an area of memory where input from the keyboard is temporarily placed before it is converted to the correct value and stored in its variable.
What is an “Expression”?
Is something that can be evaluated to produce a single value.
“Associativity”
is the order in which an operator works with its operands. It is either left-to-right or right-to-left.
What is this for?: algebra = pow(4.0, 2);
It is the variable algebra that has an expression of 4 being raised to the second power.
What header file must be included in order to use the pow function?
What is “type coercion”?
When C++ automatically converts two values to the same type when used with an operator.
char, short, and unsigned short are automatically converted to which type?
int data type
An operator working with a lower value data type and a higher value data type will be promoted to what data type?
The higher value variable data type
When the final value of an expression (with an operator) is assigned to a variable what happens?
It is converted to the data type assigned to the variable
What happens when a floating point number is converted to an int?
It is “truncated” and the decimal gets left out
A ________ lets you manually promote or demote a value
“type cast expression”
What does this do?: static_cast(Value)
This is type conversion. It can be used to convert the data type of a variable to another.
What type cast is this?: pennies = (double)dollar;
Prefix Notation
What type conversion is this?: pennies = float(dollar);
Functional notation
High-order Bit
It is the leftmost bit. If it is 1 the number stored is negative. If it is 0 the number stored is positive.
What is a named constant/variable constant and how is it declared?
It is a variable who has a “read-only” value stored in its memory. You declare it by using “const” before declaring your variable.
How would you assign a value to multiple variables at once?
a = b = c = d = e = 12;
What direction are assignment operations carried out in?
Right to left
How do we write a stream manipulator?
setw(number)
What is the setprecision manipulator and how do we use it?
It is used to specify how many decimals we would like to be included in our cout display. It can be used as such - cout «_space;setprecision(number) «_space;variable;
How would we a float number display only 4 digits after the decimal?
cout «_space;fixed «_space;setprecision(4) «_space;variable;
How would we display the digits after a decimal even if they are zeros?
cout «_space;fixed «_space;showpoint «_space;setprecision(number) «_space;variable;
We would use the showpoint manipulator
What header file is needed for setw and setprecision?
The header file iomanip
What manipulators remain in effect till the programmer changes them?
setprecision, fixed, showpoint
When is showpoint not needed in your source code?
When fixed and setprecision are already being used.
How would you make text be left or right justified?
You would use the “left” or “right” manipulator
How do we input a string?
getline(cin, variable);
What is a member function of cin?
“get” is a member function of cin
What does cin.get(variable); do?
It will receive any character as input EVEN A WHITESPACE OR THE ENTER KEY!
How do we skip or “ignore” characters?
cin.ignore(n, c);
This will make the program skip “n” number of characters OR to include everything until character “c” is encountered
How do we find out the length of a string literal?
variable.length();
How do we assign 22 spaces to the variable named x?
x.assign(22, ‘ ‘);
What is a C-string and how can we write one?
It is essentially an array. It was the way that C used to store string literals.
char example[10] = “Timmy”;
How would we assign a string to a c-string?
We would need to use “strcpy”.
char example[32];
strcpy(example, “This is our c-string text”);
How do we give a c-string memory bytes?
With the “size declarator”
What are two ways that we can prevent buffer overrun?
- setw();
2. cin.width();
What header file must we include to be able to use the rand() function?
cstdlib
How would we generate a random number based on the input from the user?
By creating a variable that would store the input “seed” value and then using the “stand(variable);” function to start the algorithm with the input “seed”.
How would you randomly generate a seed without user input?
You would use the “time” function AND you would pass a “0” to its argument
What header file must be included to use the time function?
ctime
How would we get a random number generated between 10-25?
int x;
x = srand(seed) % (MAX - MIN + 1) + MIN;