< previous page page_113 next page >

Page 113
Header FileManipulatorParameter TypeEffect
<iostream.h>endlNoneTerminates the current output line
<iomanip.h>setw(n)intSets fieldwidt to n*
<iomanip.h>setprecision(n)intSets floating point precision to n digits
*setw is only for numbers and strings, not char data. Also, setw applies only to the very next output item, after which the fieldwidth is reset to 0 (meaning use only as many columns as are needed).

MATTERS OF STYLE
Program Formatting
As far as the compiler is concerned, C++ statements are free format: They can appear anywhere on a line, more than one can appear on a single line, and one statement can span several lines. The compiler only needs blanks (or comments or new lines) to separate important symbols, and it needs semicolons to terminate statements. However, it is extremely important that your programs be readable, both for your sake and for the sake of anyone else who has to use them.
When you write an outline for an English paper, you follow certain rules of indentation to make it readable. These same kinds of rules can make your programs easier to read.
Take a look at the following program for computing the cost per square foot of a house. Although it compiles and runs correctly, it does not conform to any formatting standards.
// HouseCost program
// This program computes the cost per square foot of
   // living space for a house, given the dimensions of
// the house, the number of stories, the size of the
// nonliving space, and the total cost less land
#include <iostream.h>
#include <iomanip.h>// For setw() and setprecision()
const float WIDTH = 30.0; // Width of the house
    const float LENGTH = 40.0; // Length of the house
const float STORIES = 2.5; // Number of full stories
const float NON_LIVING_SPACE = 825.0;// Garage, closets, etc.

 
< previous page page_113 next page >