the software lifecycle. example problem: update a checkbook write a program that allows the user to...

27
The Software Lifecycle Analysis ------------ Verify Design ------------ Verify Implem entation ------------------- Test Integration ------------- Test Maintenance

Upload: olivia-miller

Post on 27-Mar-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The Software Lifecycle. Example Problem: Update a Checkbook Write a program that allows the user to enter a starting balance, a transaction type, D or

The Software Lifecycle

Analysis------------Verify

Design------------Verify

Implementation-------------------

Test

Integration-------------Test

Maintenance

Page 2: The Software Lifecycle. Example Problem: Update a Checkbook Write a program that allows the user to enter a starting balance, a transaction type, D or

Example Problem: Update a Checkbook

Write a program that allows the user toenter a starting balance, a transactiontype, D or W, and a transaction amount.

The program should perform the given operation (deposit or withdraw) and display the results.

Page 3: The Software Lifecycle. Example Problem: Update a Checkbook Write a program that allows the user to enter a starting balance, a transaction type, D or

Sample User Interactionwith the Program

Enter the starting balance and press <Enter>: 235.16Enter the transaction type (D) deposit or (W) withdrawal and press <Enter>: DEnter the transaction amount and press <Enter>: 75.00

Starting Balance $235.16

Transaction $75.00 D

Ending Balance $310.16

Page 4: The Software Lifecycle. Example Problem: Update a Checkbook Write a program that allows the user to enter a starting balance, a transaction type, D or

Sample User Interactionwith the Program

Enter the starting balance and press <Enter>: 310.16Enter the transaction type (D) deposit or (W) withdrawal and press <Enter>: WEnter the transaction amount and press <Enter>: 65.75

Starting Balance $310.16

Transaction $65.75 W

Ending Balance $244.41

Page 5: The Software Lifecycle. Example Problem: Update a Checkbook Write a program that allows the user to enter a starting balance, a transaction type, D or

Analysis

• Analysis describes what needs to be done to solve a problem, not the details of how that is done

• We can use structure charts or module specifications

Page 6: The Software Lifecycle. Example Problem: Update a Checkbook Write a program that allows the user to enter a starting balance, a transaction type, D or

Structure Chart for Top-Down Analysis

Main Task

Subtask 1 Subtask 2 Subtask 3

Page 7: The Software Lifecycle. Example Problem: Update a Checkbook Write a program that allows the user to enter a starting balance, a transaction type, D or

Structure Chart for The Checkbook Problem

Update checkbook

GetInformation

PerformComputations

DisplayResults

Page 8: The Software Lifecycle. Example Problem: Update a Checkbook Write a program that allows the user to enter a starting balance, a transaction type, D or

Second-Level Refinement

Update checkbook

GetInformation

PerformComputations

DisplayResults

GetStartingBalance

GetTransaction

Type

GetTransaction

Amount

Page 9: The Software Lifecycle. Example Problem: Update a Checkbook Write a program that allows the user to enter a starting balance, a transaction type, D or

Analysis: Specify Module, Task,Inputs, and Outputs

Module: Get information

Task: Have the user enter information from the keyboard

Outputs: starting balance transaction type transaction amount

Page 10: The Software Lifecycle. Example Problem: Update a Checkbook Write a program that allows the user to enter a starting balance, a transaction type, D or

Analysis: Specify Module, Task,Inputs, and Outputs

Module: Perform computations

Task: If the transaction is a deposit add it to the balance else subtract it from the balance

Inputs: starting balance transaction type transaction amount

Outputs: ending balance

Page 11: The Software Lifecycle. Example Problem: Update a Checkbook Write a program that allows the user to enter a starting balance, a transaction type, D or

Analysis: Specify Module, Task,Inputs, and Outputs

Module: Display results

Task: Display the results in readable form

Inputs: starting balance transaction type transaction amount ending balance

Page 12: The Software Lifecycle. Example Problem: Update a Checkbook Write a program that allows the user to enter a starting balance, a transaction type, D or

Design

• Receives the results of analysis

• Describes how a module accomplishes its solution

• Concern is with logic

Page 13: The Software Lifecycle. Example Problem: Update a Checkbook Write a program that allows the user to enter a starting balance, a transaction type, D or

Pseudocode

• Pseudocode is a high-level, non-executable notation for describing designs

• Pseudocode language forms resemble those of most programming languages but are easier to read

• Concern is with logic, not syntax

Page 14: The Software Lifecycle. Example Problem: Update a Checkbook Write a program that allows the user to enter a starting balance, a transaction type, D or

Design: Pseudocode forthe Top-Level Task

1. Get information2. Perform computations3. Display results

Page 15: The Software Lifecycle. Example Problem: Update a Checkbook Write a program that allows the user to enter a starting balance, a transaction type, D or

