|
|
|
|
|
|
|
// Assumptions: Solar time is specified for a longitude of 0
// degrees (GMT, UT, or Z time zone) |
|
|
|
|
|
|
|
|
Header comments should also be included for all user-defined functions. (See Chapters 7 and 8.) |
|
|
|
|
|
|
|
|
2. Declaration comments accompany the constant and variable declarations in the program. Anywhere that an identifier is declared, it is helpful to include a comment that explains its purpose. In programs in the text, declaration comments appear to the right of the identifier being declared. For example: |
|
|
|
|
|
|
|
|
const float E = 2.71828; // The base of the natural logarithms
float deltaX; // The difference in the x direction
float deltaY; // The difference in the y direction |
|
|
|
|
|
|
|
|
Notice that aligning the comments gives the code a neater appearance and is less distracting. |
|
|
|
|
|
|
|
|
3. In-line comments are used to break long sections of code into shorter, more comprehensible fragments. These are often the names of modules in your algorithm design, although you may occasionally choose to include other information. It is generally a good idea to surround in-line comments with blank lines to make them stand out. For example: |
|
|
|
|
|
|
|
|
// Prepare file for reading
scoreFile.open(scores.dat);
// Get data
scoreFile >> test1 >> weight1;
scoreFile >> test2 >> weight2;
scoreFile >> test3 >> weight3;
// Print heading
cout << Test Score Weight << endl; |
|
|
|
|
|
|
|
|
Even if comments are not used, blank lines can be inserted wherever there is a logical break in the code that you would like to emphasize. |
|
|
|
|
|
|
|
|
4. Sidebar comments appear to the right of executable statements and are used to shed light on the purpose of the statement. Sidebar comments are often just pseudocode statements from the lowest levels of your design. If a |
|
|
|
|
|