#include #include using namespace std; void Func1(); void Func2(); void PrintBalances(const double* list, const int size); const int SIZE = 5; int main() { cout << right << fixed << setprecision(2); double balances[SIZE] = { 23.45, 134.56, 987.3546, 33.0, 15483.977 }; PrintBalances(balances, SIZE); // Func1(); Func2(); PrintBalances(balances, SIZE); } void Func1() // does some formatting changes, does NOT reset stream flags { cout << left << scientific << setprecision(3); double x = 12345.6789, y = 9874586.3456; cout << setw(20) << x << setw(20) << y << "***\n\n"; cout << setw(15) << x << setw(15) << y << "***\n\n"; cout << setfill('-'); cout << setw(20) << x << setw(20) << y << "***\n\n"; cout << setw(15) << x << setw(15) << y << "***\n\n"; } void Func2() // same function, does formatting changes, but resets stream flags to // prior state { // capture current settings ios_base::fmtflags fstate = cout.flags(); char oldfill = cout.fill(); int oldprecision = cout.precision(); // make changes and do OUR output for this function cout << left << scientific << setprecision(3); double x = 12345.6789, y = 9874586.3456; cout << setw(20) << x << setw(20) << y << "***\n\n"; cout << setw(15) << x << setw(15) << y << "***\n\n"; cout << setfill('-'); cout << setw(20) << x << setw(20) << y << "***\n\n"; cout << setw(15) << x << setw(15) << y << "***\n\n"; // RESTORE settings to what they were when this function started cout.flags(fstate); cout.fill(oldfill); cout.precision(oldprecision); } void PrintBalances(const double* list, const int size) { cout << '\n'; for (int i = 0; i < size; i++) { cout << "Account " << i+1 << " balance = $ "; cout << setw(20) << list[i] << '\n'; } cout << '\n'; }