(a)
To determine the output of the give code:
(a)
|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: -
(b)
To determine and write the display produced by the below statement.
(b)
|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
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)
To determine and write the display produced by the below statement.
(c)
|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: -
(d)
To determine and write the display produced by the below statement.
(d)
| 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: -
(e)
To determine and write the display produced by the below statement.
cout<<"|"<<setw(5)<<setiosflags(ios::fixed)<<setprecision(2)<<5.267<<"|";
(e)
|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: -
(f)
To determine and write the display produced by the below statement.
cout<<"|"<<setw(5)<<setiosflags(ios::fixed)<<setprecision(2)<<53.264<<"|";
(f)
|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: -
(g)
To determine and write the display produced by the below statement.
cout<<"|"<<setw(5)<<setiosflags(ios::fixed)<<setprecision(2)<<534.264<<"|";
(g)
|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: -
(h)
To determine and write the display produced by the below statement.
cout<<"|"<<setw(5)<<setiosflags(ios::fixed)<<setprecision(2)<<534.<<"|";
(h)
|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: -
Want to see more full solutions like this?
Chapter 3 Solutions
C++ for Engineers and Scientists
- State whether each of the following is true or false. If false, explain why e) All variables must be given a type when they’re defined.arrow_forwardState whether each of the following is true or false. If false, explain why j) The arithmetic operators *, /, %, + and - all have the same level of precedence.arrow_forwardFill in the blanks to rewrite the following statement: c. If x___________, then ________.arrow_forward
- -Convert SES variable to a factor and assign the value labels “low”, ”middle” and “high” to the 3 levels of thevariable. Then -Define the variables complic, comorb, depressi, diabetes as factors. For all these factors, a zero means “no” and a 1 means “yes”. Assign these value labels through the function factor() and check the change using str()arrow_forwardState whether each statment is true or false. If the answer is false, explain why? "The address operator & can be applied only to constants and to expressions."arrow_forwardWhat’s the output of the following programs?arrow_forward
- State which of the following are true and which are false. If false, explain your answer.d) A valid arithmetic expression containing no parentheses is evaluated from left to right.arrow_forwardCompute the weakest precondition for each of the following statements based on their postconditions. b= 2*a + 3*b – 1; a = 2*b {a >= 2} if ( x==4) x = y /2+3; else x = y / 2; {x > 1}arrow_forwardC++ program chose the correct result for each of the following programming statementsarrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning