What is the output of the following code: #include <fstream> #include <iomanip>
ID: 3537327 • Letter: W
Question
What is the output of the following code: #include <fstream> #include <iomanip> #include <string> using namespace std; int main() { string name_str = "John Paul Jones"; double height = 175.21345; double income = 1793.3421; cout << "12345678901234567890123456789012345678901234567890 " << fixed << showpoint << left << setfill('.') << setw(30) << name_str << setprecision(1) << setfill(' ') << setw(10) << height << '$' << right << setprecision(2) << setw(8) << income << endl; return 0; }
Explanation / Answer
12345678901234567890123456789012345678901234567890
John Paul Jones...............175.2 $ 1793.34
clearly,first line will be printed.
fixed:write floating-point values in fixed-point notation
showpoint:When the showpoint format flag is set, the decimal point is always written for floating point values inserted into the stream (even for those whose decimal part is zero).
left:the output is padded to the field width appending fill charecters at the end... 1
setfill(.):Sets . as the stream's fill charecters...... 2
setw :Sets the field width to be used on output operations..... 3
from 1 2 n 3...in 2nd line ,in first 30 charecters at first name_str will be printed n then (.) ,after that height will be printed...
then in next 10 charecter will be height with one digit after decimal n spaces as setprecision(1) .
nd next 8 char will be income with 2 digits after decimaland a $ sign in the begining
so clearly we can get the output.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.