Chapter 3 (The Program Development Cycle)

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Example 3.10 Comparing Pseudocode and Flowcharts

1 Main module 2 Declare ItemName As String 3 Declare OriginalPrice As Float 4 Declare DiscountRate As Float 5 Declare SalePrice As Float 6 Declare TotalPrice As Float 7 Write "Sale Price Program" 8 Write "This program computes the total price, including tax, of an item that has been discounted a certain percentage." 9 Call Input Data module 10 Call Perform Calculations module 11 Call Output Results module 12 End Program 13 Input Data module 14 Write "What is the item's name?" 15 Input ItemName 16 Write "What is its price and the percentage discounted?" 17 Input OriginalPrice 18 Input DiscountRate 19 End Input Data Module 20 Perform Calculations module 21 Declare AmountSaved As Float 22 Set AmountSaved = OriginalPrice * (DiscountRate/100) 23 Set SalePrice = OriginalPrice - AmountSaved 24 Set Tax = SalePrice * .065 25 Set TotalPrice = SalePrice + Tax 26 End Perform Calculations Module 27 Output Results module 28 Write "The item is: " + ItemName 29 Write "Pre-sale price was: " + OriginalPrice 30 Write "Percentage discounted was: " + DiscountRate + "%" 31 Write "Sale price: " + SalePrice 32 Write "Sales tax: " + Tax 33 Write "Total: $" + TotalPrice 34 End Output Results Module

3.1 Name the four fundamental phases of the program development cycle.

1.) Analyze the Problem 2.) Design the Program 3.) Code the Program 4.) Test The Program

3.2 In one sentence each, describe what takes place during each phase of the program development cycle.

1.) Analyze the Problem - First, we must analyze the given problem, which means that we will study it until we fully understand it. 2.) Design the Program - The design process often uncovers flaws or inadequacies in the analysis of the problem and may necessitate a return to this phase. 3.) Code the Program - In coding the program certain problems may be encountered that may lead to the need for modifications or additions to the program design. 4.) Test The Program - The final testing phase, which can last for months for complex programs, inevitably uncovers problems with the coding, design, and analysis phases.

External documentation serves two purposes. This is listed as follows:

1.) Documentation found in a user's guide or an on-screen help system provides information about the program for its end users—people who will apply the software at work or in their everyday lives. 2.) Documentation found in a program maintenance manual provides information about how the program code accomplishes its purposes. This kind of external documentation is written for the benefit of programmers who may have to modify the software in the future to correct bugs or add features.

alpha testing

An attempt by the firm to determine whether a product will perform according to its design and whether it satisfies the need for which it was intended; occurs in the firm's research and development (R&D) department.

Program Development Process

Analyze the Problem Design the Program Code the Program Test The Program

runtime error

Failure to predict some input data that may lead to an illegal operation (such as division by zero) when the program is run

modular programming

Identifying the tasks and various subtasks involved in the program design is called modular programming

infinite loop

If an algorithm doesn't terminate it called an infinite loop - not an algorithm

Code the Program

In coding the program certain problems may be encountered that may lead to the need for modifications or additions to the program design.

Input/Output

Input/Output steps are represented as parallelograms. In the Sale Price program, input steps are those that require the user to input the name of an item, its original price, and how much the item is discounted. Displaying the results of the computations, including the item's name, its sale price, the tax, and the new price, are examples of output steps.

Processing

Processing steps are represented as rectangles. For example, doing a calculation such as computing the sale price of an item, the sales tax of an item, or the total new price (from the Sale Price problem) are examples of processing steps.

Declare

Recall that this statement defines a variable and sets its data type.

