Coding_Style

Coding_Style - Coding Style From Cs142fa11 Jump to:...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Coding Style From Cs142fa11 Jump to: navigation , search C++ Language Coding Standards
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Contents 1 Introdu ction 2 Test Cases 3 Source Files 4 Functio ns 5 Local Variabl es 6 Constan ts 7 Classes 8 Control Flow 9 Nonline ar Control Flow 10 Naming Conven tions 11 Indentat ion and White Space 12 Braces 13 Unstabl e Layout Introduction This coding style guide should be used for all assignments you submit in class. You will be graded on your ability to create code using these standards. A style guide is a set of mandatory requirements for layout and formatting. Uniform style makes it easier for you to read code from your instructor and classmates. You will really appreciate the consistency if
Background image of page 2
you do a team project. It is also easier for your instructor and your grader to grasp the essence of your programs quickly. Here are the most important highlights: 1. Tabs are set every four spaces. 2. Variable and function names are lowercase. 3. Constant names are uppercase. Class names start with an uppercase letter. 4. There are spaces after reserved words and between binary operators. 5. Braces must line up. 6. No magic numbers may be used. 7. Every function must have a comment. 8. At most 30 lines of code may be used per function. 9. Limit the use of global variables 10.Never, ever, ever use goto Test Cases In order to pass-off your programs, you are required to have test cases. Test cases help you to check your code for errors. The following is an acceptable way of writing your test cases: Inputs Outputs Logic Test Cases For Example: // This program decides on which light bulb is the better deal Inputs: Initial cost of bulb1 Initial cost of bulb2 Power used for bulb1 Power used for bulb2 Cost of power Outputs: Total cost for a year of bulb 1 usage Total cost for a year of bulb 2 usage Logic: Total cost is power cost + initial cost for each bulb Test Cases: 1) bulb1_Cost = 10.50; // dollars bulb2_Cost = 0.85; bulb1_Power = 0.005; // KW bulb2_Power = 0.100; // KW total_bulb1 = 12.69 total_bulb2 = 44.65 2) bulb1_Cost = 0; // dollars bulb2_Cost = 0; bulb1_Power = 0.005; // KW bulb2_Power = 0.100; // KW total_bulb1 = 2.19 total_bulb2 = 43.8 3) bulb1_Cost = 10.50; // dollars bulb2_Cost = 0.85; bulb1_Power = 0.000; // KW
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
bulb2_Power = 0.000; // KW total_bulb1 = 10.50 total_bulb2 = 0.85 Source Files Each program is a collection of one or more files or modules. The executable program is obtained by compiling and linking these files. Organize the material in each file as follows: Header comments #include statements Constants Classes Functions It is common to start each file with a comment block. Here is a typical format: /** @file invoice.cpp @author Jenny Koo @date 2012-01-24 @version 3.14 */ You may also want to include a copyright notice, such as /* Copyright 2012 Jenny Koo */ A valid copyright notice consists of the copyright symbol © or the word "Copyright" or the abbreviation "Copr." the year of first publication of the work
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 10

Coding_Style - Coding Style From Cs142fa11 Jump to:...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online