270 likes | 290 Views
CS2006 - Data Structures I. Chapter 2 Principles of Programming & Software Engineering. Topics. Software Life Cycle. 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?.
E N D
CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering
Topics • Software Life Cycle
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?
Introduction • A better way • Systematic way (Structured approach) • Specify problem • Analyze • Design • Implement • Test • Maintain
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
The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing 7. Refining 8. Production 9. Maintainence
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.
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
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
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.
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.
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
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?
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
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.
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
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
A S1 S2 S3 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
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
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.
8. Production • Distribute the SW product to its intended users • Install the SW • Use the SW
9. Maintenance • Correct errors not discovered during testing • Add more features • Enhance existing features • Modify to suit the user better
Review • The first phase of the life cycle of software is the ______ phase. • design • risk analysis • specification • coding
Review • The syntax errors of a program are removed during the ______ phase of the program’s life cycle. • verification • coding • testing • refining • maintenance
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”
Review • During the design phase of the software life cycle, the program is divided into ______. • invariants • loops • Modules • prototypes
Review • A prototype program is created during the ______ phase of the software life cycle. • design • specification • Coding • testing