0% found this document useful (0 votes)
8 views8 pages

Quiz 3 (Chapter 3)

The document contains a quiz with multiple-choice questions focused on C++ programming concepts, including input/output operations, data types, operators, and manipulators. Each question requires the selection of a single correct answer from provided options. The quiz is designed to assess knowledge of fundamental programming principles in C++.

Uploaded by

datbuckdough05
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views8 pages

Quiz 3 (Chapter 3)

The document contains a quiz with multiple-choice questions focused on C++ programming concepts, including input/output operations, data types, operators, and manipulators. Each question requires the selection of a single correct answer from provided options. The quiz is designed to assess knowledge of fundamental programming principles in C++.

Uploaded by

datbuckdough05
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Quiz 3 (Chapter 3)

MULTIPLE CHOICE (select single option for given questions below)

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.
a. True b. False

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.
a. True b. False

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

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.
a. True b. False

5. Arithmetic operators that share the same precedence have right to left associativity.
a. True b. False

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

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

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


cout << setprecision(5) << dollars << endl;
a. True b. False

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

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


a. True b. False
11. 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

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

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

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

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

16. 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
17. 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

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

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

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

21. 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
22. 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

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

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

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

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

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

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

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

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

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

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

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

34. 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).

35. 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();

36. 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);

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

38. __________ 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

39. 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);

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

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


a. cstdlib
b. cstring
c. iostream
d. cmath
e. iomanip

42. To use the rand()function, you must include the __________ header file?
a. cstdlib
b. cstring
c. iostream
d. cmath
e. iomanip

43. 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)

44. 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
45. 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

You might also like