(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
- [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!arrow_forwardDon'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_forward
- (C PROGRAMMING ONLY) 3. From Person to Peopleby CodeChum Admin Now that we have created a Person, it's time to create more Person and this tech universe shall be filled with people! Instructions: In the code editor, you are provided with the definition of a struct Person. This struct needs an integer value for its age and character value for its gender. Furthermore, you are provided with a displayPerson() function which accepts a struct Person as its parameter. In the main() function, there's a pre-created array of 5 Persons.Your task is to ask the user for the values of the age and gender of these Persons.Then, once you've set their ages and genders, call the displayPerson() function and pass them one by one.Input 1. A series of ages and genders of the 5 Persons Output Person #1Enter Person's age: 24Enter Person's gender: M Person #2Enter Person's·age: 21Enter Person's gender: F Person #3Enter Person's age: 22Enter Person's gender: F Person #4Enter Person's age: 60Enter…arrow_forward2. (Functions with C string parameters) Write a program in C that uses the function, MakeSentenceExcited() to replace any period (full stop or comma) with an exclamation point. If the input string is: I told my computer I needed a break. It replied "I am sorry, I'm not programmed for that function." The output will be: I told my computer I needed a break! It replied "I am sorry! I'm not programmed for that function!" Assign a string size of 200 or above. Use "fgets()" to take the string input. Don't forget to include the string header file. Hint: A very similar example 3 problem is given in the lab slide. Try to follow that example.arrow_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(Q1)This is a Data Structures problem and the programming language used is Lisp. Solve the question we detailed steps and make it concise and easy to understand. Please and thank you.arrow_forward(Intro to Java) 4. Pls help Thanksarrow_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_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning