#include #include #include using namespace std; // formatting using manipulators int main() { const double CENTIPI = 100 * acos(-1); // arccos(-1) = PI const int MAX = 10; const int TAB = 15; int k; cout << "default setting " << CENTIPI << ", with setprecision(4), " << setprecision(4) << CENTIPI << endl; cout << "\nfixed floating-point, precision varies, fixed/scientific\n" << endl; for(k=0; k < MAX; k++) { cout << left << "pre. " << k << "\t" << setprecision(k) << setw(TAB) << fixed << CENTIPI << scientific << "\t" << CENTIPI << endl; } cout << endl << "width and justification vary, fixed, precision 2\n" << endl; cout << setprecision(2) << fixed; for(k=3; k < MAX+3; k++) { cout << "wid. " << k << "\t+" << left << setw(k) << CENTIPI << right << "+\t\t-" << setw(k) << CENTIPI << "-" << endl; } cout << endl << "repeated, fill char = @\n" << endl; cout << setfill('@'); for(k=3; k < MAX+3; k++) { cout << "wid. " << k << "\t+" << left << setw(k) << CENTIPI << right << "+\t\t-" << setw(k) << CENTIPI << "-" << endl; } return 0; }