ENSC 104: DIGITAL COMPUTER PROGRAMMING

PROGRAMMING STANDARDS


Standard 1.0: All programs will have a title section beginning at the first line in the program source code.

	//
	// Filename:      *.cpp
	//
	// Description:   'Exact description of problem and the problem 
        //                number if applicable.' For example: 1.23) Write a 
        //                program that asks the user to enter two numbers, obtains
        //                the two numbers from the user, and prints the sum, 
        //                product, difference,  and quotient of the two numbers.
	//
	// ENSC 104:      Digital Computer Programming
        //
        // Instructor:    Dr. Walsh
	//
	// Class Time:    11:00 or 12:30
	//
	// Date Created:  xx/xx/98
	// Last Modified: xx/xx/98
	//
	// Name:          student's name
	//

Standard 2.0: All If statements will use three space indentation and braces around if and else blocks of code. Note that the if and its corresponding else will be alligned vertically.

       if ( grade >= 90 )
          {
          cout << "A\n"; } else if ( grade>= 80 )
               {
               cout << "B\n"; } else if ( grade>= 70 )
                    {
                    cout << "C\n"; } else if ( grade>= 60 )
                         {
                         cout << "D\n"; } else { cout << "F\n"; } 

Standard 3.0: Only one variable declared per line.

             int loop_counter;
             int num_students;
             float grades;
             float average;
             char name[20];   

Standard 4.0: All for, while and do while loops will include braces that will be indented three spaces from the keyword for, while or do. Even if the body of the loop is a single statement, you must use the braces.

             for ( i=0; i&ltN; i++)
                {
                body of loop;
                }

             while ( expression )
                {
                body of loop;
                }

             do
                {
                body of loop;
                } while ( expression );


Standard 5.0: The main function and all subroutines will have the braces surrounding the body of their function indented three spaces from the function name.

             main()
                {
                int variable_1;
                int variable_2;

                ...

                for ( i=0; i&ltN; i++)
                   {
                   statement1;
                   statement2;
                   ...
                   statementN;
                   }

                ...

                return 0;
                }

Standard 6.0: All variables used local to main will be declared immediately after the function name 'main()'.

                main()
                   {
                   int variable_1;
                   int variable_2;
                   .
                   .
                   .
                   int variable_n;
                   .
                   . main body of code
                   .
                   return 0;
                   }