Example 3.5 Pseudocode for the Sale Price Program (#3 Refine pseudocode)

The following is the refined pseudocode for the input and output modules: Input Data module Write "What is the item's name?" Input ItemName Write "What is its price and the percentage discounted?" Input OriginalPrice Input DiscountRate Output Results module Write "The item is: " + ItemName Write "Pre-sale price was: " + OriginalPrice Write "Percentage discounted was: " + DiscountRate + "%" Write "Sale price: " + SalePrice Write "Sales tax: " + Tax Write "Total: $" + TotalPrice

Example 3.5 Pseudocode for the Sale Price Program (#1 initial pseudocode)

The initial pseudocode for the Sale Price program might look as follows: Input Data module Input ItemName, OriginalPrice, DiscountRate Perform Calculations module Compute SalePrice Compute TotalPrice Output Results module Output the input data and TotalPrice

Testing

The program ensures that it is free of errors and that it does indeed solve the given problem. The final testing phase, which can last for months for complex programs, inevitably uncovers problems with the coding, design, and analysis phases.

syntax

The ways that specific words and symbols are used by each language

submodules

Then if needed, we can break each of these fundamental "high-level" tasks into subtasks. The latter are called submodules of the original, or parent, module.

Example 3.5 Pseudocode for the Sale Price Program (#2 Refine pseudocode)

Then, we refine and add detail to each module, which gives us the following version of the pseudocode: Input Data module Prompt for ItemName, OriginalPrice, DiscountRate Input ItemName, OriginalPrice, DiscountRate Perform Calculations module Set AmountSaved = OriginalPrice * (DiscountRate/100) Set SalePrice = OriginalPrice - AmountSaved Set Tax = SalePrice * .065 Set TotalPrice = SalePrice + Tax Output Results module Write ItemName Write OriginalPrice Write DiscountRate Write SalePrice Write Tax Write TotalPrice

The following are a few kinds of logic errors:

Use of an incorrect formula to produce a desired result Use of an incorrect sequence of statements to carry out an algorithm Failure to predict some input data that may lead to an illegal operation (such as division by zero) when the program is run—this kind of bug is sometimes called a runtime error

Set

When a Set (assignment) statement is executed, the expression on the right of the equals sign is evaluated and assigned to the variable on the left.

Design

a program means to create a detailed description, using relatively ordinary language or special diagrams of the program to be created. The design process often uncovers flaws or inadequacies in the analysis of the problem and may necessitate a return to this phase. For example, the design phase can be broken into two major parts. 1.) Create an outline of the program so that it is apparent what major tasks and subtasks have to be accomplished and the relationships among these tasks. 2.) Describe in detail how each of these tasks is to be carried out.

Step comments

also referred to as in-line comments Step comments appear throughout the program to explain the purpose of specific portions of code.

user's guide

and on-screen help documents are usually written once the program development cycle is well underway, often when the software is undergoing alpha or beta testing.

Connectors

are represented as circles. These are used to connect one program segment to another.

sequential structure

consists of a series of consecutive statements, executed in the order in which they appear.

Input

determining what information (input) is needed to produce these results

Internal documentation

exists within the code and explains it

Design documentation

focuses more on the why than the how. In design documentation, the programmer might explain the rationale behind why certain data was organized in a particular way or why certain methods were used.

code

his is where we translate the pseudocode of the design into the corresponding statements in a particular programming language.

Output

identifying the desired results (output)

test data

input to test the program

user interface

is a collection of displays, menus, and other features that provide an efficient way for the user to input data and view results.

design phase of the program development cycle

is often the most important aspect of developing a program, especially in the case of complex problems.

syntax error

is the violation of the programming language's rules for creating valid statements.

beta test

limited release of a product, especially an innovative technology, to allow usage and feedback from a small number of customers who are willing to test the product under normal, everyday conditions of use

Note

main program, and all other modules are known as (depending upon the programming language) subprograms, procedures, subroutines, and/or functions.

logic error

results from failing to use the proper combination of statements to accomplish a certain task. It may occur due to faulty analysis, faulty design, or failure to code the program properly.

Pseudocode

uses short, English-like phrases to describe the outline of a program.

desk-checking

walking through a program

Header comments

which appear at the beginning of a program or a program module, provide general information about that program or module.

External documentation

is provided separate from the program in a user's guide or maintenance manual.

comment

is text inserted into the program for explanatory purposes but ignored by the computer when the program is run.

Program Development Cycle

it provides a framework for creating a suitable program to solve a given problem

maintenance manual

may contain several different topics that pertain to the software and that are helpful to programming experts.

debug

means we must locate and eliminate the errors

The three fundamental tasks that we must perform to solve this problem are as follows:

1.) Input Data 2.) Perform calculations 3.) Output results

Benefits of Modular Programming

