Presentation is loading. Please wait.

Presentation is loading. Please wait.

Program style. Global area Place comment s at beginning of the program: 1.purpose 2.author 3.the date the program was written 4.the data and description.

Similar presentations


Presentation on theme: "Program style. Global area Place comment s at beginning of the program: 1.purpose 2.author 3.the date the program was written 4.the data and description."— Presentation transcript:

1 Program style

2 Global area Place comment s at beginning of the program: 1.purpose 2.author 3.the date the program was written 4.the data and description of all cahnges Preprocessor commands: 1.all includes 2.defined constants 3.macros

3 Global area Prototype Structure /* this program … written by: date: change history: mm / dd / yy : */ #include … // constants //prototype declarations //marcos //interprogram communication varibales

4 Program main line The only statements found in main are: 1.a start-of-program message 2.function calls 3.an end-of-program message. Int main(void) { // local definitions // statements cout<<“ begin program …”<<endl; count<<“end of program…”<<endl; return 0; } //main

5 General coding standards Don’t crowd your code 1.at least one space before and after every operator. 2.at least one space beginning and end of every expression. 3.align the operator and second operand in a series of assignment statement.

6 General coding standards Only one declaration or definition may be coded on a line. Group variable declarations by type. order them alphabetically by type and place a blank line between types. Abbreviate only when identifiers become long: 1.remove all vowels unless they start a word 2.represent double consonants by a consonant.

7 General coding standards Minimize the number of statement within a function. The statement portion of a function should fit on a screen. All blocks are terminated with a comment. 1.end a function block with a comment that contains the name of the function. ex: //main 2.end if statements with // if or // if 3.end else statement with // else or // else

8 General coding standards 4.end while statement with //while 5.end for statements with //for 6.cooment intrafucntion blocks at the beginning and at the end

9 Variable and structures Use intelligent identifier names. 1 avoid single-character identifiers except for loop counters in a for statement. 2.identifiers should clearly convey their contents and use.

10 Function definition Always explicitly code the return type. Begin each function with comments: 1.identify its purpose 2.explain its parameters and return value. Place the parameters within a function prototype statement on multiple lines only when there are to many. Clearly document the declarative portion of all functions (general coding standards)

11 Function definition Within a function. use comments only to explain a block of code. Place comments at the beginning of the code that need explanation, Do not place comments on lines. Terminate all functions with a return a statement. Avoid multiple return statement within a function. Clearly mark the end of the program.

12 Function definition /* ================ ======================== pre post */ Int doIt ( int p1, float p2) { // Local Definitions // statements return 0; } // //=====================end of program=======================

13 Question?


Download ppt "Program style. Global area Place comment s at beginning of the program: 1.purpose 2.author 3.the date the program was written 4.the data and description."

Similar presentations


Ads by Google