Test Questions & Answers Ch3 Expressions And Interactivity - Test Bank | C++ Control Structures 9e by Tony Gaddis. DOCX document preview.

Test Questions & Answers Ch3 Expressions And Interactivity

Starting Out with C++ from Control Structures to Objects, 9e (Gaddis)

Chapter 3 Expressions and Interactivity

TRUE/FALSE

1. When the fixed manipulator is used, the value specified by the setprecision manipulator will be the number of digits to appear after the decimal point.

2. The only difference between the get function and the >> operator is that get reads the first character typed, even if it is a space, tab, or the [Enter] key.

3. The cin << statement will stop reading input when it encounters a newline character.

4. If you want to know the length of the string that is stored in a string object, you can call the object's size member function.

5. Arithmetic operators that share the same precedence have right to left associativity.

6. When C++ is working with an operator, it strives to convert the operands to the same type.

7. When a program uses the setw manipulator, the iosetwidth header file must be included in a preprocessor directive.

8. The following statement will output $5.00 to the screen:

cout << setprecision(5) << dollars << endl;

9. In C++, it is impossible to display the number 34.789 in a field of 9 spaces with 2 decimal places of precision.

10. The fixed manipulator causes a number to be displayed in scientific notation.

MULTIPLE CHOICE

1. The __________ causes a program to wait until information is typed at the keyboard and the [Enter] key is pressed.

a.

output stream

b.

cin object

c.

cout object

d.

preprocessor

e.

None of these

2. The __________ operator always follows the cin object, and the __________ operator follows the cout object.

a.

binary, unary

b.

conditional, binary

c.

>>, <<

d.

<<, >>

e.

None of these

3. Which of the following must be included in any program that uses the cin object?

a.

compiler

b.

the header file iostream

c.

linker

d.

brackets

e.

None of these

4. When a user types values at the keyboard, those values are first stored

a.

as ASCII characters

b.

in the header file iostream

c.

in the keyboard buffer

d.

as integers

e.

None of these

5. Which of the following will allow the user to input the values 15 and 20 and have them stored in variables named base and height, respectively?

a.

cin << base << height;

b.

cin base, height;

c.

cin >> base >> height;

d.

cin base >> cin height;

e.

None of these

6. What will be displayed after the following statements execute?

int num1 = 5;

int num2 = 3;

cout << "The result is " << (num1 * num2 + 10) << endl;

a.

The result is 5 * 3 + 10

b.

The result is (num1 * num2 + 10)

c.

The result is 25

d.

The result is 65

e.

None of these

7. What is the value of result after the following statement executes?

result = (3 * 5) % 4 + 24 / (15 - (7 - 4));

a.

-6.4

b.

5

c.

1.6

d.

2.25

e.

None of these

8. In the following statement, what will be executed first according to the order of precedence?

result = 6 - 3 * 2 + 7 - 10 / 2;

a.

6 - 3

b.

3 * 2

c.

2 + 7

d.

10 / 2

e.

7 - 10

9. Associativity is either right to left or

a.

top to bottom

b.

front to back

c.

left to right

d.

undeterminable

e.

None of these

10. What is the value of x after the following code executes?

int x = 0;

int y = 5;

int z = 4;

x = x + y + z * 2;

a.

18

b.

0

c.

13

d.

26

e.

unknown

11. What is the value of average after the following code executes?

double average;

average = 1.0 + 2.0 + 3.0 / 3.0;

a.

2.0

b.

3.0

c.

4.0

d.

2

e.

unknown

12. What is the value of cube after the following code executes?

double cube, side;

side = 5.0;

cube = pow(side, 3.0);

a.

25.0

b.

15.0

c.

125.0

d.

8.0

e.

unknown

13. When the final value of an expression is assigned to a variable, it will be converted to

a.

the smallest C++ data type

b.

the largest C++ data type

c.

the data type of the variable

d.

the data type of the expression

e.

None of these

14. When C++ is working with an operator, it strives to convert operands to the same type. This is known as

a.

type correction

b.

type conversion

c.

promotion

d.

demotion

e.

None of these

15. When a variable is assigned a number that is too large for its data type, it

a.

underflows

b.

overflows

c.

reverses

d.

converts

e.

None of these

16. What is the value of x after the following code executes?

int x;

x = 3 / static_cast<int>(4.5 + 6.4);

a.

0.3

b.

0

c.

