COSC 1315
Programming Fundamentals
Practice Text #106
Revised: February 3, 2007
By Richard G. Baldwin
File Pfsg00106.htm
Practice Text Index
Welcome
The practice tests in this series were written specifically for the benefit
of my students in COSC 1315, Fundamentals of Programming. They
consists of questions, answers, and explanations. The questions are
based on the material covered in my series of online lecture notes for the
course. Each practice test is keyed to a specific lecture. This
practice test is keyed to lecture #106 titled Formatted
Output.
Questions
106-1. The file named iomanip must be included in
order to support which of the following capabilities:
-
A. Floating-point arithmetic.
-
B. Certain types of input/output formatting.
-
C. The ability to read and write data files.
-
D. None of the above.
Answer and Explanation
106-2. True or False. C++ manipulators make it
possible to manipulate the format of
data in a variety of ways.
Answer and Explanation
106-3. True or False. Manipulators are not only used
in C++, they are also used in Java and C#.
Answer and Explanation
106-4. True or False. The contents of the include file named
iomanip
are required in order to use the following manipulators:
- setprecision: Sets the number of digits to be printed to the
right of the decimal point.
- fixed: Used fixed point notation for floating-point
numbers (as opposed to scientific notation). If no precision has
already been specified, the use of this manipulator will set the precision
to 6 by default.
- showpoint: Causes the decimal point to be printed even if
the precision is set to zero and the values printed are whole numbers.
- setw: Sets minimum field (column) width on output.
This sets the minimum size of the field. A larger number will use more
columns.
- endl: Writes a newline ('\n') and flushes the buffer.
Answer and Explanation
106-5. True or False. The statement in Listing 106-5 uses manipulators to prepare the system to:
- Print floating-point data with three digits to the right of the decimal
point.
- Use fixed instead of scientific display format for
floating-point values.
- Show the decimal point.
Listing 106-5.
cout << setprecision(2) << fixed << showpoint;
|
Answer and Explanation
106-6. True or False. The code in Listing 106-6 prints:
- The text contained within the quotation marks, followed by
- The result of dividing 10.0 by 3.0. This value is printed as floating-point data with
two digits to the right of the decimal point, using fixed instead of
scientific display format for
floating-point values.
Listing 106-6.
cout << setprecision(2) << fixed << showpoint;
cout << "10 divided by 3 is: " << 10.0/3.0;
|
Answer and Explanation
106-7. True or False. The code in Listing 106-7 prints:
10 divided by 3 is: 3.333
Listing 106-7.
cout << setprecision(2) << fixed << showpoint;
cout << "10 divided by 3 is: " << 10.0/3.0;
|
Answer and Explanation
106-8. True or False. The code in Listing 106-8
produces the screen output shown below where I manually replaced space
characters with '-' characters so that you can see them and count them.
-------1.5-------2.200
Listing 106-8.
cout
<< setw(10) << setprecision(1) << fixed << 1.5;
cout
<< setw(12) << setprecision(3) << fixed << 2.2
<< endl;
|
Answer and Explanation
106-9. True or False. The code in Listing 106-9
produces the screen output shown below where I manually replaced space
characters with '-' characters so that you can see them and count them.
------12.8-----3.14159
Listing 106-9.
cout
<< setw(10)
<< setprecision(1) << fixed << 12.78;
cout
<< setw(12)
<< setprecision(3) << fixed << 3.14159
<< endl;
|
Answer and Explanation
106-10. True or False. All of the capabilities
supported by the include file named iomanip are shown in the following
list.
- setprecision: Sets the number of digits to be printed to the
right of the decimal point.
- fixed: Used fixed point notation for floating-point
numbers (as opposed to scientific notation). If no precision has
already been specified, the use of this manipulator will set the precision
to 6 by default.
- showpoint: Causes the decimal point to be printed even if
the precision is set to zero and the values printed are whole numbers.
- setw: Sets minimum field (column) width on output.
This sets the minimum size of the field. A larger number will use more
columns.
- endl: Writes a newline ('\n') and flushes the buffer.
Answer and Explanation
Copyright 2007, Richard G. Baldwin. Reproduction in whole or
in part in any form or medium without express written permission from Richard
Baldwin is prohibited.
About the author
Richard Baldwin
is a college professor (at Austin Community College in Austin, TX) and private consultant whose primary focus is a
combination of Java and XML. In addition to the many platform-independent
benefits of Java applications, he believes that a combination of Java and
XML will become the primary driving force in the delivery of structured
information on the Web.
Richard has participated in numerous consulting projects involving
Java, XML, or a combination of the two. He frequently provides onsite
Java and/or XML training at the high-tech companies located in and around
Austin, Texas. He is the author of Baldwin's Java Programming Tutorials,
which has gained a worldwide following among experienced and aspiring Java
programmers. He has also published articles on Java Programming in Java
Pro magazine.
Richard holds an MSEE degree from Southern Methodist University and
has many years of experience in the application of computer technology
to real-world problems.
Baldwin@DickBaldwin.com
Answers and Explanations
Answer 10
FalseBack to Question 10
Explanation 10
Answer 9
FalseBack to Question 9
Explanation 9
Too many digits to the right of the decimal point in the value in the second
column.
Answer 8
True
Back to Question 8
Explanation 8
Answer 7
FalseBack to Question 7
Explanation 7
Too many digits to the right of the decimal pointl.
Answer 6
True
Back to Question 6
Explanation 6
Answer 5
FalseBack to Question 5
Explanation 5
Should be two digits to the right of the decimal point.
Answer 4
True
Back to Question 4
Explanation 4
Answer 3
FalseBack to Question 3
Explanation 3
Answer 2
True
Back to Question 2
Explanation 2
Answer 1
B. Certain types of input/output formatting.Back to Question 1
Explanation 1
Copyright 2007, Richard G. Baldwin. Reproduction in whole or
in part in any form or medium without express written permission from Richard
Baldwin is prohibited.
About the author
Richard Baldwin
is a college professor (at Austin Community College in Austin, TX) and private consultant whose primary focus is a
combination of Java and XML. In addition to the many platform-independent
benefits of Java applications, he believes that a combination of Java and
XML will become the primary driving force in the delivery of structured
information on the Web.
Richard has participated in numerous consulting projects involving
Java, XML, or a combination of the two. He frequently provides onsite
Java and/or XML training at the high-tech companies located in and around
Austin, Texas. He is the author of Baldwin's Java Programming Tutorials,
which has gained a worldwide following among experienced and aspiring Java
programmers. He has also published articles on Java Programming in Java
Pro magazine.
Richard holds an MSEE degree from Southern Methodist University and
has many years of experience in the application of computer technology
to real-world problems.
Baldwin@DickBaldwin.com
-end-