C++ Programming Ground Rules for CS226

Keep this nearby at all times! Points will be lost on programming assignments for not adhering to these standards!

General Rules

Organizing your Program

You must put the various sections of your C++ programs in the following order:

  1. comment block, at the top of the file; the format for this block is given below
  2. #include directives
  3. global constants
  4. type definitions, if any
  5. function prototypes
  6. main function
  7. all other functions

There should be blank lines between each of these sections.

Documentation Standards

//---------------------------------------------------------------------
//
// Name:    your name
// 
// Course:  CS 226, Section 060A, Fall 2002
//
// Purpose: General description of what the program does.  This should
//          be at least several lines long and should discuss the
//          purpose of the program, the format of the input, and the
//          output the program produces.  This information should be
//          from a programmer's perspective (as opposed to the user's
//          perspective).
//
//---------------------------------------------------------------------

Note that you can use cut and paste to copy this header into new programs.

//---------------------------------------------------------------------
// A few lines describing what the function does.
// params: (in/out/inout, ...)
//---------------------------------------------------------------------
result_type function_name(type1 param1, type2 param2, ...)

For example,

//---------------------------------------------------------------------
// This function uses hours and rate to compute and return the gross
// pay and the net pay of an employee.
// params: (in, in, out, out)
//---------------------------------------------------------------------
void ComputePay(int hours, float rate, float& GrossPay, float& NetPay)
        count = count + 1;      // add one to count

is a useless comment. For the most part, you shouldn't need more than one line of comments within functions for every few lines of code. The exception is for very difficult sections of code, where several lines may be needed.

Names

        const int CLASS_SIZE = 25;      // students in class

Be sure to give these constants meaningful names; the name TEN in

        const int TEN = 10;             // useless!

doesn't add to the understanding of the program at all. Any value other than 0 or 1 must be given a name in a constant declaration.

Formatting

You are responsible for proper indentation. MVC++ provides help, but you cannot depend on it to do all the work of indenting your program correctly. If you are using your own version of Turbo C++ or some other compiler, make sure the environment option "insert tab characters" or the equivalent in your system is turned off; this will ensure what you see on the screen is the same as what we grade.

        cout << "The cost for 1 loaf of bread" << endl
             << "is $1.89" << endl;
        if ( radius > 0 )
        {
           area = PI * radius * radius;
        }

Output

Submit based on these handouts . Your project should include the following parts (source code is  mandatory and program should be executable):           

  1. Problem Solving (state the problem description) (2 point)
  2. Algorithm (10 points)
  3. Test Plan (5 points)
  4. Source code (email me .cpp and .h files)
  5. Source code must include comments (see the guidelines below)(20points)
  6. Output (screen shots) (20  point)