{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

setw - cout<< setw(20<< temp c...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
//Example: setw #include <iostream> #include <iomanip> #include < string> using namespace std; int main() { int x = 19, a = 345, N=12; i double y = 76.384, z = 0.0000007658; d string temp = "hello"; s cout << endl << "Default format \n" ; cout<<a<<'\n'<<"Hi"<<" \n"<<x<<y<< '\n'<<temp <<'\n'<<z<<'\n'<<endl; c cout<<fixed<<showpoint; cout <<endl <<"fixed format for z = "<<z << endl; cout<<setprecision(2); c cout <<"setprecision(2), fixed<<showpoint Left" << endl<<endl ; cout<<"12345678901234567890"<<endl; c cout << left ; cout<<setw(5)<<x<<endl; c cout<<setw(2)<< z <<endl ; cout<<setw(5)<<a<<setw(5)<<"Hi"<<setw(5)<<x<<setw(5)<< z <<endl<<endl; c cout << setw(20) << temp ; cout << "\n Right " << endl ; c cout <<"setprecision(3), fixed<<showpoint Right" << endl<<endl ; cout << right ; cout<<setprecision(3); c cout<<setw(6)<<a<<setw(6)<<y <<setw(6)<<x<<setw(6)<< z<<endl; c cout<<setw(6)<<x<<setw(6)<<a<<setw(6)<<y<<setw(6)<< z<<endl<<endl;
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: cout << setw(20) << temp ; c cout<<setw(5)<<a<<x<<endl; c cout<<setw(2)<<a<<setw(4)<<x<<setw(5)<< z<<endl; c cout<<fixed<<showpoint<<setprecision(7); c cout<<setw(2)<< z <<endl<<left ; cout << setw(N) << "x is : "<< right <<setw(N-2) <<x <<endl ; cout << left << setw(N) << "z = : "<< right << setw(N-2)<< z <<endl ; cout << setw(N) << "Y : "<< setw(N-2)<< y <<endl ; cout << setw(N) << "A as int: "<< setw(N-2)<< a <<endl ; c return 0; } /*output / Default format 345 Hi 1976.384 hello 7.658e-007 7 fixed format for z = 0.000001 setprecision(2), fixed<<showpoint Left s 12345678901234567890 19 0.00 345 Hi 19 0.00 3 hello Right setprecision(3), fixed<<showpoint Right s 34576.384 19 0.000 19 34576.384 0.000 hello 34519 345 190.000 0.0000008 x is : 19 z = : 0.0000008 Y : 76.3840000 A as int: 345 */...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern