Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 The Software Lifecycle

2 Example Problem: Update a Checkbook Write a program that allows the user to enter a starting balance, a transaction type, D or W, and a transaction amount. The program should perform the given operation (deposit or withdraw) and display the results.

3 Sample User Interaction with the Program Enter the starting balance and press : 235.16 Enter the transaction type (D) deposit or (W) withdrawal and press : D Enter the transaction amount and press : 75.00 Starting Balance $235.16 Transaction $75.00 D Ending Balance $310.16

4 Sample User Interaction with the Program Enter the starting balance and press : 310.16 Enter the transaction type (D) deposit or (W) withdrawal and press : W Enter the transaction amount and press : 65.75 Starting Balance $310.16 Transaction $65.75 W Ending Balance $244.41

5 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

6 Structure Chart for Top-Down Analysis Main Task Subtask 1Subtask 2Subtask 3

7 Structure Chart for The Checkbook Problem Update checkbook Get Information Perform Computations Display Results

8 Second-Level Refinement Update checkbook Get Information Perform Computations Display Results Get Starting Balance Get Transaction Type Get Transaction Amount

9 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

10 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

11 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

12 Design Receives the results of analysis Describes how a module accomplishes its solution Concern is with logic

13 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

14 Design: Pseudocode for the Top-Level Task 1. Get information 2. Perform computations 3. Display results

15 Second-Level Refinement 1. Get information 1.1 get starting balance 1.2 get transaction type 1.3 get transaction amount 2. Perform computations 2.1 if deposit then add amount to balance else subtract amount from balance 3. Display results 3.1 display starting balance 3.2 display transaction type 3.3 display ending balance

16 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

17 Steps in Coding Edit the program Compile the program Run the program Syntax errors Run-time and logic errors

18 The Parts of a C++ Program Preprocessor directives (to include libraries) Main function –data declarations –program statements

19 Program Comments // Program file: chbook.cpp // This program updates a checkbook. Not executable, but describes the task of the program for the reader.

20 Preprocessor Directives // Program file: chbook.cpp // This program updates a checkbook. #include Ask the compiler to include library code for the program. These libraries contain code for input and output operations.

21 The main Function // Program file: chbook.cpp // This program updates a checkbook. #include int main() { return 0; } This program actually does nothing, but well include the code for the checkbook program shortly.

22 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.

23 Declare Data Variables int main() { double startingBalance, endingBalance, transAmount; char transType; C++ is case sensitive. TransType is a different name than transType. Use names that describe roles of data in the program.

24 Code the Module for Getting Data int main() { double startingBalance, endingBalance, transAmount; char transType; // Module for getting the data. cout : "; cin >> startingBalance; cout << "Enter the transaction type (D) deposit or (W) withdrawal "; cout : "; cin >> transType; cout : "; cin >> transAmount; Dont worry about understanding all these statements; we will cover them in detail shortly.

25 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;

26 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; }

27 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)


Download ppt "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."

Similar presentations


Ads by Google