next up previous
Next: Activity Up: Syntax Errors Previous: Syntax Errors

Testing a Program

How can you know that a C++ program you have written is correct? If you say "when it gives the right answer," then you are at an impasse, since if you already know the right answer, what is the purpose of the program?

Unfortunately, for a program of any substantial complexity, it is rare that we can be fully confident it is entirely correct. Highly complex programs commonly undergo continued testing, revision and correction even while they are in common use. This is the process called maintaining a program.

Most of the programs you will write in this course can be thoroughly validated by a combination of processes. First, as you become familiar in using C++, you will begin to discover sources of error by inspection. When you have finished writing a program , do not assume it is correct, Read it through again carefully and never assume that you have solved all of the difficulties the first time. The second technique, and one you will find helpful, is called tracing. Tracing is the process of outputting values of certain variables at critical points in the execution of the program. These statements can be removed whenever they no longer serve a useful purpose.


next up previous
Next: Activity Up: Syntax Errors Previous: Syntax Errors
Yousef Haik
2/23/1998