(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
- ( 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[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_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_forward
- 5. (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_forwardQ3. (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( 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
- (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_forwardQuestion 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_forward
- (3) What is wrong with the foliowing statement? Syatem.out.printin("To be ar not to be, tha: is the question.";arrow_forward(Displaying a Square of Any Character) Modify the function created in Exercise 5.19 toform the square out of whatever character is contained in character parameter fillCharacter. Thusif side is 5 and fillCharacter is “#”, then this function should print: ##### ##### ##### ##### #####arrow_forwardQ3. (Dice Rolling) Write a program that simulates the rolling of two dice. The program should use rand to roll the first die and should use rand again to roll the second die. The sum of the two values should then be calculated. [Note: Each die can show an integer value from 1 to 6, so the sum of the two values will vary from 2 to 12, with 7 being the most frequent sum and 2 and 12 being the least frequent sums.] Figure 7.26 shows the 36 possible combinations of the two dice. Your program should roll the two dice 10,000 times. Use a one-dimensional array to tally the numbers of times each possible sum appears. Print the results in a tabular format. Also, determine if the totals are reasonable (i.e., there are six ways to roll a 7, so approximately one-sixth of all the rolls should be 7). 1 2 3 4 5 1 2 4 6 7 3 4 6 7 3 4 5 7 8 9 4 7 8 9 10 7 8 10 11 7 10 11 12 Row\Col 3.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education