The following three chapters introduce basic C++ program structure and syntax inthe context first of procedural programming and subsequently, in the two laterchapters, of object-oriented programming. The material in these chaptersaddresses the significant challenges encountered by beginning programmers.
Scientific software development
Procedural programing follows a clearly defined set of steps, which are discussedindividually in this section.
Problem definition. First, a problem description that capturesthe main scenarios (possible outcomes), including possible abnormal situations,such as, for example, those generated by erroneous input data, should beformulated.
Detailed specification. A program specification comprises adetailed solution strategy such as the form and content of the input and outputdata, the equations to be programmed, the numerical methods to be employed, thehardware and software to be used and the manner in which the code will handlethe various scenarios. This can be facilitated by first generating the input andoutput screens that the user will encounter.
Iterative coding and modular testing. Subsequently, the programtasks should be compartmentalized into functions. Each of these should beverified independently with a set of test data that is subsequently saved incomment lines for possible future use. Comments should be supplied for eachadditional function or block of code and the verified code modules packaged forreuse in other projects. As a rule, only a single change or function isadded to the program at a time before retesting. In addition, beforeimplementing any non-trivial change, the previous version of the code (withan appropriate version number) should be saved in case an inadvertent erroris introduced. An editor that can identify the differences betweentwo text files can then find subtle errors such as adding an additional(sometimes invisible) character during editing.