Chapter 3 Flashcards

1
Q

how do you express 2^4 in C++?

A

pow(2.0, 4.0)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

expression

A

a programming statement that has a value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

type coercion

A

C++ automatically converts operands to the same type when working with an operator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

overflow and underflow

A

when a value is above or below the acceptable range of a data type. It will wrap around and start from the opposite end.
Ex: short is within -32767 and 32767
x = 32767 is 32767
x = 32768 is -32767
x = -32768 is 32767

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

type casting

A

performs manual data type conversion
static_cast<DataType>(Value)</DataType>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

multiple assignment

A

to assign the same value to several variables with one statement
Ex: a = b = c = 12

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

setw()

A

stream manipulator that specifies the field width for the value immediately following it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

<cmath>
</cmath>

A

required for advance math formulas… pow, cos, sin, abs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

<iomanip>
</iomanip>

A

required for formatting manipulators: setw, setprecision, fixed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

setprecision()

A

controls the number of significant digits with floating-point values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

fixed manipulator

A

set the number of digits to the right of a decimal point specified by setprecision. change scientific notation to standard notation.
Ex: setprecision(2) &laquo_space;fixed;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

showpoint manipulator

A

allows padding with trailing zeros
Ex: setprecision(2) &laquo_space;showpoint;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

left and right manipulators

A

left &laquo_space;setw(10);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

getline()

A

function that reads an entire line, including leading and embedded spaces, and stores it in a string object.
geline(cin, variableName)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

member function

A

a function that is built into an object
Ex: cin.get() where the get() is a member function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

cin.get()

A

waits until the user enters a character. This works even is just a space or no character is entered.

17
Q

cin.ignore()

A

tells the cin object to skip one or more characters in the keyboard buffer
Ex: cin.ignore(); // skip newline character

18
Q

<random>
</random>

A

allow the use of random

19
Q

random device engine

A

generates a sequence of random bits
random_device myEngine;

20
Q

distribution object

A

reads the random bits generated by the random number engine and produces random numbers of a specified data type, within a specific range.
uniform_int_distribution<int> randomInt(0, 100);</int>

21
Q

How do you display a random number from 1 to 100?

A

include <random></random>

random_device myEngine;
uniform_int_distribution<int> randomInt(0, 100);
cout << randomInt(myEngine);</int>

22
Q

How do you display a random floating-point number from 1 to 100?

A

random_device myEngine;
uniform_real_distribution<double> randomReal(0.0, 1.0);
double number = randomReal(myEngine);
cout << number;</double>