Prompts the user for 4 one-word items and their corresponding prices in US dollars • Compute the total price and displays a well-formatted receipt using manipulators. Task 1 Sample Output: Enter names of 4 one-word (maximum 10 letters) items to purchase: Yogurt Apple Butter Bread Enter their prices in US Dollars (<= $1,000): 0.75 8.00 12.99 2.85 +- --+---- ----+ Receipt +--- |Yogurt | Apple | Butter |Bread ---+ 0.751 8.001 12.99 2.851 +---- | TOTAL: $ 24.591 +---- -----+

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Prompts the user for 4 one-word items and their corresponding prices in US dollars
Compute the total price and displays a well-formatted receipt using manipulators.
Task 1 Sample Output:
Enter names of 4 one-word (maximum. 10 letters) items to purchase:
Yogurt Apple Butter Bread
Enter their prices in US Dollars (<= $1,000) :
0.75
8.00
12.99
2.85
Receipt
|Yogurt
|Apple
| Butter
|Bread
%41
0.75]
8.001
12.991
%24
2.85
| TOTAL: $
24.59|
Transcribed Image Text:Prompts the user for 4 one-word items and their corresponding prices in US dollars Compute the total price and displays a well-formatted receipt using manipulators. Task 1 Sample Output: Enter names of 4 one-word (maximum. 10 letters) items to purchase: Yogurt Apple Butter Bread Enter their prices in US Dollars (<= $1,000) : 0.75 8.00 12.99 2.85 Receipt |Yogurt |Apple | Butter |Bread %41 0.75] 8.001 12.991 %24 2.85 | TOTAL: $ 24.59|
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;
cout << ff << endl;
cout << d << endl;
cout << dd << endl;
Note the
// output: 123
// output: 12.300000
// output:0.000123
// output: 10.000000
// output: 20.123457-
rounding
Note the
rounding
• setp
ecision (n) : when used in conjunction with
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: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; cout << ff << endl; cout << d << endl; cout << dd << endl; Note the // output: 123 // output: 12.300000 // output:0.000123 // output: 10.000000 // output: 20.123457- rounding Note the rounding • setp ecision (n) : when used in conjunction with 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:
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY