Tags:
create new tag
view all tags

C++ Coding Style Standard

Coding style is important as it make easier to read, easier to correct, and easier to change. It is an investment in the future!

Features

  • Indentation - Code should be indented to match how deeply it is embedded within code blocks (between { and } )
  • Comments - You should carefully, and precisely, place comments through the program to explain that may not be completely clear with an explaination. You should also use comments to what the program does, who wrote it, what date it was created, and when appropriate a dated change history.
  • Indentifier Names - Should be meaningful with respect to the purpose they serve in the code.
//File Name: health.cpp 
//Author: Your Name Goes Here.
//Email Address: you@yourmachine.bla.bla
//Assignment Number: 2
//Description: Program to determine if the user is ill.
//Last Changed: September 23, 2016

#include <iostream>
using namespace std;
int main( )
{
    const double NORMAL = 98.6;//degrees Fahrenheit
    double temperature;
 
    // Get the measured temperature
    cout << "Enter your temperature: ";
    cin >> temperature;
 
    // Check if temperature is in the normal range or not,
    // and give user appropriate advice
    if (temperature > NORMAL)
    {
        cout << "You have a fever.\n";
        cout << "Drink lots of liquids and get to bed.\n";
    }
    else 
    {
        cout << "You don't have a fever.\n";
        cout << "Go study.\n";
    }
    return 0;  
}

-- Jim Skon - 2016-09-05

Comments

Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r3 - 2016-09-08 - JimSkon
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2018 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback