Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Login

Register Now

Welcome to All Test Answers

Chapter 03 Starting out with C++ Expressions and Interactivity


 

Download  file with the answers

Not a member!
Create a FREE account here to get access and download this file with answers


 

Chapter Three

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 the above

 

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 the above

 

3. In any program that uses the cin object, you must include the ___________.
a. compiler
b. iostream header file
c. linker
d. >> and << operators
e. None of the above

 

4. ___________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

 

5. When this operator is used with string operands it concatenates them, or joins them together.
a. &
b. *
c. %
d. +
e. None of the above

 

6. What is the value stored at x, given the statements:

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

a. .3
b. 0
c. .275229
d. 3.3
e. None of these

 

7. This function 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 the above

 

8. The function, pow(x, 5.0), requires this header file.
a. cstdlib
b. cmath
c. cstring
d. iostream
e. iomanip
.

 

9. You want the user to enter the length, width, and height from the keyboard. Which cin statement is correctly written?
a. cin << length, width, height; b. cin.get(length, width, height); c. cin >> length >> width >> height;
d. cin >> length, width, height;
e. cin << length; width; height;

 

10. You can use these to override the rules of operator precedence in a mathematical expression.
a. [Brackets]
b. (Parentheses)
c. {Braces}
d. The escape character \
e. None of these

 

11. In the following C++ 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. 7 – 10
e. 10 / 2

 

12. 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 the above

 

13. When a variable is assigned a number that is too large for its data type, it:
a. underflows
b. overflows
c. reverses polarity
d. exceeds expectations
e. None of the above

 

14. This manipulator is used to establish a field width for the value immediately following it.
a. field_width
b. set_field
c. setw
d. iomanip
e. None of the above

 

15. 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

 

16. This statement will pause the screen, until the [Enter] key is pressed.
a. cin;
b. cin.getline();
c. cin.get();
d. cin.ignore();
e. cin.input();

 

17. To use the rand() function, you must #include this header file in your program.
a. iostream
b. iomanip
c. iorand
d. cstdlib
e. None of these

 

18. Assume that x is an int variable. What value is assigned to x after the following assignment statement is executed?

x = -3 + 4 % 6 / 5;

a. 0
b. 1
c. 2
d. –3
e. None of these

 

19. Which statement will read an entire line of input into the following string object?

string address;

a. cin << address;
b. cin address;
c. getline(cin, address);
d. cin.get(address);
e. None of the above

 

20. Associativity is either right to left or
a. Top to bottom
b. Front to back
c. Left to right
d. Undeterminable
e. None of the above

 

21. When converting some algebraic expressions to C++, you may need to insert ___________ that do not appear in the algebraic expression.
a. Parentheses
b. Exponents
c. Calculations
d. Coercions
e. None of the above

 

22. Which is true about the following statement?

cout << setw(4) << num4 << ” “; a. It allows four spaces for the value in the variable num4. b. It outputs “setw(4)” before the value in the variable num4. c. It should use setw(10) to output the value in the variable num10. d. It inputs up to four characters stored in the variable num4. e. None of these ANS: A 23. The total number of digits that appear before and after the decimal point is sometimes referred to as: a. floating points b. significant digits c. precision d. b and c e. None of these ANS: D 24. This stream manipulator forces cout to print the digits in fixed-point notation. a. setprecision(2) b. setw(2) c. fixed d. setfixed(2) e. None of these ANS: C 25. When using the sqrt function you must include this header file. a. cstdlib b. cmath c. cstring d. iostream e. iomanip ANS: B 26. The statement cin >> setw(10) >> str;

will read up to this many characters into str.
a. Nine
b. Ten
c. Eleven
d. Eight
e. None of these

 

27. What will the value of result be after the following statement executes?

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

a. 8 c. 1.5
b. 6 d. 2

 

28. What will the value of x be after the following statements execute?

int x = 0;
int y = 5;
int z = 4;
x = y + z * 2;

a. 13 c. 0
b. 18 d. unknown

 

29. 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 c. 1.5
b. 4.0 d. 6.0

 

30. Which statement is equivalent to the following?

number += 1;

a. number = number + 1; c. number = 1;
b. number + 1; d. None of these

 

31. Which statement is equivalent to the following?

x = x * 2;

a. x * 2; c. x = x * x;
b. x *= 2; d. None of these

 

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

int number = 10;
number += 5;
number -= 2;
number *= 3;

a. 3 c. 15
b. 30 d. 2

 

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

1 #include
2 using namespace std;
3
4 int main()
5 {
6 const int MY_VAL;
7 MY_VAL = 77;
8 cout << MY_VAL << endl;
9 return 0;
10 }

a. 6 c. 9
b. 8 d. 7

 

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

1 #include
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. 6 c. 9 b. 8 d. 7 ANS: D 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. ANS: T 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 statement

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

will output $5.00 to the screen.

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.

About

Leave a reply

Captcha Click on image to update the captcha .

error: Content is protected !!