Chapter 3
Chapter 3
in the development of a solution to a problem processing, and output for a solution of a problem for the solution of a problem
external documentation
Pseudocode Flowchart
IPO Chart
The Input-Process-Output chart also known as
the IPO chart extends and organizes the information in the problem analysis.
outputs, and the processing steps required to transform the inputs into the outputs.
IPO Chart
The INPUT section contains all input data to be
IPO Chart
Has Three
IPO Chart for Payroll Problem Input processing 1.Prompt and Get pay_rate 2. Calculate pay 3. Print pay Output
pay_rate
pay
4. End
times does the heart beat in a lifetime of 78 years? (use 365.25 for days in a year). Write a program that can calculate the total heart beats as the heart rate (beat per minute) and the lifetime are provided by user.
IPO chart
INPUT heart_rate lifetime PROCESS 1. 2. 3. 4. Prompt and get for heart_rate Prompt and get for lifetime Calculate total_heart_beat Display total_heart_beat to the screen 5. End OUTPUT total_heart_beat
in a tax rate (as a percentage) and the prices of three items. The program is to calculate the total price, before tax, of the items, then the tax payable on those items. The tax payable is calculated by applying the tax rate percentage to the total price. Print the total price and the tax payable as output. IPO chart
INPUT taxrate item1 item2 item3 PROCESS OUTPUT
1. Prompt for taxrate, item1, item2, totalprice item3 taxpayable 2. Get taxrate, item1, item2, item3 3. Calculate totalprice, taxpayable 4. Display totalprice, taxpayable 5. End
Algorithm
Algorithm
Representation of algorithm:
A.Pseudocode B.Flowcharts
Pseudocode
Pseudocode
Algorithm in simple English (All statements are
written in simple English). Each instruction is written on a separate line. Keywords and instructions is written from top to bottom, with only one entry and one exit. Groups of statements may be formed into modules, and that group given a name. (optional)
Pseudocode
Remember all the keywords for six basic computer operations?
Pseudocode
One : A computer can receive information
Pseudocode
Two : a computer can put out information
Pseudocode
Three : a computer can perform arithmetic
Pseudocode
Four: A computer can assign a value to a variable or memory location
Set student_count to 0
total_price = cost_price Store customer_num in last_customer_num
Pseudocode
Five: A computer can compare two variables and select one of two alternate actions
IF student_attendance_status = part_time THEN add 1 to part_time_status ELSE
add 1 to full_time_count
ENDIF
Pseudocode
Six: A computer can repeat a group of actions
DOWHILE student_total < 50
Read student_record
Print student_name, Add 1 to student_total ENDDO
Pseudocode
Example
A Program is required to prompt the terminal operator for the maximum and minimum temperature readings on a particular day, accept those readings as integers, and calculate and display to the screen the average temperature, calculated by (maximum temperature + minimum temperature)/2 IPO Chart Input max_temp min_temp Process 1.Prompt for max_temp, min_temp 2.Get max_temp, min_temp 3.Calculate avg_temp 4.Display avg_temp 5.End Output avg_temp
Pseudocode
FIND_AVERAGE_TEMPERATURE
Prompt operator for max_temp, min_temp Get max_temp, min_temp
Pseudocode example
If a human heart beats on the average of once a second, how many
times does the heart beat in a lifetime of 78 years? (use 365.25 for days in a year). Write a program that can calculate the total heart beats as the heart rate (beat per minute) and the lifetime are provided by user.
FIND_TOTAL_HEART_BEAT Prompt and Get for heart_rate Prompt and Get for lifetime total_heart_beat = lifetime * heart_rate * 60 * 24 * 365.25 Display total_heart_beat to screen END
FIND_TOTAL_HEART_BEAT Prompt and Get for heart_rate Prompt and Get for lifetime total_heart_beat = lifetime * heart_rate * 60 * 24 * 365 Display total_heart_beat to screen END
in a tax rate (as a percentage) and the prices of three items. The program is to calculate the total price before tax of the items, then the tax payable on those items. The tax payable is calculated by applying the tax rate percentage to the total price. Print the total price and the tax payable as output. IPO chart
INPUT taxrate item1 item2 item3 PROCESS 1. Prompt for taxrate, item1, item2, item3 2. Get taxrate, item1, item2, item3 3. Calculate totalprice, taxpayable 4. Display totalprice, taxpayable 5. End OUTPUT totalprice taxpayable
Flow Chart
Flow Chart
FIND_AVERAGE_TEMPERATURE
Prompt and Get for max_temp Prompt and Get for min_temp avg_temp = (max_temp + min_temp)/2 Display avg_temp to the screen END
Flowchart example
FIND_TOTAL_HEART_BEAT Prompt and Get for heart_rate Prompt and Get for lifetime total_heart_beat = lifetime * heart_rate * 60 * 24 * 365.25 Display total_heart_beat to screen END
Start
Stop
Designing Solutions
Using Logic Structure (Structured Theorem) Assist programmer in writing effective error free programs. Possible by write the computer program by using Three control structures
processing step after another Next slide flowchart representation of sequence control structure
Statemement b
Statemement c
Statemement a
Statemement b
Case Structure
Case Of variable
Value 1 Value 2 Value 3 Value 4
Statement_a
Statement_b
Statement_c
Statement_d
3. Repetition
Defined as the presentation of a set of instruction to
be performed repeatedly Block of statement is executed again and again until a terminating condition occurs
Three loop structure : FOR WHILE DO-WHILE
prefix
condition
FOR Loop
statement
update
stop
condition update T
WHILE Loop
statement T
stop
DO-WHILE Loop
statement update F Condition
T stop
to explain what is being done in the program. Necessary so that program can be easily understood by another programmer External documentation Manuals or help menus written about the solutions. For users of program
Internal documentation
Extra Exercise 1
A program is required to read from the screen the length and width of a rectangular house block, and the length and width of the rectangular house that has been built on the block. The algorithm should then compute and display the mowing time required to cut the grass around the house, at the rate of 2 square meters per minute. Design the IPO chart and construct pseudocode and flowchart for this program.