Chapter 03 Flashcards

1
Q
  1. Assume that the following variables are defined:
    int age;
    double pay;
    char section;
    Write a single cin statement that will read input into each of these variables.
A

1.

cin&raquo_space; age&raquo_space; pay&raquo_space; section;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  1. Assume a string object has been defined as follows:
    string description;
    A) Write a cin statement that reads in a one-word string.
    B) Write a statement that reads in a string that can contain multiple words separated
    by blanks.
A

A)
cin&raquo_space; description;

B)
getline (cin,description);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
3. What header files must be included in the following program?
int main()
{
double amount = 89.7;
cout << showpoint << fixed;
cout << setw(8) << amount << endl;
return 0;
}
A
#include 
#include
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
28 / 4 - 2
6 + 12 * 2 - 8
4 + 8 * 2
6 + 17 % 3 - 2
2 + 22 * (9 - 7)
(8 + 7) * 2
(16 + 7) % 2 - 1
12 / (10 - 6)
(19 - 3) * (2 + 2) / 4
A
5
22
20
6
46
30
0
3
16
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  1. Assume a program has the following variable definitions:
    int units;
    float mass;
    double weight;
    and the following statement:
    weight = mass * units;
    Which automatic data type conversion will take place?
    A) mass is demoted to an int, units remains an int, and the result of mass * units is
    an int.
    B) units is promoted to a float, mass remains a float, and the result of mass *
    units is a float.
    C) units is promoted to a float, mass remains a float, and the result of mass *
    units is a double.
A

c

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
7. Assume a program has the following variable de nitions:
int a, b = 2;
float c = 4.2;
and the following statement:
a = b * c;
What value will be stored in a?
A) 8.4
B) 8
C) 0
D) None of the above
A

b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  1. Assume that qty and salesReps are both integers. Use a type cast expression to
    rewrite the following statement so it will no longer perform integer division.
    unitsEach = qty / salesReps;
A

unitsEach = static_cast(qty)/salesReps;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  1. Rewrite the following variable definition so the variable is a named constant.
    int rate;
A

9.

const int RATE = 12;

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

10 Complete the following table by writing statements with combined assignment operators
in the right-hand column. The statements should be equivalent to the statements
in the left-hand column.

x = x + 5;
total = total + subtotal;
dist = dist / rep;
ppl = ppl * period;
inv = inv - shrinkage;
num = num % 2;
A
x +=5;
total +=subtotal;
dist/=rep;
ppl*=period;
inv-=shrinkage;
num%=2
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
11. Write a multiple assignment statement that can be used instead of the following group
of assignment statements:
east = 1;
west = 1;
north = 1;
south = 1;
A

east = west = north = south = 1;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
  1. Write a cout statement so the variable divSales is displayed in a field of 8 spaces, in
    fixed point notation, with a precision of 2 decimal places. The decimal point should
    always be displayed.
A

cout

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
  1. Write a cout statement so the variable totalAge is displayed in a field of 12 spaces,
    in fixed point notation, with a precision of 4 decimal places.
A

13.
cout &laquo_space;setw(12) &laquo_space;fixed
&laquo_space;setprecision(4) &laquo_space;totalAge;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
  1. Write a cout statement so the variable population is displayed in a field of 12
    spaces, left-justified, with a precision of 8 decimal places. The decimal point should
    always be displayed.
A

cout

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
  1. The __________ library function returns the cosine of an angle.
A

cos

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
  1. The __________ library function returns the sine of an angle.
A

sin

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
  1. The __________ library function returns the tangent of an angle.
A

tan

17
Q
  1. The __________ library function returns the exponential function of a number.
A

exp

18
Q
  1. The __________ library function returns the remainder of a floating point division.
A

fmod

19
Q
  1. The __________ library function returns the natural logarithm of a number.
A

log

20
Q
  1. The __________ library function returns the base-10 logarithm of a number.
A

log10

21
Q
  1. The __________ library function returns the value of a number raised to a power.
A

pow

22
Q
  1. The __________ library function returns the square root of a number.
A

sqrt

23
Q
  1. The __________ file must be included in a program that uses the mathematical functions.
A

include