28
ICS124 Session 8 Structured Programming 1

ICS124 Session 8 Structured Programming 1. By the end of this section the student will be able to: List the steps of a model Systems Development Life

Embed Size (px)

Citation preview

ICS124

Session 8

Structured Programming

1

By the end of this section the student will be able to:

List the steps of a model Systems Development Life Cycle Describe the purpose of each of the model steps List the steps of a model Program Development Cycle Describe the purpose of each step of the Program Development Cycle Name which columns of an IPO Chart contain verbs and which contain nouns Represent a word problem in an IPO Chart

2

Structured Programming

BackgroundAs systems become more complex, and businesses become more reliant on computers, means to structure the way new software is delivered is needed. There are two aspects that will be discussed:

System Development Life Cycle Program Development Cycle

The Program Development Cycle is a subset of the System Development Life Cycle.

The following slides will provide an overview of SDLC and PDC. The section on PDC will be investigated closer for the remainder of the course.

3

Structured Programming, continued

System Development Life CycleThe steps of the System Development Life Cycle are:

Analyze System Define System Requirements Design New System Develop New System Accept New System Implement System

These steps are guidelines, and are not cast in stone. Each company will have some variation of these steps. There may be more steps, or some steps will be combined.

4

Structured Programming, continued

SDLC: Analyze System

Performed on existing manual systems as well as existing automated systemsPerformed by System AnalystMost effectively performed by interviewing the usersIdentify what is done, and howIdentify any problems with current systemGo-NoGo Decision based on ROI estimates

5

Structured Programming, continued

SDLC: Define System Requirements

What changes are required System Analyst works with Business Analyst Develop 'look and feel' of new system Determine what needs to be done (not how) Every input, output and process is documented:

Output: reports, screen designs Input: what data, where does it come from Process:what activities are required to produce the output

Go-NoGo Decision

6

Structured Programming, continued

SDLC: Design New System

Define all programs, files, databases, manual processes System Flowcharts are a common tool

Like a program flowchart Major inputs Major outputs Inter-relationships between entities in system

No details as to how the programs work

7

Structured Programming, continued

SDLC: Develop New System

Involves designing, coding and unit-testing Uses Program Development Cycle Goal is high-quality well structured programs Main focus of the remainder of this course

8

Structured Programming, continued

SDLC: Accept New System

Performed by Business user or Representative who has intimate knowledge of Business functionality of the system

Entire system is tested to ensure it conforms to the System Requirements (Phase 2)

Assumes no knowledge of internal workings of system System documentation reviewed Implementation strategies discussed Users trained

9

Structured Programming, continued

SDLC: Implement New System

When the new system is implemented into the production environment Evaluation of new system (comparison between the expected objectives and

the actual results) Results of the evaluation may become the input to a subsequent SDLC

10

Structured Programming, continued

Program Development CycleThe steps of the Program Development Cycle are:

Define the Problem Outline the Solution Develop the Solution into an Algorithm Test the Algorithm for Correctness Code the Program into a Specific Language (C) Run the Program on the Computer Document and Maintain the Program

These steps are guidelines, and are not cast in stone. Each company will have some variation of these steps. There may be more steps, or some steps will be combined.

11

Structured Programming, continued

PDC: Define the Problem

Must have a clear understanding of the problem There is no room for assumptions There is no difference between solving the wrong problem correctly and

solving the right problem incorrectly To help with analysis, the problem should be broken into:

Inputs Outputs Processes

IPO Charts to be discussed later today

12

Structured Programming, continued

PDC: Outline the Solution

Break problem into smaller tasks or steps Create a rough draft of the solution, may include

Major processing steps Major sub-tasks (if any) Major control structures (repetition loops) Major variables and record structures Mainline logic of the program

Top-down design Modularity and Hierarchy charts are tools discussed outside of this class

13

Structured Programming, continued

PDC: Develop the Outline into an Algorithm

Computers cannot devise a plan or decide to act Computers can only do what they are told, exactly the way they are told Computers do what you tell them to do, not what you want them to do An algorithm is a set of precise instructions which describe the task to be

performed and the order in which they are to be carried out’ Flowcharts and Pseudocode to be discussed next week

14

Structured Programming, continued

PDC: Test the Algorithm for Correctness

One of the most important steps Identifies major logic errors Walkthroughs are a technique for testing Test plans are outside the scope of this class

15

Structured Programming, continued

PDC: Code the Program

Performed only after previous design considerations have been complete In this course the C language will be used, although these techniques can be

used for any language (Fortran, COBOL, BASIC, Pascal, Turing, TAL...) Unfortunately, this is where many people begin PDC or SDLC

16

Structured Programming, continued

PDC: Run the Program

Most will find this the most rewarding step This step involves the compiler, which will identify syntax errors and some

basic coding/logic errors Further testing takes place against a Test Plan Can be very frustrating if the design and testing is incomplete before the

coding is performed May need to be performed several times

17

Structured Programming, continued

PDC: Document and Maintain Program

Documentation is an ongoing task throughout the PDC External Documentation Internal Documentation Maintenance takes place during the life of the program, due to:

