|
|
|
|
|
|
|
Test Score Weight
90 0.30
85 0.25
78 0.45
Weighted average = 83.35 |
|
|
|
|
|
|
|
|
An important part of implementing a program is testing it (checking the results). By now you should realize that there is nothing magical about the computer. It is infallible only if the person writing the instructions and entering the data is infallible. Don't trust it to give you the correct answers until you've verified enough of them by hand to convince yourself that the program is working. |
|
|
|
|
|
|
|
|
From here on, these Testing and Debugging sections offer tips on how to test your programs and what to do if a program doesn't work the way you expect it to work. But don't wait until you've found a bug to read the Testing and Debugging sections. It's much easier to prevent bugs than it is to fix them. |
|
|
|
|
|
|
|
|
When testing programs that input data values from a file, it's possible for input operations to fail. And when input fails in C++, the computer doesn't issue a warning message or terminate the program. The program simply continues executing, ignoring any further input operations on that file. The two most common reasons for input failure are invalid data and the end-of-file error. |
|
|
|
|
|
|
|
|
An end-of-file error occurs when the program has read all of the input data available in the file and needs more data to fill the variables in its input statements. It might be that the data file simply was not prepared properly. Perhaps it contains fewer data items than the program requires. Or perhaps the format of the input data is wrong. Leaving out whitespace between numeric values is guaranteed to cause trouble. For example, we may want a data file to contain three integer values25, 16, and 42. Look what happens with this data: |
|
|
|
|
|