title: C++ Walkthrough cout.setf(ios::fixed); and cout.precision();
body: <pre><code>/* Problem 38 */
          #include &lt;iostream&gt;
          using namespace std;
          class abc {
          double n;
            public:
          abc() { n = 67.5; cout &lt;&lt; "1\n"; }
          abc(double num) { set(num); cout &lt;&lt; "2\n"; }
          double get() const { cout&lt;&lt;"3\n"; return n; }
          virtual void set(double num) {
              if (num &lt; 10)
              n = 10;
              else if (num &gt; 100)
              n = 100;
              else
              n = num;
              cout &lt;&lt; "4\n";
          }
          };
          class def: public abc {
          double m;
            public:
          def() { m = 6.2; cout &lt;&lt; "5\n"; }
          def(double num1, double num2): abc(num1) {
              set(num2 - abc::get()); cout &lt;&lt; "6\n"; }
          double get() const {
              cout &lt;&lt; "7\n"; return m + abc::get(); }
          void set(double num) {
              if (num &lt; 10 || 100 &lt; num)
              m = num;
              else
              m = 55;
              cout &lt;&lt; "8\n";
          }
          };
          void do_it(abc &amp;var, double num)
          {   cout &lt;&lt; var.get() &lt;&lt; '\n';
          var.set(num);
          cout &lt;&lt; var.get() &lt;&lt; '\n';
          }
          int main()
          {   abc x(45);
          def y(2, 340);
          cout.setf(ios::fixed);
          cout.precision(3);
          do_it(x, 200);
          do_it(y, 253);
          cout &lt;&lt; x.get() &lt;&lt; '\n';
          cout &lt;&lt; y.get() &lt;&lt; '\n';
          return 0;
          }
  </code></pre>
  
  <p>With the above code I just wanted to know what below two lines will really do in the above code</p>
  
  <p><code>cout.setf(ios::fixed);</code>
  <code>cout.precision(3);</code></p>
  
  <p>Please do not just give me answer some explanation would be so appreciated because I'm doing a walkthrough to prepare for my final exam tomorrow.</p>
  
  <p>I searched and some source says it is to set flags but really I don't get what is the concept of it and how it works</p>