CptS 121 Fall 09 Lecture 12 - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

CptS 121 Fall 09 Lecture 12

Description:

Checks to make sure that program is syntactically correct ... High-level programs often make use of software libraries containing predefined ... – PowerPoint PPT presentation

Number of Views:39
Avg rating:3.0/5.0
Slides: 23
Provided by: eecs8
Category:
Tags: cpts | fall | lecture | make

less

Transcript and Presenter's Notes

Title: CptS 121 Fall 09 Lecture 12


1
CptS 121 Fall 09 Lecture 1-2
  • HK Chapter 1 Computer Software The Software
    Development Process
  • Lecture Outline
  • Computer Software (revisited)
  • Programming Languages
  • Software Development Method
  • Example Application

2
The Continuum of Programming Languages
3
High-Level Programming Languages Developed for
Many Application Areas
  • Scientific programming FORTRAN
  • Business data processing COBOL
  • Artificial Intelligence LISP, PROLOG
  • Systems programming C (this course)
  • Real-time distributed systems Ada
  • GUIs, object-oriented programming SmallTalk
  • Object-oriented programming C, Java, C

4
High-Level languages Must Be Translated
  • Problem Computers cant understand high-level
    programming languages
  • Solution They must be translated
  • Programmer uses a text editor to write a
    text-based source file in a programming language
  • Compiler translates source file
  • Checks to make sure that program is syntactically
    correct
  • If so, the compiler translates the program into
  • an object file with machine language
    instructions

5
Object File Translated by Compiler Willll NOT
Execute
  • High-level programs often make use of software
    libraries containing predefined pieces of code,
    including
  • Math functions
  • Input/output functions
  • In order to execute, object file must be linked
    to object files containing these predefined
    pieces of code
  • A Linker program performs this operation
  • A Loader program loads the linked program into
    memory so that it can be executed

6
Executing Programs Results in Interactive Program
  • In this class, programs will execute in a
    text-based window called a console
  • Input data can be entered at command-line prompts
  • Output results will be displayed in the console
    window
  • In the real world, most programs have a graphical
    user interface
  • GUI programming is, however, beyond the scope of
    this course

7
Integrated Development Environments Make
Programming More Accessible
  • Combine compiler, linker, and loader with a
    source code editor
  • Insulate programmers from the details of
    compiling, linking, and loading
  • Provide a variety of tools to assist programmers,
    for example,
  • Source code syntax highlighting
  • Autocompletion lists ("Intellisense")
  • A debugger, which allows a programmer to step
    through programs, one instruction at a time

8
Software Development Method Provides Systematic
Approach
  • Analogous to the Scientific Method in the
    sciences, and the Systems Approach in business
  • Six basic steps
  • Specify problem requirements
  • Analyze the problem
  • Design an algorithm to solve the problem
  • Implement the algorithm
  • Test and verify the completed program
  • Maintain and update the program

9
1.Specify Problem
  • In the real world of analysis, problem
    specification is called requirements analysis,
    and it is one of the most difficult steps
  • In this class, the problem will be given to you
    in a few sentences, or as a pseudocode algorithm
  • Usually, there will be some sort of scenario to
    make the problem more concrete
  • Exact inputs and outputs may not be specified,
    but should be inferable from the problem statement

10
2. Analyze Problem
  • Identify
  • Inputs (input data to be processed)
  • Outputs
  • the results to be displayed and/or stored
    somewhere
  • The format of the results
  • Problem variables
  • Formulas relating problem variables
  • If problem specification and analysis are done
    wrong, youll solve the wrong problem

11
Example of Problem Specification and Analysis
  • Problem statement Calculate the temperature in
    degrees Celsius given the temperature in degrees
    Fahrenheit
  • Problem Input
  • FahrenheitTemp Temperature in degrees Fahrenheit
  • Problem Output
  • CelsiusTemp Temperature in degrees Celsius
  • Formula
  • CelsiusTemp 5/9 (FahrenheitTemp 32)

12
3. Design Algorithm
  • Can be the most challenging and creative part of
    the method
  • Decompose the problem into high-level steps or
    subproblems (top-down design)
  • Then figure out the details of solving each
    subproblem (algorithm refinement)
  • Use pseudocode to write algorithms in this step
  • General algorithm
  • Get the data
  • Perform the computations
  • Display the results
  • Desk check your algorithm
  • Simulate its execution on sample input data
  • Make sure that it works with the correct inputs,
    and produces the correct outputs

13
4. Implement Algorithm
  • Translate your pseudocode into a high-level
    programming language
  • Remove all syntax errors from your program

14
5. Test and Verify Completed Program
  • Testing
  • Perform code review on a team to identify issues
    with the code, e.g.,
  • Does your implementation meet requirements?
  • Is the code well documented?
  • Does it adhere to good design principles?
  • etc.
  • Run your program with sample input data
  • Verify that the outputs are correct
  • Use a debugger to trace through your program and
    to pinpoint logic errors (debugging is an
    essential part of testing)

15
6. Maintain Program
  • Most programs are used for a long period of time
    (5 years or more)
  • Previously undetected errors will emerge, and
    clients needs will change
  • Maintenance will thus be required to keep the
    program up to date and working properly

16
Documentation is an Important Part of Maintenance
  • Programs often outlast the programmers who
    originally developed them
  • It is therefore important to make it easy for new
    program team members to maintain a program
  • Document, document, document!
  • Comments are absolutely essential to reading and
    understanding someone elses code
  • Adhere to established or accepted coding
    conventions and style
  • Clever code that solves problems in
    unconventional ways is difficult to understand
    and maintain

17
Applying the Software Development Method
  • Warning You will rarely get it right the first
    time! This is an iterative process in which you
    would do well to be persistent and learn from
    your mistakes
  • Example problem Compute a students quiz score
    average given three integer quiz scores.

18
Step 2. Analyze Problem
  • Problem inputscore1, score2, score3 (the three
    quiz scores)
  • Problem outputaverage (the average of the three
    quiz scores)
  • Relevant formulaaverage sum of scores/number
    of scores

19
Step 3. Design the Algorithm
  • Algorithm
  • Get the three quiz scores
  • Compute the average score
  • Display the result
  • Refined algorithm
  • Get the three quiz scores
  • Compute the average score
  • Average (score1 score2 score3)/3
  • Display the result

20
Step 4. Implement the Algorithm
  • Implementation (in C)/ Computes the average
    of three quiz scores /include ltstdio.hgt /
    printf, scanf defs /define NUM_SCORES 3int
    main(void)
  • int score1, score2, score3 double
    average / Get the scores / printf("Enter
    quiz score 1 ") scanf("d", score1)
    printf("Enter quiz score 2 ") scanf("d",
    score2) printf("Enter quiz score 3 ")
    scanf("d", score3) / Compute average /
    average ((double)(score1 score2 score3))/
    ((double) NUM_SCORES)
    / Display result / printf("The average of
    those three scores is f.", average)
    return(0)

21
Steps 5 and 6 Test and Maintain Program
  • Testing
  • This program is too small for a peer code review
    to be of much help
  • We would compile and execute the program, trying
    several different input data values and observing
    the results
  • Maintenance
  • It is highly unlikely that this particular
    program will be of general use to anyone. Most
    likely, we'll want to update it with new
    functionality

22
Next Week
  • We've covered the general software development
    method
  • It's time to start learning the C language!
  • Have a great weekend!
Write a Comment
User Comments (0)
About PowerShow.com