C++ for Engineers and Scientists
C++ for Engineers and Scientists
4th Edition
ISBN: 9781133187844
Author: Bronson, Gary J.
Publisher: Course Technology Ptr
bartleby

Videos

Question
Book Icon
Chapter 3.2, Problem 6E

(a)

Program Plan Intro

To determine the output of the give code:

(a)

Expert Solution
Check Mark
Program Description Answer

|5|

Explanation of Solution

Given information:

cout<<"|"<<5<<"|";

Program:

#include <iostream>
usingnamespacestd;
intmain()
{
cout<<"|"<<5<<"|";

Explanation:

The output stream, cout, is used along with the insertion operator (<<), to display values on the standard output.

The bar symbol ‘|’ is used to indicate start and end of the display. It acts like a string as this is placed inside the double codes “”.

Sample output: -

  C++ for Engineers and Scientists, Chapter 3.2, Problem 6E , additional homework tip  1

(b)

Program Plan Intro

To determine and write the display produced by the below statement.

(b)

Expert Solution
Check Mark
Program Description Answer

|5|

Explanation of Solution

Given information:

cout<<"|"<<setw(4)<<5<<"|";

Program:

#include <iostream>
#include <iomanip>
usingnamespacestd;
intmain()
{
cout<<"|"<<setw(4)<<5<<"|";

}

Explanation:

The stream manipulator, setw (4) is used to set the field width to 4 places and theresult is displayed at fourth place using cout output stream. The setw() function is defined in the header file.

The bar symbol, ‘|’ is used to indicate start and end of the display. It acts like a string as this is placed inside the double codes “”.

Sample output: -

  C++ for Engineers and Scientists, Chapter 3.2, Problem 6E , additional homework tip  2

(c)

Program Plan Intro

To determine and write the display produced by the below statement.

(c)

Expert Solution
Check Mark
Program Description Answer

|56829|

Explanation of Solution

Given information:

cout<<"|"<<setw(4)<<56829<<"|";

Program:

#include <iostream>
#include <iomanip>
usingnamespacestd;
intmain()
{
cout<<"|"<<setw(4)<<56829<<"|";

}

Explanation:

The stream manipulator: setw(4) is used to set the field width to 4 places. Since, the number is of 5 digits, the width will automatically adjust to accommodate 5 digits and the result is displayed using cout output stream.

The bar symbol, ' | ' is used to indicate start and end ofthe display.It acts like a string as this is placed inside the double codes “”.

Sample output: -

  C++ for Engineers and Scientists, Chapter 3.2, Problem 6E , additional homework tip  3

(d)

Program Plan Intro

To determine and write the display produced by the below statement.

(d)

Expert Solution
Check Mark
Program Description Answer

| 5.26|

Explanation of Solution

Given information:

cout<<"|"<<setw(5)<<setiosflags(ios::fixed)<<setprecision(2)<<5.26<<"|";

Program:

#include <iostream>
#include <iomanip>
usingnamespacestd;
intmain()
{
cout<<"|"<<setw(5)<<setiosflags(ios::fixed)<<setprecision(2)<<5.26<<"|";

}

Explanation:

The given stream manipulator, setw(5) will set the width to 5 places, as 5 is passed in the parameter. And the given stream manipulator that issetiosflags( ios: : fixed ) , is used for the formatting and the stream manipulator, setprecision (2 ), will set the number to

2 places after the decimal point.

The bar symbol, ' | ' is used to indicate start and end ofthe display.It acts like a string as this is placed inside the double codes “”.

Sample output: -

  C++ for Engineers and Scientists, Chapter 3.2, Problem 6E , additional homework tip  4

(e)

Program Plan Intro

To determine and write the display produced by the below statement.

cout<<"|"<<setw(5)<<setiosflags(ios::fixed)<<setprecision(2)<<5.267<<"|";

(e)

Expert Solution
Check Mark
Program Description Answer

|5.27|

Explanation of Solution

Given information:

cout<<"|"<<setw(5)<<setiosflags(ios::fixed)<<setprecision(2)<<5.267<<"|";

Program:

#include <iostream>
#include <iomanip>
usingnamespacestd;
intmain()
{
cout<<"|"<<setw(5)<<setiosflags(ios::fixed)<<setprecision(2)<<5.267<<"|";

}

Explanation:

The given stream manipulator, setw(5) will set the width to 5 places, as 5 is passed in the parameter. And the given stream manipulator that issetiosflags( ios: : fixed ) , is used for the formatting and the stream manipulator, setprecision (2 ), will set the number to 2 places after the decimal point. As the precision is set to 2, the number 5.267 will be rounded off (67 to 70) and only two digits will be displayed on the screen.

The bar symbol, ' | ' is used to indicate start and end ofthe display.It acts like a string as this is placed inside the double codes “”.

Sample output: -

  C++ for Engineers and Scientists, Chapter 3.2, Problem 6E , additional homework tip  5

(f)

Program Plan Intro

To determine and write the display produced by the below statement.

cout<<"|"<<setw(5)<<setiosflags(ios::fixed)<<setprecision(2)<<53.264<<"|";

(f)

Expert Solution
Check Mark
Program Description Answer

|53.26|

Explanation of Solution

Given information:

cout<<"|"<<setw(5)<<setiosflags(ios::fixed)<<setprecision(2)<<53.264<<"|";

Program:

#include <iostream>
#include <iomanip>
usingnamespacestd;
intmain()
{
cout<<"|"<<setw(5)<<setiosflags(ios::fixed)<<setprecision(2)<<53.264<<"|";

}

Explanation:

The given stream manipulator, setw(5) will set the width to 5 places, as 5 is passed in the parameter. And the given stream manipulator that issetiosflags( ios: : fixed ) , is used for the formatting and the stream manipulator, setprecision (2 ), will set the number to

2 places after the decimal point. Since,the number occupies 6 places; the width will automatically adjust to accommodate 7 places.

The bar symbol, ' | 'is used to indicate start and end ofthe display.It acts like a string as this is placed inside the double codes “”.

Sample output: -

  C++ for Engineers and Scientists, Chapter 3.2, Problem 6E , additional homework tip  6

(g)

Program Plan Intro

To determine and write the display produced by the below statement.

cout<<"|"<<setw(5)<<setiosflags(ios::fixed)<<setprecision(2)<<534.264<<"|";

(g)

Expert Solution
Check Mark
Program Description Answer

|534.26|

Explanation of Solution

Given information:

cout<<"|"<<setw(5)<<setiosflags(ios::fixed)<<setprecision(2)<<534.264<<"|";

Program:

#include <iostream>
#include <iomanip>
usingnamespacestd;
intmain()
{
cout<<"|"<<setw(5)<<setiosflags(ios::fixed)<<setprecision(2)<<534.264<<"|";

}

Explanation:

The given stream manipulator, setw(5) will set the width to 5 places, as 5 is passed in the parameter. And the given stream manipulator that issetiosflags( ios: : fixed ) , is used for the formatting and the stream manipulator, setprecision (2 ), will set the number to

2 places after the decimal point. Since,the number occupies 7 places; the width will automatically adjust to accommodate 7places.

The bar symbol, ' | 'is used to indicate start and end ofthe display.It acts like a string as this is placed inside the double codes “”.

Sample output: -

  C++ for Engineers and Scientists, Chapter 3.2, Problem 6E , additional homework tip  7

(h)

Program Plan Intro

To determine and write the display produced by the below statement.

cout<<"|"<<setw(5)<<setiosflags(ios::fixed)<<setprecision(2)<<534.<<"|";

(h)

Expert Solution
Check Mark
Program Description Answer

|534.00|

Explanation of Solution

Given information:

cout<<"|"<<setw(5)<<setiosflags(ios::fixed)<<setprecision(2)<<534.<<"|";

Program:

#include <iostream>
#include <iomanip>
usingnamespacestd;
intmain()
{
cout<<"|"<<setw(5)<<setiosflags(ios::fixed)<<setprecision(2)<<534.<<"|";

}

Explanation:

The given stream manipulator, setw(5) will set the width to 5 places, as 5 is passed in the parameter.And the givenstream manipulator that issetiosflags( ios: : fixed ) , is used for the formatting and the stream manipulator, setprecision (2 ), will set the number to 2 places after the decimal point.

Therefore, two zeroes are added after the decimal pomt to set the precision to 2 places and the width are auto adjusted to accommodate 6 places.

The bar symbol, ' | ' is used to indicate start and end ofthe display.It acts like a string as this is placed inside the double codes “”.

Sample output: -

  C++ for Engineers and Scientists, Chapter 3.2, Problem 6E , additional homework tip  8

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
This week we will be building a regression model conceptually for our discussion assignment. Consider your current workplace (or previous/future workplace if not currently working) and answer the following set of questions. Expand where needed to help others understand your thinking:  What is the most important factor (variable) that needs to be predicted accurately at work? Why? Justify its selection as your dependent variable.
According to best practices, you should always make a copy of a config file and add a date to filename before editing? Explain why this should be done and what could be the pitfalls of not doing it.
In completing this report, you may be required to rely heavily on principles relevant, for example, the Work System, Managerial and Functional Levels, Information and International Systems, and Security. apply Problem Solving Techniques (Think Outside The Box) when completing. should reflect relevance, clarity, and organisation based on research. Your research must be demonstrated by Details from the scenario to support your analysis, Theories from your readings, Three or more scholarly references are required from books, UWIlinc, etc, in-text or narrated citations of at least four (4) references. “Implementation of an Integrated Inventory Management System at Green Fields Manufacturing” Green Fields Manufacturing is a mid-sized company specialising in eco-friendly home and garden products. In recent years, growing demand has exposed the limitations of their fragmented processes and outdated systems. Different departments manage production schedules, raw material requirements, and…

Chapter 3 Solutions

C++ for Engineers and Scientists

Ch. 3.1 - (Debug) Determine and correct the errors in the...Ch. 3.1 - Prob. 12ECh. 3.1 - Prob. 13ECh. 3.1 - (General math) The area of an ellipse (see Figure...Ch. 3.1 - Prob. 15ECh. 3.2 - Prob. 1ECh. 3.2 - Prob. 2ECh. 3.2 - (Practice) Write a C++ program that displays the...Ch. 3.2 - Prob. 4ECh. 3.2 - Prob. 5ECh. 3.2 - Prob. 6ECh. 3.2 - Prob. 7ECh. 3.2 - Prob. 8ECh. 3.2 - (Electrical eng.) The combined resistance of three...Ch. 3.2 - Prob. 10ECh. 3.2 - Prob. 11ECh. 3.2 - (Civil eng.) Write a C++ program to calculate and...Ch. 3.3 - Prob. 1ECh. 3.3 - Prob. 2ECh. 3.3 - (Practice) Write C++ statements for the following:...Ch. 3.3 - Prob. 4ECh. 3.3 - (General math) Write, compile, and run a C++...Ch. 3.3 - (General math) If a 20-foot ladder is placed on...Ch. 3.3 - (Physics) The maximum height reached by a ball...Ch. 3.3 - (Transportation) Road construction requires...Ch. 3.3 - Prob. 9ECh. 3.3 - Prob. 10ECh. 3.3 - Prob. 11ECh. 3.3 - Prob. 12ECh. 3.4 - Prob. 1ECh. 3.4 - (Practice) a. Write a C++ program that first...Ch. 3.4 - Prob. 3ECh. 3.4 - Prob. 4ECh. 3.4 - Prob. 5ECh. 3.4 - Prob. 6ECh. 3.4 - (General math) a. Write, compile, and run a C++...Ch. 3.4 - Prob. 8ECh. 3.4 - Prob. 9ECh. 3.4 - (Electrical eng.) For the series circuit shown in...Ch. 3.4 - Prob. 11ECh. 3.4 - Prob. 12ECh. 3.4 - Prob. 13ECh. 3.5 - Prob. 1ECh. 3.5 - Prob. 2ECh. 3.5 - Prob. 3ECh. 3.5 - Prob. 4ECh. 3.5 - Prob. 5ECh. 3.6 - Prob. 1ECh. 3.6 - (General math) The value of p can be approximated...Ch. 3.6 - Prob. 3ECh. 3.6 - (General math) The volume of oil stored in an...Ch. 3.6 - Prob. 5ECh. 3.6 - (General math) The perimeter, approximate surface...Ch. 3.6 - Prob. 7ECh. 3.6 - Prob. 8ECh. 3.6 - Prob. 9ECh. 3 - (General math) a. Write a C++ program to calculate...Ch. 3 - General math) a. Write a C++ program to calculate...Ch. 3 - (General math) Modify the program written for...Ch. 3 - (Biology) The number of bacteria, B, in a culture...Ch. 3 - Prob. 5PPCh. 3 - (Heat transfer) The formula developed in Exercise...Ch. 3 - Prob. 7PPCh. 3 - (Electrical eng.) a. The voltage gain of an...Ch. 3 - (Electrical eng.) a. Write, compile, and run a C++...Ch. 3 - (Electrical eng.) The amplification of electronic...Ch. 3 - (Acoustics) The loudness of a sound is measured in...Ch. 3 - (General math) a. A balance has the following...
Knowledge Booster
Background pattern image
Computer Science
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
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Boolean Algebra - Digital Logic and Logic Families - Industrial Electronics; Author: Ekeeda;https://www.youtube.com/watch?v=u7XnJos-_Hs;License: Standard YouTube License, CC-BY
Boolean Algebra 1 – The Laws of Boolean Algebra; Author: Computer Science;https://www.youtube.com/watch?v=EPJf4owqwdA;License: Standard Youtube License