0.275229

d.

3.3

e.

None of these

17. Which statement is equivalent to the following?

number += 1;

a.

number = number + 1;

b.

number = 1;

c.

number + 1;

d.

number =+ 1;

e.

None of these

18. Which statement is equivalent to the following?

number = number * 2;

a.

number = pow(number, 2);

b.

number *= 2;

c.

number = number * number;

d.

number * 2 = number;

e.

None of these

19. What is the value of number after the following statements execute?

int number = 10;

number += 5;

number -= 2;

number *= 3;

a.

3

b.

30

c.

39

d.

2

e.

None of these

20. This manipulator is used to establish a field width for the value that follows it:

a.

field_width

b.

set_field

c.

setw

d.

iomanip

e.

None of these

21. This manipulator causes the field to be left justified with padding spaces printed to the right:

a.

left_justify

b.

right

c.

left

d.

left_pad

e.

None of these

22. You can control the number of significant digits in your output with the __________ manipulator.

a.

setprecision

b.

set_precision

c.

to_fixed

d.

setfixed()

e.

None of these

23. This manipulator forces cout to print digits in fixed-point notation:

a.

setprecision(2)

b.

setw(2)

c.

fixed

d.

setfixed(2)

e.

None of these

24. What is true about the following statement?

cout << setw(4) << num4 << " ";

a.

It allows four spaces for the value in num4.

b.

It outputs "setw(4)" before the value in num4.

c.

It is incorrect because it should use setw(10).

d.

It is incorrect because it should use setw(num4).

25. Which of the following statements will pause the screen until the [Enter] key is pressed?

a.

cin;

b.

cin.getline();

c.

cin.get();

d.

cin.ignore();

e.

cin.input();

26. Which of the following statements will allow the user to enter three values to be stored in variables length, width, and height, in that order?

a.

cin << length, width, height;

b.

cin.get(height, width, length);

c.

cin.get(length, width, height);

d.

cin >> length; width; height;

e.

cin.get(length >> width >> height);

27. Which of the following functions tells the cin object to skip one or more characters in the keyboard buffer?

a.

cin.ignore

b.

cin.jump

c.

cin.hop

d.

cin.skip

e.

None of these

28. __________ reads a line of input, including leading and embedded spaces, and stores it in a string object.

a.

cin.get

b.

getline

c.

cin.getline

d.

get

e.

None of these

29. Which of the following statements will read an entire line of input into the string object, address?

a.

cin << address;

b.

cin address;

c.

cin.get(address);

d.

getline(cin, address);

e.

cin.get(length >> width >> height);

30. How many characters will the following statement read into the variable myString?

cin >> setw(10) >> myString;

a.

9

b.

10

c.

11

d.

however many characters are in myString

e.

None of these

31. The function pow(x, y), requires which header file?

a.

cstdlib

b.

cstring

c.

iostream

d.

cmath

e.

iomanip

32. To use the rand()function, you must include the __________ header file?

a.

cstdlib

b.

cstring

c.

iostream

d.

cmath

e.

iomanip

33. Which of the following functions will return the value of x, rounded to the nearest whole number?

a.

abs(x)

b.

fmod(x)

c.

sqrt(x)

d.

round(x)

e.

whole(x)

34. Which line in the following program will cause a compiler error?

1 #include <iostream>

2 using namespace std;

3

4 int main()

5 {

6 const int MY_VAL = 77;

7 MY_VAL = 99;

8 cout << MY_VAL << endl;

9 return 0;

10 }

a.

line 6

b.

line 7

c.

line 8

d.

line 9

e.

there will be no compiler error

35. A debugging process where you, the programmer, pretend you are a computer and step through each statement while recording the value of each variable at each step is known as

a.

error checking

b.

hand writing

c.

hand tracing

d.

error handling

e.

None of these

Document Information

Document Type:
DOCX
Chapter Number:
3
Created Date:
Aug 21, 2025
Chapter Name:
Chapter 3 Expressions And Interactivity
Author:
Tony Gaddis

Connected Book

Test Bank | C++ Control Structures 9e

By Tony Gaddis

Test Bank General
View Product →

$24.99

100% satisfaction guarantee

Buy Full Test Bank

Benefits

Immediately available after payment
Answers are available after payment
ZIP file includes all related files
Files are in Word format (DOCX)
Check the description to see the contents of each ZIP file
We do not share your information with any third party