Second-Level Refinement

1. Get information 1.1 get starting balance 1.2 get transaction type 1.3 get transaction amount2. Perform computations 2.1 if deposit then add amount to balance else subtract amount from balance3. Display results 3.1 display starting balance 3.2 display transaction type 3.3 display ending balance

Page 16: The Software Lifecycle. Example Problem: Update a Checkbook Write a program that allows the user to enter a starting balance, a transaction type, D or

Implementation (Coding)

• Receives the results of design

• One design can be coded in many different programming languages

• Concern is with syntax or correct form of code

Page 17: The Software Lifecycle. Example Problem: Update a Checkbook Write a program that allows the user to enter a starting balance, a transaction type, D or

Steps in Coding

Edit theprogram

Compile theprogram

Run theprogram

Syntax errors

Run-time andlogic errors

Page 18: The Software Lifecycle. Example Problem: Update a Checkbook Write a program that allows the user to enter a starting balance, a transaction type, D or

The Parts of a C++ Program

• Preprocessor directives (to include libraries)

• Main function– data declarations– program statements

Page 19: The Software Lifecycle. Example Problem: Update a Checkbook Write a program that allows the user to enter a starting balance, a transaction type, D or

Program Comments

// Program file: chbook.cpp

// This program updates a checkbook.

Not executable, but describes the task of the program for the reader.

Page 20: The Software Lifecycle. Example Problem: Update a Checkbook Write a program that allows the user to enter a starting balance, a transaction type, D or

Preprocessor Directives

// Program file: chbook.cpp

// This program updates a checkbook.

#include <iostream.h>#include <iomanip.h>

Ask the compiler to include library code for the program.

These libraries contain code for input and outputoperations.

Page 21: The Software Lifecycle. Example Problem: Update a Checkbook Write a program that allows the user to enter a starting balance, a transaction type, D or

The main Function

// Program file: chbook.cpp

// This program updates a checkbook.

#include <iostream.h>#include <iomanip.h>

int main(){ return 0;}

This program actuallydoes nothing, but we’llinclude the code forthe checkbook program shortly.

Page 22: The Software Lifecycle. Example Problem: Update a Checkbook Write a program that allows the user to enter a starting balance, a transaction type, D or

Declare Data Variables

int main(){ double startingBalance, endingBalance, transAmount; char transType;

Each data variable has a name and a type.

Type double is for numbers with a decimal point.

Type char is for letters and other keyboard characters.

Page 23: The Software Lifecycle. Example Problem: Update a Checkbook Write a program that allows the user to enter a starting balance, a transaction type, D or

Declare Data Variables

int main(){ double startingBalance, endingBalance, transAmount; char transType;

C++ is case sensitive. TransType is a different name thantransType.

Use names that describe roles of data in the program.

Page 24: The Software Lifecycle. Example Problem: Update a Checkbook Write a program that allows the user to enter a starting balance, a transaction type, D or

Code the Module for Getting Data

int main(){ double startingBalance, endingBalance, transAmount; char transType; // Module for getting the data.

cout << "Enter the starting balance and press <Enter>: "; cin >> startingBalance; cout << "Enter the transaction type (D) deposit or (W) withdrawal "; cout << endl << "and press <Enter>: "; cin >> transType; cout << "Enter the transaction amount and press <Enter>: "; cin >> transAmount;

Don’t worry about understanding all these statements;we will cover them in detail shortly.

Page 25: The Software Lifecycle. Example Problem: Update a Checkbook Write a program that allows the user to enter a starting balance, a transaction type, D or

Code the Module for Performing Computations

int main(){ double startingBalance, endingBalance, transAmount; char transType; // Module for getting the data (now hidden)

// Module for performing computations.

if (transType == 'D') endingBalance = startingBalance + transAmount; else endingBalance = startingBalance - transAmount;

Page 26: The Software Lifecycle. Example Problem: Update a Checkbook Write a program that allows the user to enter a starting balance, a transaction type, D or

Code the Module for Displaying Results

int main(){ double startingBalance, endingBalance, transAmount; char transType; // Module for getting the data (now hidden)

// Module for performing computations (now hidden)

// Module for displaying results.

cout << setiosflags(ios::fixed | ios::showpoint | ios::right) << setprecision(2);

cout << endl; cout << "Starting balance $" << startingBalance << endl; cout << "Transaction $" << transAmount << " " << transType << endl; cout << "Ending balance $" << endingBalance << endl; return 0;

}

Page 27: The Software Lifecycle. Example Problem: Update a Checkbook Write a program that allows the user to enter a starting balance, a transaction type, D or

Testing

• Receives the results of coding

• Must check to see that the program produces the expected output for any given input

• Cannot be exhaustive; must use typical inputs and limiting cases (such as 0)