Chapter 03 Checkpoints Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

3.1 What header le must be included in programs using cin?

A

3.1

iostream

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

3.2 TRUE or FALSE: cin requires the user to press the [Enter] key when finished
entering data.

A

3.2 True

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

3.3 Assume value is an integer variable. If the user enters 3.14 in response to the following
programming statement, what will be stored in value?
cin&raquo_space; value;
A) 3.14
B) 3
C) 0
D) Nothing. An error message is displayed.

A

3.3 B

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

3.4 A program has the following variable de nitions.
long miles;
int feet;
float inches;
Write one cin statement that reads a value into each of these variables.

A

3.4

cin&raquo_space; miles&raquo_space; feet&raquo_space; inches;

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

3.5 The following program will run, but the user will have dif culty understanding
what to do. How would you improve the program?
// This program multiplies two numbers and displays the result.
#include
using namespace std;
int main()
{
double first, second, product;
cin&raquo_space; first&raquo_space; second;
product = first * second;
cout

A

3.5 Include one or more
cout
statements explaining what values the user should enter.

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

3.6 Complete the following program skeleton so it asks for the user s weight (in
pounds) and displays the equivalent weight in kilograms.
#include
using namespace std;
int main()
{
double pounds, kilograms;
// Write code here that prompts the user
// to enter his or her weight and reads
// the input into the pounds variable.
// The following line does the conversion.
kilograms = pounds / 2.2;
// Write code here that displays the user’s weight
// in kilograms.
return 0;
}

A
3.6
#include 
using namespace std;
int main()
{
double pounds, kilograms;
cout > pounds;
// The following line does the conversion.
// One kilogram weighs 2.2 pounds.
kilograms = pounds / 2.2;
cout
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

3.7 Complete the table below by writing the value of each expression in the Value
column.

Expression Value
6 + 3 * 5
12 / 2 - 4
9 + 14 * 2 - 6
5 + 19 % 3 - 1
(6 + 2) * 3
14 / (11 - 4)
9 + 12 * (8 - 3)
(6 + 17) % 2 - 1
(9 - 3) * (6 + 9) / 3
A
3.7
Value
21
2
31
5
24
2
69
0
30
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

3.8 Write C++ expressions for the following algebraic expressions:

y = 6x
a = 2b + 4c
y x2
=
g
x + 2
z2
= ------------
y
x2
z2
= -----
A
3.8
y = 6 * x;
a = 2 * b + 4 * c;
y = x * x;
or
y = pow(x, 2.0);
g = (x + 2) / (z * z);
or
g = (x + 2.0) / pow(z, 2.0);
y = (x * x) / (z * z);
or
y = pow(x, 2.0) / pow (z, 2.0);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
3.9 Study the following program and complete the table.
#include 
#include 
using namespace std;
int main()
{
double value1, value2, value3;
cout > value1;
value2 = 2 * pow(value1, 2.0);
value3 = 3 + value2 / 2 - 1;
cout
A
3.9
If the user enters… The program displays…
2 6
5 27
4.3 20.49
6 38
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
Complete the following program skeleton so it displays the volume of a cylindrical
fuel tank. The formula for the volume of a cylinder is
Volume = r2h
where
is 3.14159
r is the radius of the tank
h is the height of the tank
#include 
#include 
using namespace std;
int main()
{
double volume, radius, height;
cout > height;
cout > radius;
// You must complete the program.
}
A

3.10
#include
#include
using namespace std;

int main()
{
double volume, radius, height;
cout > height;
cout > radius;
volume = 3.14159 * pow(radius, 2.0) * height;
cout
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
3.11 Assume the following variable de nitions:
int a = 5, b = 12;
double x = 3.4, z = 9.1;
What are the values of the following expressions?
A) b / a
B) x * a
C) static_cast(b / a)
D) static_cast(b) / a
E) b / static_cast(a)
F) static_cast(b) / static_cast(a)
G) b / static_cast(x)
H) static_cast(x) * static_cast(z)
I) static_cast(x * z)
J) static_cast(static_cast(x) *
static_cast(z))
A
3.11 A) 2
B) 17.0
C) 2.0
D) 2.4
E) 2.4
F) 2.4
G) 4
H) 27
I) 30
J) 27.0
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
3.12 Complete the following program skeleton so it asks the user to enter a character.
Store the character in the variable letter. Use a type cast expression with the variable
in a cout statement to display the character s ASCII code on the screen.
#include 
using namespace std;
int main()
{
char letter;
// Finish this program
// as specified above.
return 0;
}
A
3.12
#include 
using namespace std;
int main()
{
char letter;
cout > letter;
cout
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
3.13 What will the following program display?
#include 
using namespace std;
int main()
{
int integer1, integer2;
double result;
integer1 = 19;
integer2 = 2;
result = integer1 / integer2;
cout
A

3.13 9
9.5
9

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

3.14 Write a multiple assignment statement that assigns 0 to the variables total,
subtotal, tax, and shipping.

A

3.14

total = subtotal = tax = shipping = 0;

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

3.15 Write statements using combined assignment operators to perform the following:
A) Add 6 to x.
B) Subtract 4 from amount.
C) Multiply y by 4.
D) Divide total by 27.
E) Store in x the remainder of x divided by 7.
F) Add y * 5 to x.
G) Subtract discount times 4 from total.
H) Multiply increase by salesRep times 5.
I) Divide profit by shares minus 1000.

A
3.15 A)
x += 6;
B)
amount -= 4;
C)
y *= 4;
D)
total /= 27;
E)
x %= 7;
F)
x += (y * 5);
G)
total -= (discount * 4);
H)
increase *= (salesRep * 5);
I)
profit /= (shares – 1000);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
3.16 What will the following program display?
#include 
using namespace std;
int main()
{
int unus, duo, tres;
unus = duo = tres = 5;
unus += 4;
duo *= 2;
tres -= 4;
unus /= 3;
duo += tres;
cout
A

3.16
3
11
1

17
Q

3.17 Write cout statements with stream manipulators that perform the following:
A) Display the number 34.789 in a eld of nine spaces with two decimal places
of precision.
B) Display the number 7.0 in a eld of ve spaces with three decimal places of
precision.
The decimal point and any trailing zeroes should be displayed.
C) Display the number 5.789e+12 in xed point notation.
D) Display the number 67 left justi ed in a eld of seven spaces.

A

3.17 A)

cout

18
Q

3.18 The following program will not compile because the lines have been mixed up.
#include
}
cout

A
3.18
#include 
#include 
using namespace std;
int main()
{
string person = "Wolfgang Smith";
cout
19
Q

3.19 The following program skeleton asks for an angle in degrees and converts it to
radians. The formatting of the nal output is left to you.
#include
#include
using namespace std;
int main()
{
const double PI = 3.14159;
double degrees, radians;
cout > degrees;
radians = degrees * PI / 180;
// Display the value in radians left justified, in fixed
// point notation, with 4 places of precision, in a field
// 5 spaces wide, making sure the decimal point is always
// displayed.
return 0;
}

A
3.19
#include 
#include 
using namespace std;
int main()
{
const double PI = 3.14159;
double degrees, radians;
cout > degrees;
radians = degrees * PI / 180;
cout
20
Q

3.20 Write a short description of each of the following functions:
cos log sin
exp log10 sqrt
fmod pow tan

A

3.20
cos
: Returns the cosine of the argument.
exp
: Returns the exponential function of the argument.
fmod
: Returns the remainder of the first argument divided by the second argument.
log
: Returns the natural logarithm of the argument.
log10
: Returns the base-10 logarithm of the argument.
pow
: Returns the value of the first argument raised to the power of the second
argument.
sin
: Returns the sine of the argument.
sqrt
: Returns the square root of the argument.
tan
: Returns the tangent of the argument.

21
Q

3.21 Assume the variables angle1 and angle2 hold angles stored in radians. Write a
statement that adds the sine of angle1 to the cosine of angle2, and stores the
result in the variable x.

A

3.21

x = sin(angle1) + cos(angle2);

22
Q

3.22 To nd the cube root (the third root) of a number, raise it to the power of 1
3. To
nd the fourth root of a number, raise it to the power of 1
4. Write a statement
that will nd the fth root of the variable x and store the result in the variable y.

A

3.22

y = pow(x, 0.2); // 0.2 is equal to 1/5

23
Q

3.23 The cosecant of the angle a is
Write a statement that calculates the cosecant of the angle stored in the variable a,
and stores it in the variable y.

A

3.23

y = 1 / sin(a);