BASIC FORMATTING GUIDELINES

  1. Start every file of your program with an identification section consisting of the following :

    // =============== ===================================
    //
    //
    Name: individual name/s
    and group name ( if appropriate )
    //
    //
    //
    Course: CMPSC 101 or 201 /
    CSE 121 or 122 /
    IST 230
    // Project Number: 3
    //
    //
    NSD Due Date: 1976 August 13
    ( for CMPSC 101, 201, CSE 103 only )
    // Project Due Date: 1976 August 20
    // Project Filename: a:demo.bpr
    // Program Filename: demo.cpp
    // Input Filename: a:demo.dat ( if any )
    // Output Filename: a:demo.txt
    // =============== ===================================

  2. State the objective of the program in the program abstract section which follows the identification section.   Include the input data required by the program as well as the output to be produced by the program.

    // =============== ===================================
    // Program Abstract: The purpose of this program is . . .
    // Input Required: ( describe input required and manner of data input )
    // Output Desired: ( describe program output produced )
    // =============== ===================================

  3. List of header files following the program abstract section.

  4. Global function prototypes which include the main function prototype follow the list of header files.
    Separate the prototypes from the header files with a blank line.

  5. Declaration of global variables, if any, follow the global function prototypes.
    Separate the global variables from the prototypes with a blank line.

  6. Refer to the following as a separator line .

    // =========================================================================

  7. The main function follows the global variables.
    Separate the main function from the global variable with a separator line.

  8. Separate functions with a separator line.

  9. Each function should mirror the order of the main program in that it should consist of its own abstract section, followed by any function prototypes, declarations of variables local to the function, if any, and each section separated by a blank line.

  10. Each statement must begin on a new line.

  11. Use two blank spaces for all indentations .

  12. Always indent when using the delimiters "{" and "}" and indent further all statements within these delimiters.

  13. Use a blank space before and after variables and operators as you would in an ordinary text.
    Consider operators as you would consider identifiers.

    x = ( – b + sqrt ( b * b – 4 * a * c )) / ( 2 * a )   and NOT   x=(–b+sqrt(b*b–4*a*c))/(2*a)

    mp = ( P * i ) / ( 1 – 1 / (Power ( 1 + i, t )))   and NOT   mp=(P*i)/(1 – 1/(Power(1+i,t)))

// ==============================================
// identification section
// ==============================================
// program abstract section
// ==============================================
list of header files
list of global function prototypes
list of global variables
// ==============================================
// function abstract section
// ==============================================
main function definition heading
    {
        list of local function prototypes
        list of local variables
        function statements
    }
// ==============================================
// function abstract section
// ==============================================
another function definition heading
    {
        list of local function prototypes
        list of local variables
        function statements
    }

Example:   average.cpp

© 1999-01-12 cpsm ; last update 2006-12-04