![Page 1: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022081519/56649f145503460f94c2904a/html5/thumbnails/1.jpg)
CS2006 - Data Structures I
Chapter 2Principles of Programming
& Software Engineering
![Page 2: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022081519/56649f145503460f94c2904a/html5/thumbnails/2.jpg)
2
Topics
Software Life Cycle
![Page 3: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022081519/56649f145503460f94c2904a/html5/thumbnails/3.jpg)
3
Introduction
How do you write a Java program? Old fashion way
Write code Compile Check syntax Run Check logic
How long will this take? Which phase takes more time?
![Page 4: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022081519/56649f145503460f94c2904a/html5/thumbnails/4.jpg)
4
Introduction
A better way Systematic way (Structured approach)
Specify problem Analyze Design Implement Test Maintain
![Page 5: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022081519/56649f145503460f94c2904a/html5/thumbnails/5.jpg)
5
Introduction
SW Engineering: Computer science branch that provides
techniques for development of computer programs
Systematic approach to analyze, design, implement, and maintain software
Uses CASE tools
![Page 6: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022081519/56649f145503460f94c2904a/html5/thumbnails/6.jpg)
6
The Software Life Cycle
1. Specification
2. Design
3. Risk Analysis
4. Verification
5. Coding
6. Testing
7. Refining
8. Production
9. Maintainence
![Page 7: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022081519/56649f145503460f94c2904a/html5/thumbnails/7.jpg)
7
1. Specification & Analysis
Specification A contract between the module and any other
module using it Doesn't include information about how the
task is to be performed or the method of solution, but what
May involve construction of a prototype program to get more details from users.
![Page 8: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022081519/56649f145503460f94c2904a/html5/thumbnails/8.jpg)
8
1. Specification & Analysis
Example: “begin & write a software to store a library’s
catalogue of books” Input:
Librians enter new books as they arrive Library users enter search keys to search
through our list
![Page 9: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022081519/56649f145503460f94c2904a/html5/thumbnails/9.jpg)
9
1. Specification & Analysis
Process: Add new book Search for books
Output: Show all the info about a book
Requirements What type of processing is required Are there any time/space/performance constraints
![Page 10: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022081519/56649f145503460f94c2904a/html5/thumbnails/10.jpg)
10
2. Design
Given: Clear & detailed specification of all aspects of
the problem Output:
Design for a solution to the problem Idea:
Use modular design Divide & conquer Divide the problem into smaller manageable parts.
![Page 11: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022081519/56649f145503460f94c2904a/html5/thumbnails/11.jpg)
11
2. Design
Generate an outline of the problem solution. Requires breaking the entire problem down into
small manageable parts - modules. Modules are self-contained units of code.
![Page 12: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022081519/56649f145503460f94c2904a/html5/thumbnails/12.jpg)
12
2. Design
Design Example: Sort Function Purpose:
Sort an array of integers
Specification: Receive an array of N integers (input), where N > 0
(assumption) Return the array (output) with the integers sorted (action)
Remember: Specification is a contract
![Page 13: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022081519/56649f145503460f94c2904a/html5/thumbnails/13.jpg)
13
2. Design
Design Example: Sort Function First-draft specification:
Sort(A, N)
// Sorts an array
// Precondition: A is an array of N integers; N > 0
// Postcondition:Integers in A are sorted
What is missing?
![Page 14: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022081519/56649f145503460f94c2904a/html5/thumbnails/14.jpg)
14
2. Design
Design Example: Sort Function Revised Specification:
Sort(A, N)// Sorts an array of MAX_ARRAY elements// Precondition:// A is an array of N integers;// and 1 <= N <= MAX_ARRAY, // where MAX_ARRAY is a global constant// that specifies the maximum size of A// Postcondition:// A [0] <= A [1] <= . . . <= A [N-1],// N is unchanged
![Page 15: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022081519/56649f145503460f94c2904a/html5/thumbnails/15.jpg)
15
3. Risk Analysis
Risks are primarily business related but can be personal as well.
Example: If a piece of software is not ready in time the company may lose the market to a competitor.
Not an important issue for this course.
![Page 16: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022081519/56649f145503460f94c2904a/html5/thumbnails/16.jpg)
16
4. Verification
Determining the degree to which a software product fulfills its specification
Formal, theoretical methods for proving algorithm correctness
Assertion (Predicate): Statement about a particular condition at certain point
in an algorithm Invariant:
Condition that is always true at a certain point in an algorithm
![Page 17: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022081519/56649f145503460f94c2904a/html5/thumbnails/17.jpg)
17
5. Implementation (Coding)
Coding Translating the algorithm into a particular
programming language & removing syntax errors
Should not start unless previous stages are well defined
Original solution usually simplified
![Page 18: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022081519/56649f145503460f94c2904a/html5/thumbnails/18.jpg)
18
5. Coding
Bottom-up implementation: First implement submodules, then modules
Top-down implementation: Implement a module before implementing its
submodules Use stubs Refinement might be needed Stubs:
Dummy functions that do nothing and are placed in the place of submodules to focus attention on the module itself
A
S3S2S1
![Page 19: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022081519/56649f145503460f94c2904a/html5/thumbnails/19.jpg)
19
6. Testing
Careful design of test data is important Valid (In-range) data Invalid (out-of-range) data Random values of data
Test several times on different circumstances
Any modification in the program needs re-testing
![Page 20: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022081519/56649f145503460f94c2904a/html5/thumbnails/20.jpg)
20
7. Refining the Solution
Usually involves increasing the "robustness" of a solution.
Often simplifying assumptions are made in the design process that must be removed from final versions.
Example: assume that the input will be be integers between 0 and 1000.
During this step code would be inserted to actually test the input values.
![Page 21: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022081519/56649f145503460f94c2904a/html5/thumbnails/21.jpg)
21
8. Production
Distribute the SW product to its intended users
Install the SW Use the SW
![Page 22: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022081519/56649f145503460f94c2904a/html5/thumbnails/22.jpg)
22
9. Maintenance
Correct errors not discovered during testing
Add more features Enhance existing features Modify to suit the user better
![Page 23: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022081519/56649f145503460f94c2904a/html5/thumbnails/23.jpg)
23
Review The first phase of the life cycle of software
is the ______ phase. design risk analysis specification coding
![Page 24: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022081519/56649f145503460f94c2904a/html5/thumbnails/24.jpg)
24
Review The syntax errors of a program are
removed during the ______ phase of the program’s life cycle. verification coding testing refining maintenance
![Page 25: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022081519/56649f145503460f94c2904a/html5/thumbnails/25.jpg)
25
Review Which of the following is an example of a
logical error? an algorithm that calculates the monthly payment
of a loan displays incorrect results an array subscript in a program goes out of range a program expects a nonnegative number but
reads –23 the beginning of a while loop is written as “whille”
instead of “while”
![Page 26: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022081519/56649f145503460f94c2904a/html5/thumbnails/26.jpg)
26
Review During the design phase of the software
life cycle, the program is divided into ______. invariants loops Modules prototypes
![Page 27: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022081519/56649f145503460f94c2904a/html5/thumbnails/27.jpg)
27
Review A prototype program is created during the
______ phase of the software life cycle. design specification Coding testing