Basic C Programming - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

Basic C Programming

Description:

Writing a C Program ( 1.7) There are 3 fundamental steps to ... development environment (IDE) like Borland C Builder) ... with Borland C ... – PowerPoint PPT presentation

Number of Views:129
Avg rating:3.0/5.0
Slides: 11
Provided by: robert1778
Category:

less

Transcript and Presenter's Notes

Title: Basic C Programming


1
Basic C Programming
Review C Programming Elements, Expressions,
Control Flow, Functions, Classes
2
Writing a C Program ( 1.7)
  • There are 3 fundamental steps to writing a C
    program
  • Design
  • Coding
  • Testing and Debugging

3
Design ( 1.7.1)
  • Perhaps most important step!
  • Determine classes
  • how they will interact
  • data each will store
  • actions each will perform

4
Class Design Rules of Thumb ( 1.7.1)
  • Responsibilities Divide the work into different
    actors
  • each with a different responsibility
  • describe responsibilities using action verbs
  • actors will form the classes
  • Independence Keep work of classes as independent
    as possible
  • Behaviors Define behaviors of each class
    carefully and preciselythese will define member
    functions (the set of behaviors may be called a
    protocol).

5
Coding ( 1.7.2)
  • Once design phase completed, create actual code
    for the classes (using integrated development
    environment (IDE) like Borland CBuilder).
  • Compile into working code
  • fix any identified syntax errors
  • Run program!

6
Readability and Style ( 1.7.2)
  • Programs should be easy to read and understand
  • Use meaningful names for identifiers.
  • Can be read aloud and reflect the action,
    responsibilty, or data
  • capitalize first letter unless for a variable or
    method
  • Date Vector identify classes
  • isFull() studentName identify a member
    function variable
  • Use named constants and enumerations
  • Indent statement blocks.
  • Organize each class in a consistent order.
  • private properties
  • private/protected member functions
  • public member functions
  • Use comments that add meaning and explain
    confusing constructs.

7
Testing Debugging ( 1.7.3)
  • Testing
  • process of verifying the correctness of program
  • Debugging
  • process of tracking execution of program and
    discovering errors in it
  • Most time-consuming activity in program
    development!

8
Testing ( 1.7.3)
  • A careful testing plan is essential.
  • Often impossible to verify correctness over all
    possible inputs
  • Select a representative subset of test values
  • Method coverage
  • Every method tested at least once
  • Statement coverage (better)
  • Every statement executed at least once
  • Check special cases.

9
Testing Arrays ( 1.7.3)
  • For example, suppose you are testing a method
    that sorts an array of integers.
  • Test with an empty array
  • Test with an array of length 1
  • Test when all elements of the array are equal
  • Test when array already sorted
  • Test when array in reverse order
  • Also with arrays,
  • Test that boundary/end values are handled
    properly
  • Test with fixed values as well as randomly
    generated/user defined values

10
Debugging ( 1.7.3)
  • Possible techniques
  • Use print statements (cout ltlt x) to track
    variable values during execution
  • simplest technique
  • problem these statements must be deleted or
    commented out later before program could be
    executed as desired
  • Use a debugger
  • better approach
  • a specialized environment for controlling and
    monitoring program execution
  • insert breakpoints within codeexecution stops at
    each, and current values of variables can be
    observed
  • Investigate with Borland C Builder
Write a Comment
User Comments (0)
About PowerShow.com