< previous page page_177 next page >

Page 177
Summary
Programs operate on data. If data and programs are kept separate, the data is available to use with other programs, and the same program can be run with other sets of input data.
The extraction operator (>>) inputs data from the keyboard or a file, storing the data into the variable specified as its right-hand operand. The extraction operator skips any leading whitespace characters to find the next data value in the input stream. The get function does not skip leading whitespace characters; it inputs the very next character and stores it into the char variable specified in its parameter list. Both the >> operator and the get function leave the reading marker positioned at the next character to be read. The next input operation begins reading at the point indicated by the marker.
The newline character (denoted by \n in a C++ program) marks the end of a data line. You create a newline character each time you press the Return or Enter key. Your program generates a newline each time you use the endl manipulator or explicitly output the \n character. Newline is a control character; it does not print. It controls the movement of the screen cursor or the position of a line on a printer.
Interactive programs prompt the user for each data entry and directly inform the user of results and errors. Designing interactive dialogue is an exercise in the art of communication.
Noninteractive input/output allows data to be prepared before a program is run and allows the program to run again with the same data in the event that a problem crops up during processing.
Data files often are used for noninteractive processing and to permit the output from one program to be used as input to another program. There are four things you have to do to use these files: (1) include the header file fstream.h; (2) declare the file streams along with your other variable declarations; (3) prepare the files for reading or writing by calling the open function; and (4) specify the name of the file stream in each input or output statement that uses it.
Top-down design and object-oriented design are methods for tackling large programming problems. Top-down design begins with an abstract solution that then is divided into major steps. Each step becomes a subproblem that is analyzed and subdivided further. A concrete step is one that can be translated directly into C++; those that need more refining are abstract steps. A module is a collection of concrete and abstract steps that solves a subproblem. Programs can be built out of modules using a flat implementation, a hierarchical implementation, or a semihierarchical implementation.
Object-oriented design produces a problem solution by focusing on objects and their associated operations. The first step is to identify the major objects in the problem and choose appropriate operations on those objects.

 
< previous page page_177 next page >