COMP102 Lab 4 - PowerPoint PPT Presentation

1 / 5
About This Presentation
Title:

COMP102 Lab 4

Description:

Coding Style. Compilation will succeed if your code does not contain syntax errors ... and maintain the code, there are a few coding guideline in addition to ... – PowerPoint PPT presentation

Number of Views:42
Avg rating:3.0/5.0
Slides: 6
Provided by: raym168
Category:
Tags: code | comp102 | lab

less

Transcript and Presenter's Notes

Title: COMP102 Lab 4


1
COMP102 Lab 4
2
Coding Style
  • Compilation will succeed if your code does not
    contain syntax errors
  • However, error-free code doesnt imply that it is
    good enough
  • To assist you (and your partners) to understand,
    write and maintain the code, there are a few
    coding guideline in addition to syntax rules
  • It also helps to eliminate careless mistakes

3
Coding Style (Cont)
  • Start the program with a header that tells what
    the program does
  • Use meaningful variable names
  • Document each variable declaration with a comment
    telling what the variable is used for
  • Place each executable statement on a single line
  • A segment of code is a sequence of executable
    statements that belong together
  • Use blank lines to separate different segments of
    code
  • Document each segment of code with a comment
    telling what the segment does
  • Sub-block with indentation

4
A Good Example
/ this application is to judge whether a
person is fit or not. / include
ltiostream.hgt void main() int weight // the
weight of the person int height // the height
of the person int gender // the gender of the
person // ask user to input his/her
weight cout ltlt "pls input your weight (kg)
" cin gtgt weight // ask user to input his/her
height cout ltlt "pls input your height (cm)
" cin gtgt height // some more code...
5
A Good Example (Cont)
// more... if ( 0 gender ) constant
110 else if ( 1 gender ) constant
105 else cout ltlt "wrong input!" return
// more...
Write a Comment
User Comments (0)
About PowerShow.com