Redirecting I/O -- you may have a program read data from either the terminal or a file by using the redirection facilities in unix.
For example, suppose you had a program that read 5 numbers from the terminal (using standard cin statements). You could put the 5 numbers is a file called input (for example). Then, in running the program say:
a.out < input
and the numbers from the file will be read! You may also redirect the output from a program into a file by saying:
a.out > out-file
All output that you generally see on the terminal will go to the file instead!
Reading: D&D pp. 170-208 (Starting Chapter 3)
Exercises: p.165, #2.47, #2.47 (Extra Credit Part for extra credit), #2.49
Problem 2.16 from the book. Drivers are concerned with the mileage obtained by thier automobiles. One driver has kept track of several tankfuls of gasoline by recording miles driven and gallons used for each tankful. The program should calculate and display the miles per gallon obtained for each tankful. After processing all input information, the program should calculate and print the combined miles per gallon obtained for all tankfuls.
General form
for
( statement1 expression1; expression2 )
statement2;
...
statements
case constant-expression_3:
case constant-expression_4:
...
statements
default:
statements
}
EXAMPLE