Published online by Cambridge University Press: 05 June 2012
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.
To save this book to your Kindle, first ensure no-reply@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.
Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.
Find out more about the Kindle Personal Document Service.
To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.
To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.