setprecision (n) : when used in conjunction with fixed, set the number of digits after the decimal point to n. Without fixed, the setprecision (n) will output n significant digits instead. showpoint: when printing a floating-point number, display the decimal point even if the value is exactly equal to a whole number. For setw (), setprecision (), showpoint, see example below: float cost cout << ":" << cost << ":" << endl; cout << fixed << setprecision (2) << showpoint; cout << right << ":" < setw(8) << cost << ":" << endl; cout << ":" << setw(8) << "1234567" << ":" << endl; = 10.0; The output would be as follows: :10: 10.00: : 1234567:
setprecision (n) : when used in conjunction with fixed, set the number of digits after the decimal point to n. Without fixed, the setprecision (n) will output n significant digits instead. showpoint: when printing a floating-point number, display the decimal point even if the value is exactly equal to a whole number. For setw (), setprecision (), showpoint, see example below: float cost cout << ":" << cost << ":" << endl; cout << fixed << setprecision (2) << showpoint; cout << right << ":" < setw(8) << cost << ":" << endl; cout << ":" << setw(8) << "1234567" << ":" << endl; = 10.0; The output would be as follows: :10: 10.00: : 1234567:
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
![setprecision (n) : when used in conjunction with fixed, set the number of digits after
the decimal point to n. Without fixed, the setprecision (n) will output n significant
digits instead.
showpoint: when printing a floating-point number, display the decimal point even if the
value is exactly equal to a whole number.
For setw (), setprecision (), showpoint, see example below:
float cost = 10.0;
cout << ":" << cost << ":" << endl;
cout << fixed << setprecision (2) << showpoint;
cout << right << ":" << setw(8) << cost << ":" << endl;
cout << ":" << setw (8) << "1234567" << ":" << endl;
The output would be as follows:
:10:
10.00:
: 1234567:](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fe815d996-ac78-4584-a71e-4284151c4e48%2F01630c80-938d-43a9-9dda-272147d24d95%2Fbp3679e_processed.jpeg&w=3840&q=75)
Transcribed Image Text:setprecision (n) : when used in conjunction with fixed, set the number of digits after
the decimal point to n. Without fixed, the setprecision (n) will output n significant
digits instead.
showpoint: when printing a floating-point number, display the decimal point even if the
value is exactly equal to a whole number.
For setw (), setprecision (), showpoint, see example below:
float cost = 10.0;
cout << ":" << cost << ":" << endl;
cout << fixed << setprecision (2) << showpoint;
cout << right << ":" << setw(8) << cost << ":" << endl;
cout << ":" << setw (8) << "1234567" << ":" << endl;
The output would be as follows:
:10:
10.00:
: 1234567:
![Page
The text output of a program should be well-formatted for readability as well as displaying
numbers with the proper notation and precision levels. The default output formatting in C++ is
often not desirable, so one can add explicit instructions to the cout stream. These manipulators
and functions are defined in the <iomanip> library.
• setw (n): set the width (number of characters) of the next item to be at least n.
• If the next item width is less than n, then pad the item with extra spaces.
• If the next item width is greater than n, then the entire next item is output.
• left and right: when used in conjunction with setw (); justify the item to one side
forcing the padding to the other side. Note that these manipulators are persistent, i.e. remains
effective until the next change occurs.
• fixed: use the fixed-point notation (the decimal point notation that we are familiar with)
when displaying a numerical item. Note that fixed defaults to 6 decimal points if the data
type is float or double. See the example below:
int i = 123;
float f = 12.3;
float ff = 0.0001234;
double d = 10;
double dd = 20.1234567890;
cout << fixed;
cout << i << endl;
cout << f << endl;
Note the
rounding
// output: 123
// output: 12.300000
// output: 0.000123
// output: 10.000000
// output: 20.123457-
cout << ff < endl;
cout << d << endl;
Note the
cout << dd << endl;
rounding](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fe815d996-ac78-4584-a71e-4284151c4e48%2F01630c80-938d-43a9-9dda-272147d24d95%2Fo43ibqf_processed.jpeg&w=3840&q=75)
Transcribed Image Text:Page
The text output of a program should be well-formatted for readability as well as displaying
numbers with the proper notation and precision levels. The default output formatting in C++ is
often not desirable, so one can add explicit instructions to the cout stream. These manipulators
and functions are defined in the <iomanip> library.
• setw (n): set the width (number of characters) of the next item to be at least n.
• If the next item width is less than n, then pad the item with extra spaces.
• If the next item width is greater than n, then the entire next item is output.
• left and right: when used in conjunction with setw (); justify the item to one side
forcing the padding to the other side. Note that these manipulators are persistent, i.e. remains
effective until the next change occurs.
• fixed: use the fixed-point notation (the decimal point notation that we are familiar with)
when displaying a numerical item. Note that fixed defaults to 6 decimal points if the data
type is float or double. See the example below:
int i = 123;
float f = 12.3;
float ff = 0.0001234;
double d = 10;
double dd = 20.1234567890;
cout << fixed;
cout << i << endl;
cout << f << endl;
Note the
rounding
// output: 123
// output: 12.300000
// output: 0.000123
// output: 10.000000
// output: 20.123457-
cout << ff < endl;
cout << d << endl;
Note the
cout << dd << endl;
rounding
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education