Guidelines for grading Programming Assignments

The grade will be based on a scale of 100. Points will be based on both style and execution. Style will count 30 and execution will count 70. Lateness points will be subtracted after points have been subtracted for errors of style and execution. The remaining points will be recorded as the grade for the program. For example, if there are 10 points of style errors and 15 points of execution errors, the grade would be 75. If, however, the program is two days late, the lateness penalty would be 20%, and the grade would be 75-20 = 55. The schedule for lateness is given with your first programming assignment.

Here are some guidelines for the two categories, style and execution.

Style 30 points. Style consists of comments, mnemonic variable names, and indentation. The purpose of good style is to make the meaning of your program clear to someone who has never seen it before, cannot run it, and cannot talk with you.

  1. Comments 15 points. Both new and old style comments are correct. There should be a prologue of approximately this form:
    // CIS 303, Section 1, Fall 1999, Programming Assignment 1
    // Author: Ima Student
    // Purpose: Print ten approximations to a square root.
    // Usage:  The user types in one positive number.  It need not be an integer.
    // Method: The user is prompted for the number.  A first approximation
    //        is made by ....  A for loop is used to ....  Each approximation ....
    ////////////////////////////////////////////////////////////////////////////////
    
    There should be comments alongside the definition (or declaration) of every variable.
    const char control_z = 26; // ASCII code for control-z
    char input_char;           // input character
    float key[];               // If the comment that goes with the declaration
                               // requires two or more lines, do it this way.
    int i;                     // counter for input while loop
    int numeric = 0;           // 1 if numeric sort, 0 if alphabetic
    
    Interspersed within the C code there should be comments wherever there are statements or expressions that would be difficult to understand by a C programmer. Otherwise no comments are necessary. Here are examples of unnecessary comments:
    s[i++] = c;  // set s[i] to c and then increment i
    sign = ( s[i] == '-' ) ? -1 : 1;  //  Set sign to -1 if the character s[i]
                                      // is a minus sign, or +1 otherwise.
    
    The comments are of two types. The first type of comment is written on the same line with a statement explaining that statement. The comments with the declarations above are examples. Here are examples for executable statements:
    for ( i = 0; isspace(s[i]); i++ );  // skip white space
    mask = 0xC0;   // set bits 6 and 7 high, all others low
    
    The second type of comment is written on a line or lines by itself and explains the following statement or block of statements. It should be indented the same distance as the statements following it. Here are some examples:
    // Determine the net worth of each player by subtracting liabilities from
    // assets.
    
    for ( player = 1; player <= number_players; player++ )
    {             
        ...
    }
    
    
    // The following loop counts the number of contiguous groups of
    // equal numbers in the list and the number of pairs that differ by 1.
    
    for ( i=0; i<size; i++ )
    {
        if ( item[i] == item[i+1] )
        {
           number_of_groups++;
           ...
        }
        else
        {
           ...
        }
        differ = FALSE;
    }
    
  2. Mnemonic variable names 10 points. Each variable's name should indicate its meaning. Counters can be named i, j, k and a character can be named simply c, etc., but constructs that are specific to the particular program should have specific, mnemonic names. Examples are relative_error, page_size, first, last, not_found, input_char.

  3. Indentation 5 points. The indentation should indicate the flow of control. Statements that are nested within a control statement, if, for, while, switch, etc., should be indented a constant distance of at least 3 spaces (One tab will do). More deeply nested statements should be more deeply indented, as in the case of number_of_groups++ above. (The else-if construct is an exception.) The opening brace delimiting a compound statement should be on a line by itself following the control statement, and the closing brace should be on a line by itself, as shown above. The identation of the braces should match the controlling statement, such as in the case of the for statement or the if statement above. (An alternative acceptable style is to indent the braces consistently with the statements within the compound statement itself.)

Execution 70 points. Execution consists of two parts: (1) correct results and (2) efficiency and appropriateness:

  1. Correct results 60 points. The program will be judged in this category on whether it does exactly what was stipulated in the assignment, not on efficiency or appropriateness of the code. Note that "exactly" implies that, if the desired output format has been specified explicitly, no deviation from that format will be allowed. For example, if two numbers are to be printed on the same line, it would be an error if they are printed on two lines, no matter how certain you are that it would be better that way.

  2. Efficiency and appropriateness 10 points. "Efficiency" here means the use of an algorithm "requiring a small amount of time" or "requiring a small amount of memory". For example, if a while loop makes use of some number that does not change during the execution of the loop, it should be calculated only once, before the loop begins, not over and over again inside the loop. "Appropriateness" is the degree to which the program makes use of the appropriate constructs of C in a way that fits the algorithm being implemented. For example, if the algorithm involves a loop that does not increment a loop counter at the end, a while loop is the natural C construct; a for loop should probably not be used. The const attribute or a #define should be used for constants. For selecting among a set of constant values, the switch should be used instead of a string of if...else if statements.

    Perhaps the most important aspect of appropriateness is the degree to which the program is appropriately "modularized". A program is modularized appropriately when clearly identifiable tasks are implemented as separate functions. You will not be able to modularize your programs until you learn how to write and call C functions.

External variables should never be used except as specified by your instructor. (An external variable is one that is not defined inside any function.)

The goto statement should never be used unless specified by your instructor.