1.) The program is easier to read. This in turn, reduces the time needed to locate errors in a program or make modifications to it. 2.) It's easier to design, code, and test the program one module at a time rather than all at once. This increases the productivity of the programmer or programmers involved in a project. 3.) Different program modules can be designed and/or coded by different programmers. This feature is essential when creating large, complex programs. 4.) In some cases a single module can be used in more than one place in the program. This reduces the amount of code in the program. 5.) Modules performing common programming tasks (such as sorting data in order) can be used in more than one program. Creating a library of such modules reduces design, coding, and testing time.

The three basic types of control structures are as follows:

1.) The sequential (or sequence) structure 2.) The decision (or selection) structure 3.) The loop (or repetition) structure

Thus, the flow of execution in this program proceeds as follows:

1.) The statement Call Input Data module is executed, transferring control to the first statement in the Input Data module. 2.) All statements in the Input Data module are executed and then control transfers to the next statement (Call Perform Calculations module) in the Main module, which transfers control to the first statement in the Perform Calculations module. 3.) After the last statement in Perform Calculations is executed, control transfers to the statement Call Output Results module in the Main module, which in turn transfers control to the first statement in the Output Results module. 4.) After the last statement in Output Results is executed, control transfers to the End Program statement in the Main module and execution terminates.

Steps To Writing a Great Modular Program (Programming Styles)

1.) Use Descriptive Variable Names. 2.) Provide a Welcome Message for the User. 3.) Use a Prompt Before an Input. 4.) Identify Program Output 5.) Document Your Programs

Program module

A good way to begin the job of designing a program to solve a particular problem is to identify the major tasks that the program must accomplish.

However, we can provide some general guidelines by listing the following characteristics of a program module:

A module performs a single task. For example, an input module prompts for and then inputs data from the user. A module is self-contained and independent of other modules. A module is relatively short. Ideally, its statements should not exceed one page. This makes it easier to understand the way the module works.

technical writer

A person who creates technical documentation and user guides for a professional field.

program

A program is a list of instructions that a computer does in sequence.

internal documentation

All programs should include annotation that explains the purpose of portions of code within the program itself. This kind of annotation is known as internal documentation and is made up of comments.

Algorithm

An algorithm is like a recipe. It is a step-by-step method for solving a problem or doing a task. an algorithm used in a computer program must be well defined and well ordered, with no gap in instructions. programming algorithm must contain clear, unambiguous, step-by-step instructions.

time-honored strategy for solving problems

Completely understand the problem Devise a plan to solve it Carry out the plan Review the results

To put a commercial program, produced by a software publishing company, into production may entail any or all of the following:

Creating a user's guide to accompany the software so that users can understand the intricacies of the program Creating comprehensive help files that are installed with the software so that users can obtain on-screen help as problems arise Training employees to provide telephone or web-based customer support for the software Duplicating thousands of disks and accompanying materials for distribution to retailers or directly to users Advertising the program to attract buyers

Note

Herman Goldstine, one of the original developers of ENIAC, first developed flowcharts with John von Neumann at Princeton University in the late 1946 and early 1947.

3.3 Indicate whether each of the following statements is true or false.

If you completely understand a given problem, you should skip the design phase of the program development cycle. (FALSE) Program design provides an outline for the program code. (TRUE) Testing a program is only necessary for very complex programs.(FALSE)

Trade study documentation

It is a comparison document, which focuses on one specific aspect of the system and suggests alternate approaches.It might outline what the situation is, describe alternatives, and explain the pros and cons of each. Good trade study documentation is heavy on research, expresses its idea clearly, and is impartial. A trade study is an attempt to find the best solution, rather than to push one point of view. It should be prepared as a scientific document and not as a marketing technique.

Echo printing

Printing the data values input to a program to make sure they are correct It's a good programming practice because it reminds the user what data has been entered and allows the user to check it for mistakes.

programing styles

The elements of a program that affect its readability and ease of use are grouped together under the general heading of programming style.

