(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
- Don't use ai to answer I will report your answer. . Solve it Asap with explanation properlyarrow_forward( 66 & O ıre O O p A:0Y o Lab 2_070221... → University of Babylon College of Engineering Environment Eng. Dept. Subject: Computer Programming by: Dr. Rawaa Al-Isawi Stage: First Example 1: Write a program to read student name and 6 degree then compute and print the average of student degree. Solution (for one student) Solution (for two student) Example 2: Write a program in QBASIC language to find the following mathematical expressions: 1- D-log(x)-log(x 3- D=logb-sinx+drarrow_forward5. (Algebra: solve 2 X 2 linear equations) You can use Cramer's rule to solve the following 2 X 2 system of linear equation: ax + by = e cx + dy = f ● x = ed - bf bc ad y = af - ec ad bc - Write a program that prompts the user to enter a, b, c, d, e, and f and display the result. If ad- bc is 0, report that The equation has no solution. Enter a, b, c, d, e, f: 9.0, 4.0, 3.0, -5.0, -6.0, -21.0 Enter x is -2.0 and y is 3.0 Enter a, b, c, d, e, f: 1.0, 2.0, 2.0, 4.0, 4.0, 5.0 Enter The equation has no solutionarrow_forward
- Q3. (Python programming) Develop a user defined iterator for prime numbers using class. The prime numbers should be less than 100 and greater than 40arrow_forward) (6.arrow_forward( C PROGRAMMING ONLY) 2. Solving a Person's Lonelinessby CodeChum Admin It's been 1,245 years and our sole Person is getting lonelier each day. This Person definitely needs a partner! Thus, we need to update our Person's design to have a gender as well and there shall be male and female! Instructions: In the code editor, you are provided with the definition of a struct Person. This struct needs an integer value for its age. Furthermore, you are provided with a displayPerson() function which accepts a struct Person as its parameter.Your task is to first update the struct Person so that it can have a gender as well. For this program, we shall represent a gender with a single character: 'M' for male and 'F' for female.Then, create a Person, take in an integer user input and a character user input, and then set them as the Person's age and gender respectively.Finally, call the displayPerson() function and pass that Person you created.Input 1. The age of the Person 2. The gender of…arrow_forward
- (I use mindtap on cengage, if that not possible, please use devc++ 5.11) Instructions Assume the definition of Exercise 2, which defines the struct computerType. Write a program that declares a variable of type computerType, prompts the user to input data about a computer, and outputs the computer’s data. Example input and output is shown below: Enter the name of the manufacturer: McPC Enter the model of the computer: 1000 Enter processor type: Intel GFX Enter the size of RAM (in GB): 8 Enter the size of hard drive (in GB): 1000 Enter the year the computer was built: 2016 Enter the price: 1200 Manufacturer: McPC Model: 1000 Processor:…arrow_forward(Use Python) The function course_average should calculate and return the average of the three values pass to it. The function main should ask the user to enter three grades and then pass these values to the course_average function. This function should also display a message to the user in the format below. For example, if the user entered 100, 90 and 95 the message would be:The average of 100 , 90 and 95 is 95arrow_forwardFor each of the following statements, state whether it is True or False.arrow_forward
- Question 1 (5% - 3 minutes) Assume that a Person is defined as shown here and that two variables are defined as follows: Person a, b; typedef struct p { char *name; unsigned char age: height: *friend; double struct p }Person; Complete the whole test based on this Person struct and variables a and b.arrow_forward(Using C++ language, and generate program) Design and write a program that plays Snakes and Ladders The game need not be interactive Try to write a data driven solution rather than a code driven solution. In a data driven program much of the program's logic exists in data strucutures How do you play Snakes and Ladders? Each player puts their counter on the space that says 'start here'. Decide who goest first Take your turns to roll the dice. Move your counter forward the number of spaces shown on the dice. If your counter lands at the bottom of a ladder, you can move up to the top of the ladder. If your counter lands on the head of a snake, you must slide down to the bottom of the snake. The first player to get to the space that says 'home' is the winner. You land exactly on the last square to win. Take an extra turn if you roll a six How will you represent the players? How will you represent the player's counters? How will you represent the board? How will you represent the foot of…arrow_forwardPlease help! (Java) The objective is to write a program that reads CSV data and emits HTML data. Theprogram should accept input line-by-line in CSV format and produceoutput line-by-line in HTML format. You may use Scanners but should not need any otherimports. Note that regular expressions are forbidden.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr