
Exercise four – formats and files February 21, 2006
1
Exercise IV
Exercise IV –
–Formats and File
Formats and File
Input and Output
Input and Output
Larry Caretto
Computer Science 106
Computing in Engineering
and Science
February 21, 2006
2
Outline
• Review exercise three
• Exercise four goals
• Summarize lecture material on formats
and file input and output
• Outline tasks for exercise four
• Review for quiz in laboratory on
Thursday covering exercises 1-3 (pp 1-
106 of text; homework to February 21)
3
Review Exercise Three
• Saw various ways in which type
conversion occurs and use of mod (%)
operator
• Learned how to translate mathematical
equations into C++ statements
• Wrote programs using mathematical
functions atan and sqrt
• Used symbolic constants
4
More on Exercise Three
• Use meaningful variable names
– R, r, or radius, but not x
– pi, or PI but not y (p?)
zy
xw
a−
=y
xw
x
z
b2
−
=
wy
x
zy
x
w
c
+
−
=
a = ( w + x ) / ( y – z )
b = z / x * ( w – x ) / ( 2 * y )
c = ( w – x / y ) / ( z / x + w * y )
5
Exercise Four Goals
• As a result of this exercise you should
be able to accomplish the following:
– write output commands using format
manipulators fixed, scientific,
setw(w), and setprecision(p) to print
an aligned table
– write statements to get input from and write
data to files
– write statements that combine file input
and output with formatting
6
Formatting Output
• Default output
– up to six significant figures
– fixed or scientific determined automatically
• Format requires #include <iomanip>
• Have manipulators in output commands
– fixed/scientific set appearance
– setprecision(p) for number of digits
– setw(w) for width of output