@@ -820,8 +820,14 @@ void Database::PrintQ1(std::array<DBDecimal, 3 * 2>& sum_qty,
820
820
std::cout << " l|l|sum_qty|sum_base_price|sum_disc_price|"
821
821
" sum_charge|avg_qty|avg_price|avg_disc|count_order\n " ;
822
822
823
- // print the results
823
+ // Copy old state of cout
824
+ std::ios oldState (nullptr );
825
+ oldState.copyfmt (std::cout);
826
+
827
+ // Edit the output format of cout
824
828
std::cout << std::fixed << std::setprecision (2 );
829
+
830
+ // print the results
825
831
for (int ls_idx = 0 ; ls_idx < 2 ; ls_idx++) {
826
832
for (int rf_idx = 0 ; rf_idx < 3 ; rf_idx++) {
827
833
int i = ls_idx * 3 + rf_idx;
@@ -833,6 +839,9 @@ void Database::PrintQ1(std::array<DBDecimal, 3 * 2>& sum_qty,
833
839
<< (double )(avg_discount[i]) / 100.0 << " |" << count[i] << " \n " ;
834
840
}
835
841
}
842
+
843
+ // Restore the output format of cout
844
+ std::cout.copyfmt (oldState);
836
845
}
837
846
838
847
//
@@ -878,11 +887,21 @@ void Database::PrintQ9(std::array<DBDecimal, 25 * 2020>& sum_profit) {
878
887
// print the header
879
888
std::cout << " nation|o_year|sum_profit\n " ;
880
889
881
- // print the results
890
+ // Copy old state of cout
891
+ std::ios oldState (nullptr );
892
+ oldState.copyfmt (std::cout);
893
+
894
+ // Edit the output format of cout
882
895
std::cout << std::fixed << std::setprecision (2 );
896
+
897
+ // print the results
883
898
for (int i = 0 ; i < outrows.size (); i++) {
884
899
outrows[i].print ();
885
900
}
901
+
902
+ // Restore the output format of cout
903
+ std::cout.copyfmt (oldState);
904
+
886
905
}
887
906
888
907
//
@@ -893,12 +912,22 @@ void Database::PrintQ11(std::vector<DBIdentifier>& partkeys,
893
912
// print the header
894
913
std::cout << " ps_partkey|value\n " ;
895
914
896
- // print the results
915
+ // Copy old state of cout
916
+ std::ios oldState (nullptr );
917
+ oldState.copyfmt (std::cout);
918
+
919
+ // Edit the output format of cout
897
920
std::cout << std::fixed << std::setprecision (2 );
921
+
922
+ // print the results
898
923
for (int i = 0 ; i < partkeys.size (); i++) {
899
924
std::cout << partkeys[i] << " |" << (double )(partkey_values[i]) / (100.00 )
900
925
<< " \n " ;
901
926
}
927
+
928
+ // Restore the output format of cout
929
+ std::cout.copyfmt (oldState);
930
+
902
931
}
903
932
904
933
//
@@ -910,10 +939,20 @@ void Database::PrintQ12(std::string& SM1, std::string& SM2,
910
939
// print the header
911
940
std::cout << " l_shipmode|high_line_count|low_line_count\n " ;
912
941
913
- // print the results
942
+ // Copy old state of cout
943
+ std::ios oldState (nullptr );
944
+ oldState.copyfmt (std::cout);
945
+
946
+ // Edit the output format of cout
914
947
std::cout << std::fixed;
948
+
949
+ // print the results
915
950
std::cout << SM1 << " |" << high_line_count[0 ] << " |" << low_line_count[0 ]
916
951
<< " \n " ;
917
952
std::cout << SM2 << " |" << high_line_count[1 ] << " |" << low_line_count[1 ]
918
953
<< " \n " ;
954
+
955
+ // Restore the output format of cout
956
+ std::cout.copyfmt (oldState);
957
+
919
958
}
0 commit comments