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
(Rounding Numbers) Function floor can be used to round a number to a specific decimal place. The statementy = floor(x * 10 + 0.5) / 10;rounds x to the tenths position (the first position to the right of the decimal point). The statementy                                        = floor(x * 100 + 0.5) / 100;rounds x to the hundredths position (the second position to the right of the decimal point). Write a program that defines fourfunctions to round a number x in various ways:A. roundToInteger(number)B. roundToTenths(number)C. roundToHundredths(number)D. roundToThousandths(number)For each value read, your program should print the original value, the number rounded to the nearest integer, the number rounded to the nearest tenth, the number rounded to the nearest hundredth and the number rounded to the nearest thousandth.
(b) Which of the following statements are true? In each case you should justify your argument informally. X + X * 2 i. {x > Y} {x - Y > 0} Y +Y div 2 ii. {x is even} X + x+1 X + 2 * X {x is odd} X + 2 * Y iii. {x = Y} {x = Y} Y + 2 * X
[SHORT ANSWER] Write three separate if blocks and using appropriate logical operator (and, or, not) to check the following three separate conditions (number your answers):1. If the character variable lastAlphabet is Z or z, print the message: Last Alphabet!2. If the variable daysOfWeek is outside the range O through 8 (including both those days), print the message: Invalid Day!3. If the variable monthsOfYear is inside the range 1 through 12 (including both those months), print the message: Valid Month!

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
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