Example 3.5 Pseudocode for the Sale Price Program (#5 Refine pseudocode)

The following example uses the Declare statement extensively. Recall that this statement defines a variable and sets its data type. 1 Main module 2 Declare ItemName As String 3 Declare OriginalPrice As Float 4 Declare DiscountRate As Float 5 Declare SalePrice As Float 6 Declare TotalPrice As Float 7 Write "Sale Price Program" 8 Write "This program computes the total price, including tax, of an item that has been discounted a certain percentage." 9 Call Input Data module 10 Call Perform Calculations module 11 Call Output Results module 12 End Program 13 Input Data module 14 Write "What is the item's name?" 15 Input ItemName 16 Write "What is its price and the percentage discounted?" 17 Input OriginalPrice 18 Input DiscountRate 19 End Input Data Module 20 Perform Calculations module 21 Declare AmountSaved As Float 22 Set AmountSaved = OriginalPrice * (DiscountRate/100) 23 Set SalePrice = OriginalPrice - AmountSaved 24 Set Tax = SalePrice * .065 25 Set TotalPrice = SalePrice + Tax 26 End Perform Calculations Module 27 Output Results module 28 Write "The item is: " + ItemName 29 Write "Pre-sale price was: " + OriginalPrice 30 Write "Percentage discounted was: " + DiscountRate + "%" 31 Write "Sale price: " + SalePrice 32 Write "Sales tax: " + Tax 33 Write "Total: $" + TotalPrice 34 End Output Results Module

Example 3.5 Pseudocode for the Sale Price Program (#4 Refine pseudocode)

The main module(function) has to call these submodules. Thus, it takes the following form: Main module Call Input Data module Call Perform Calculations module Call Output Results module End Program

driver

The main module(function) may also be called the driver.

cycle

implies that you may have to repeat previous steps, perhaps over and over, until the program works correctly.

Structured programming

is a method used to design and code programs in a systematic and organized manner.

Testing (or checking) should take place throughout the development process.

This is means: When analyzing the problem, continually ask yourself questions: Have I interpreted the known data correctly? Have I used the correct formulas or procedures for what I'm trying to accomplish? Have I fulfilled the program requirements? And so on. In the design phase, imagine that you are the computer and run through the algorithm using simple input data to see if you get the expected results. This is sometimes referred to as desk-checking or walking through a program. While you are coding the program, the programming language software may do some checking to verify that each statement has the proper syntax, and you are alerted if a statement has not been properly phrased.

control structures

To help create a well-structured program design, each module should consist of a series of properly organized groups of statements known as control structures

documentation

is a way to provide additional explanation in plain English that the computer ignores but which makes it easier for others to understand the program code.

Write

When a Write statement is executed, the text in quotation marks (if any) and the values of the listed variables (if any) are displayed on the screen and the cursor moves to the beginning of the next line.

Input

When an Input statement is executed, program execution pauses to allow the user to enter data (numbers or characters) from the keyboard. This data is assigned to the listed variables.

The Value of Modular Programming

When we first begin to write programs, they are normally short and simple. For most beginning programs, we do not break up the code into modules. As programs become longer and more complex, using modules (or subprograms, procedures, subroutines, or functions, as they may be called) becomes much more important.

call statement

causes a submodule to be executed.

Processing

figuring out what must be done to proceed from the known data to the desired output (processing).

Conditional (or decision or selection)

segments are represented as diamond shapes. These typically contain a Yes/No question or a True/False test. This symbol has two arrows coming out of it. One arrow corresponds to what happens in the program if the answer to the question is Yes or True, and the other arrow corresponds to what happens next if the answer to the question is No or False. The arrows should always be labeled.

Arrows

show the flow of control. An arrow coming from one symbol and ending at another symbol represents that control passes to the symbol to which the arrow points.

Program Code

that is, you must write statements (instructions) in a particular programming language such as Visual Basic, C++, or JavaScript to put the design into a usable form.

decision structure (also known as a selection structure)

there is a branch forward at some point, which causes a portion of the program to be skipped. Thus, depending upon a given condition at the branch point, a certain block of statements will be executed while another is skipped.

hierarchy chart

which describes these relationships in the same way that an organization chart determines who is responsible to whom in a business firm

Flowchart

which is a diagram that uses special symbols to display pictorially the flow of execution within a program or a program module.

main module

which is where program execution begins and normally ends. The main module is the only program module that is not a submodule of another, and it is the parent module of the program's highest-level modules—those that perform the most fundamental of tasks.

analyze

you determine what the result will be. First, we must analyze the given problem, which means that we will study it until we fully understand it. To a large extent, this step entails acquiring all the necessary facts about the problem. In doing so, we ask ourselves the following important questions: 1.) What results are we trying to obtain—what is the required output? 2.) What data needs to be given—what is the necessary input? 3.) How will we obtain the required output from the given input?


Kaugnay na mga set ng pag-aaral

Texas Pre-License- Real Estate Finance

View Set