Enhancements (new functionality, new requirements) Bugs

18

Structured Programming, continued

IPO Charts

Step 1 of the Program Development Cycle referred to a tool called an IPO Chart. It is also known as a Defining Diagram. IPO is an acronym for Input Process Output. It is a technique to break a problem down into one of these three categories using a chart such as:

The entries in the Input and Output columns are nouns. A distinct, singular item. The entries in the Process column are verbs. A specific, singular action.

There are cases when the input and output processes can be summarized into one process statement.

Input Process Output

19

Structured Programming, continued

IPO Charts, continued

Example:Develop a program to accept three numbers, add them together, then print their total and average.

What would an IPO Chart look like?

Input Process Output

20

Structured Programming, continued

IPO Charts, continued

Example:Develop a program to accept three numbers, add them together, then print their total and average.

What would an IPO Chart look like?

Input Process Outputvalue1 read the input values averagevalue2 add the numbers togethertotalvalue3 calculate average

display averagedisplay total

21

Structured Programming, continued

IPO Charts, continued

Why is the following chart wrong?

Input Process Output3 numbers read 3 numbers (n1 + n2+ n3) / 3

compute average and total n1 + n2 + n3Print average and total

22

Structured Programming, continued

IPO Charts, continued

Example:

Develop a program that displays the area and perimeter of a triangle when only two sides are given. The two sides will be 'a' and 'b' from the diagram below.

c2 = a2 + b2

area = 0.5 x (a x b)

What would an IPO Chart look like?

a

b

c

23

Structured Programming, continued

IPO Charts, continued

Example:

Develop a program that displays the area and perimeter of a triangle when only two sides are given. The two sides will be 'a' and 'b' from the diagram below.

c2 = a2 + b2

area = 0.5 x (a x b)

What would an IPO Chart look like?

Input Process OutputsideA read sideA, sideB values perimetersideB calculate side C area

calculate perimetercalculate areaprint perimeterprint area

24

Structured Programming, continued

IPO Charts, continued

Example:In order to determine the maximum range available to an aircraft flying a specific direction, the fuel on board becomes the limiting factor. While flying the assigned heading, the aircraft may experience a headwind or a tailwind. Headwinds will be indicated by negative numbers, tailwinds by positive numbers.

The cruise performance chart for the aircraft provides the airspeed and rate of fuel consumption for various altitudes and power settings. The pilot is responsible for selecting the altitude & power setting from the performance chart. Based on the values selected by the pilot from the cruise performance chart, calculate and display the actual speed of the aircraft over the ground and the maximum range of the aircraft. For maximum range, the aircraft is permitted to expend all but 15% of the starting fuel capacity.

Ground speed = Cruise airspeed + windTime aloft = (0.85 * fuel) / rate of consumptionMaximum range = Ground Speed * Time aloft

25

Structured Programming, continued

IPO Charts, continued

Example:

In order to determine the maximum range available to an aircraft flying a specific direction, the fuel on board becomes the limiting factor. While flying the assigned heading, the aircraft may experience a headwind or a tailwind. Headwinds will be indicated by negative numbers, tailwinds by positive numbers.

The cruise performance chart for the aircraft provides the airspeed and rate of fuel consumption for various altitudes and power settings. The pilot is responsible for selecting the altitude & power setting from the performance chart. Based on the values selected by the pilot from the cruise performance chart, calculate and display the actual speed of the aircraft over the ground and the maximum range of the aircraft. For maximum range, the aircraft is permitted to expend all but 15% of the starting fuel capacity.

Input Process Outputfuel on board read input values ground speedrate of fuel consumption calculate groundspeed maximum rangewind calculate time aloftcruise airspeed calculate maximum range

print ground speedprint maximum range

26

Structured Programming, continued

IPO Charts, continued

Example:

Calculate the gross pay and net pay for an employee. Display each deduction, total deduction, gross pay and net pay for the employee. Overtime is calculated at 1.5 times the normal rate for hours worked in excess of 44 hours/week. Long term benefits are charged at $2.00 per every full $100.00 of gross weekly earnings to a maximum payment of $100.00 per week. Unemployment insurance is 1.3% of gross pay to a maximum of $11.40 per week. Canada Pension Plan is 1.6% of gross pay on all earnings below $700 per week. Federal tax is calculated at 17% on the first $20,000 earned annually, 23% on the next $20,000 earned annually and 29% on the remainder. Provincial tax which is calculated with the Federal tax is 49% of Federal tax collected.

27

Structured Programming, continued

IPO Charts, continued

Input Process Outputpay rate read input values gross payhours worked calculate normal work week pay net pay

calculate overtime benefits deductioncalculate gross pay UI deductioncalculate benefits deduction CPP deductioncalculate UI deduction Federal tax deductioncalculate CPP deduction Provincial tax deductioncalculate Federal tax deduction total deductionscalculate Provincial tax deductiontotal all deductionscalculate net payprint gross pay, net pay, benefits,print UI, CPP, Fed tax, Prov Tax,print total deductions

28