



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




For this course, each program should contain the following header information
Separate your program into independent, self-complete modules. We’ll discuss this in more detail later.
Make your style as consistent as possible. The more consistent your style, the easier it will be to read and understand your program (not just others, but yourself as well!) Consistency will lead to fewer mistakes. The more consistent your style, the more automatic it will become for you and you’ll spend less time thinking about program style and more about the problem at hand.
Make the indentation of your code reflect the structure of the program. For example, if (count == 0) printf (“No data.\n”); fails to match the structure of the program. It is much better to write this as: if (count == 0) printf(“No data\n”); Here’s another bad example: if (count != 0) printf(“%d\n”, count); average = total/count; This last example is much more clear if it is indented as follows:
COP 3502C – Summer 2002 Lab Number: Assignment Number: Name: Student ID: Date:
if (count != 0) printf(%d\n”, count); average = total/count;
The natural flow of reading is vertically down the page. Things that get in the way of this or detract from this flow will make a program harder to read. We’ll see this more later in the semester as well.
Make each variable declaration unique. Don’t put more than one variable into a single declaration. Also line up the names in the variable declarations, it will make finding a variable much easier. GOOD: int i, j, k; float: a, b; BAD: int i, j, k; float a, b;
The braces which define the begin and end of a compound statement or a block of statements should be vertically aligned. There are two acceptable styles and you should adopt one or the other. Style 1: if ( … ) while ( … ) { { … … } } else { … } Style 2: if ( … ) { while ( … ) {
****************************************************************/ /* List all of the header files used here. #include <stdio.h> #include <stdlib.h> #include <time.h> /* List function prototypes here. / void func1 (int x, int y); int func2( ); / Describe the purpose of func1 / void func1 (int x, int y) { . . . } / Describe the purpose of func2 / int func2 ( ) { . . . } int main (void) { / indent the declarations and the body of the functions by at least three spaces. / int x; / if necessary describe the variable’s purpose / int y; / use short but meaningful variable names. */
/* leave a blank line before and after a loop. /* denote the end of a loop with a comment / return 0; } / end main */