Modifications of departmental standards are in red. Also see program template for an example.

Computer Science 300, Spring 2015
Coding Standard

Your code must meet the following coding standard. It is not a recommendation, it is a requirement. Clarity, simplicity, and organization are the goals.

Programs in CSC 300 and above should be in Unix format and compile and run on the Linux machines in the department without modification. Programs in Windows format or that compile and run only on Windows machines will lose significant credit.


Overall program structure is as follows:


The program must have a header block containing: Every method and function (including main) must have a header block containing:
            ifstream & fin       -  file to read the values from
            int n                -  the number of values in the file
Blocks of code need short descriptions to identify their purpose. For example:
        // fill the array with values 1,2,3,...,n
        for ( i = 0; i < n; i++ )
          list[i] = i + 1;
Inline comments should be used to clarify anything that is not immediately obvious in the code.
        roll = ( rand() % 11 ) + 2;        // compute random roll of dice

White space

Should be used liberally


Many source code editors will automatically indent your code for you. Be sure to tailor their settings to match the formatting scheme outlined here. (In particular, remember that the TAB settings do not apply outside of your editing environment. Recommendation: configure your editor to replace TAB characters with spaces when saving files.)

There are several automatic indentation programs available for reformatting existing code. We recommend "Artistic Style" ( as one of the better source code formatters. After formatting your source file, be sure to double check your code for compliance to the coding standards.

Variables and other identifiers


C++ Classes

Make a habit of separating the class interface from the implementation. The class interface contains declarations for data members and member functions prototypes, not executable code. It should be placed in a header file (.h extension), and the #included in all files that use the class. The class implementation contains the member function definitions, It should be placed in a C++ source code file (.cpp or .cc extension), compiled separately, and the resulting object module should be linked in with your program. Class implementation files should not be #included like header files. (The only valid exception to this rule involves template classes. Many C++ compilers/linkers cannot correctly manage separate compilation of template classes, so #including the entire template class may be your only option.)

Runtime requirements

Unless stated otherwise in the assignment specification: