Formatting Output O Escape Sequences O iomanip h
- Slides: 24
Formatting Output O Escape Sequences O iomanip. h Objects P setw() P setiosflags(…) P setprecision()
Output ¾ cout The object cout is used to direct data to the ststandard output device, usually the monitor. w predefined stream object w in iostream library w used with insertion operator << *
Output ¾ cout Syntax: cout << Expr. Or. String; Read << as “put to”. cout << 24; cout << ‘y’; cout << “Hello”; *
Output ¾ cout Syntax: cout << Expr. Or. String; cout << << “The answer to question “; qu_num; “ is “; 1. 5 * pay_rate; *
Output ¾ cout Syntax: cout << Expr. Or. String; Each appends data to the stream. cout << “Num 1 * num 2 is “ << num 1*num 2; OUTPUT Num 1 * num 2 is 110 space **
Output ¾ cout Syntax: cout << Expr. Or. String; Each appends data to the stream. cout << “Num =“ << 35. 1; OUTPUT Num =35. 1 no space **
Output ¾ cout Syntax: cout << Expr. Or. String; Each appends data to the stream. cout << “Hi, “ << name << “how are you? ”; space no space OUTPUT Hi, Shadowhow are you? ***
Output ¾ cout Syntax: cout << Expr. Or. String; cout << << “The answer to question “; qu_num; “ is “; 1. 5 * pay_rate; no ; cout << “The answer to question “ << qu_num << “ is “<< 1. 5 * pay_rate; **
Output ¾ cout Syntax: cout << Expr. Or. String ; cout << “The answer to question number 17 is listed after question “; cout << lastqu << ‘. ’; no ; cout << “The answer to question number 17 “ << “is listed after question “ << lastqu << ‘. ’; **
Escape Sequences Changes the meaning of the character that follows it. n hard return t tab \ ” “ a beep or bell These must be within quotation marks.
Escape Sequences cout << “Namet. Totalt. Graden”; cout << “Miyot 186t Bn”; cout << “n Jaket 211t An”; cout << “Sydt 203t An”; OUTPUT Name Miyo n n gives a blank line Jake Syd _ Total 186 211 203 Grade B A A *
Escape Sequences Changes the meaning of the character that follows it. ” take quotes literally “Alfonsus ”Butch” Billone” gives Alfonsus ”Butch” Billone *
Escape Sequences “n Alfonsusn”Butch” n. Billone” gives Alfonsus “Butch” Billone “|n Alfonsusn t ”Butch” t. Billone|” gives | Alfonsus “Butch” Billone| ****
Formatting Output endl ] ] does the same thing as n - inserts a hard return requires the insertion operator cout << endl; is the same as: cout << “nn”;
Formatting Output iomanip. h contains the objects which have special effects on the iostream. #include <iostream. h> #include <iomanip. h> *
Formatting Output iomanip. h contains the objects which have special effects on the iostream. …… …. . . setw(n) how many columns for data setprecision(n) sets number of decimals setiosflags(ios: : fixed) displays 6 digits after the decimal ***
Formatting Output setw(n) how many columns for data cout << setw(4) << ans cout << setw(1) << ans << setw(5) << num << setw(3) << num << setw(4) << “Hi”; << setw(3) << “Hi”; ¨o 33¨ 7132¨o. Hi 337132¨Hi fields expand **
Formatting Output setprecision(n) sets number of decimals x= format result 314. 0 setw(10) setprecision(2) ¨ooo 314. 00 314. 0 point counts setw(10) setprecision(5) ¨ 314. 00000 setw(7) setprecision(5) 314. 00000 columns added ***
Formatting Output setiosflags(ios: : fixed) displays 6 digits after the decimal #include<iostream. h> #include<iomanip. h> void main() { double v = 0. 00123456789; double w = 1. 23456789; double x = 12. 3456789; double y = 1234. 56789; double z = 12345. 6789;
Formatting Output cout <<v<< endl<<w<< endl <<x<< endl <<y<< endl <<z<<”nn”; cout << setiosflags(ios: : fixed); cout <<v<< endl <<w<< endl <<x<< endl <<y<< endl <<z<<”nn”; cout << setprecision(2); cout <<v<< endl <<w<< endl <<x<< endl <<y<< endl <<z<<”nn”; }
Formatting Output default 0. 00123457 12. 3457 12345. 7 ios: : fixed 0. 001235 1. 234568 12. 345679 1234. 567890 12345. 678900 + setprecision(2) 0. 00 1. 23 12. 35 1234. 57 12345. 68
Formatting Output For decimal alignment use: ios: : fixed and setprecision( ) setw( ) sitcky only once cout << setiosflags(ios: : fixed) << setprecision(n); l l l cout << “- -” << setw(n) << var 1 << setw(n) << “- -”; cout << “- -t” << setw(n) << var 1 << setw(n) <<var 2; *
cout Syntax cout << Expr. Or. String. Or. Manipulator. . . ;
Good luck is nothing but prepardness and opportunity coming together.
- Escape sequence in c
- Paragraph formatting
- Standard toolbar in ms word 2013
- Punctuation marks quotes
- Weather in excel
- A named group of formatting characteristics
- Microsoft excel conditional formatting
- Arrow font
- Pascal writeln formatting
- Data organization and formatting of magnetic disk
- Text box formatting
- Modified block letter style example
- Formatting in digital communication
- Font name
- Formatting objects processor
- Paragraph form
- Text box formatting
- Apa format for title page
- Gambar toolbar formatting
- Paragraph formatting
- Formatting objects processor
- Sqlplus report formatting
- Pascal writeln format
- What is internal dialogue in writing
- Pascal programming examples