Following these style rules is 50% of every program grade. Before you
submit a program, go through the list and make sure you have followed
every style rule.
(1) Every C++ source file must include a header comment with this format,
as the first information in the file:
/* AUTHOR: put your name here
DUE DATE: from web page
SUBMISSION DATE: when you handed it in
SUMMARY
"Blurb on the cover" that tells what the code does
INPUT
Keyboard, file, none, ....? What data types?
BAD DATA CHECKING: if you do some, tell about it
OUTPUT
Tell what shows up on the screen, what is written to any files, etc.
ASSUMPTIONS
What do you expect the user to know, to do, to NOT do, etc.
*/
(2) All code, comments, and output should fit on the page;
i.e., they should not wrap around or be truncated.
Long statements that would run off the page should be split
in a logical manner and should be indented at least 3 spaces.
(3) Each statement begins on a new line.
(4) Identifiers must be meaningful - variable, constant, function, etc.
Exception: Simple for loop index (i,j, etc.) declared in the loop
for (int i = 0; i < maximum; i++)
(5) C++ is case sensitive.
variable and function names should start with a lower case letter and use
an underscore ( _ ) to separate words..
CONSTANTS should be all capitals and use underscore to separate words.
(6) Comment all variables, constants, functions, lines of code, etc.
whose meaning would not be obvious to a beginning programmer.
Names like temp and num3 are not meaningful. (Often, a better name
for a variable can be found in the comment. Then you don't need
the comment any more!)
(7) Blank lines separate logical blocks of code.
(8) Comment logical blocks of code (like chapter titles in a book).
(9) Left braces { must appear on a new line right under the first character
of the previous line. Right braces } must line up with the corresponding left
brace and have a comment telling what is ending. For example:
int main ()
{
cout << "Hello world!";
} // main
(10) Indent 3 spaces inside each pair of {} or each control statement.
(Use a fixed width font (Monaco, Courier, etc.) so the spaces show up.)
while (x < 3)
x += 4;
while (y > 4)
{
x++;
y += x + z;
z = y + x;
} // while
(11) Put a space before and after all binary operators.
(12) Use well designed I/O (see p. 58 in text)
(13) In functions, put the variable declarations first.
(14) Only one exit point in every loop. (do not use continue. break
should be used only in switch statements)
(15) A for loop is a contract - don't break the contract by changing
the loop control variable in the body of the loop.