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
icon
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:
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
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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Program on Numbers
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.
Similar questions
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education