Date post: | 25-Sep-2015 |
Category: |
Documents |
Upload: | farahazura |
View: | 224 times |
Download: | 0 times |
UNIT 2: PROBLEM ANALYSIS AND
DESIGN Algorithm, Flowchart, Pseudocode
and Analyse Problem
1. Defining and analyzing problems identify and understand what the problems to resolve are
the problems must be clearly define 3 element of problem analysis :- input, process, output
2. Planning of variables variables are simply references to memory locations a well plan use of variables will produce an efficient
execution of program in terms of speed and memory utilization
STAGE INVOLVED IN PROBLEM SOLVING
3. Design tools 3 types of design tools i) Flowchart ii) pseudo code
4. Program Writing the program should be clear and readable through an
orderly
4. Testing and Debug Once the program has been written it must be compiled and executed. This is accomplished by an editor and compiler. An editor lets us type a program, makes changes and save it to a file. The compiler then translates the program into a form that the computer can read. Once the program has been compiled and executed the presence of errors will be readily apparent.
5. Documentation Program must be documented for future references and maintenance process.
ELEMENTS OF PROBLEMS ANALYSIS
INPUT
A set of information called data that entered into the computer from keyboard, floppy disk, hard disk etc. and stored in a portion of the computer memory.
This input which is an input to the computer will then be processed to produce the desired result.
PROCESS
Sequence of interdependent and linked procedures which, at every stage, consume one or more resources to convert inputs into outputs.
These outputs then serve as inputs for the next stage until a known goal or end result is reached.
OUTPUT
The processed data which produced certain result is
known as the output.
The output data will be presented in a sheet of paper through the printer or display on a monitor.
LETS DO AN EXERCISES:
Determine input, process and output for the given
problems.
1. A workers at TF Supermarket will be paid RM5 per
hour. Get the total hours working per day and total days working in a month from the user and calculate the gross pay for a month.
2. Students have to get at least 50 marks to PASS Fundamental Programming Subject. Calculate the average marks for the students. Their marks consist of two quizzes, one test and one assignment.
3) Calculate the area of rectangular.
4) Calculate total parking fee that customer
has to pay at SOGO shopping complex.
Given rate for parking is RM2 per hour.
Input : Total hours working per day
Total days working in a month
Process : Gross pay = RM5 x hours a day x days in a month
Output : Gross pay
Input : Marks for
a) Quiz 1
b) Quiz 2
c) Test 1
d) Assignment 1
Process : Average = (Quiz1 + Quiz 2 + Test 1 + Assg 1)/4
Output : Average
1. DEFINE & ANALYZE PROBLEM
2. PLANNING VARIABLES
3.PROGRAM DESIGN TOOLS
4. PROGRAM WRITING
5. PROGRAM TESTING & DEBUGGING
6. DOCUMENTATION
12
2 techniques
The Techniques To Develop C++ Programming
1. Flowcharts
2. Pseudo Code
STEP 3: PROGRAM DESIGN TOOLS
13
F L O W C H A R T
Graphic representation of algorithm is known as flowchart which consist of geometric
symbols.
These symbols are connected by line of arrows called flowlines which indicate the direction of
flow of processes or activities.
The shape of the symbol indicates the type of operation that is to occur.
Flowchart should flow from the top of the page to the bottom.
Symbol
Name
Meaning
Flowline
Used to connect symbols and
indicate the flow of logic
Terminal
Used to represent the
beginning (start) or the end
(End) of a task
Input/output
Used for input and output
operations, such as reading
and printing. The data to be
read or printed are describe
inside
14
Symbol
Name
Meaning
Processing
Used for arithmetic and data-
manipulation operations. The instruction
are listed inside the symbol
Decision
Used for any logic or comparison
operations. Unlike the input/output and
processing symbols, which have one entry
and one exit flowline, the decision symbol
has one entry and
two exit paths. The path chosen depends
on whether the answer to a question is
yes or no
Connector
Used to join different flowline
Offpage
connector
Used to indicate that the flow chart
continues to a second page
15
Symbol
Name
Meaning
Predefined Process
Used to represent a group of
statements that perform one
processing task.
Annotation
Used to provide additional
information about another
flowchart symbol
The main advantage of using a flowchart to plan a task is that it provides a pictorial representation of the task, which makes the logic easier to follow. We can clearly see each and every step and how it is connected to the next step. For example lets look at the discount sales program in the next page.
16
EXAMPLE:
1. A workers at TF Supermarket will be paid RM5
per hour. Get the total hours working per day
and total days working in a month from the user
and calculate the gross pay for a month.
Input : ______________________________
Process : _____________________________
Output : _____________________________
How many hours did you work?
START
Display message How many hours
did you work?
Read Hours
Display message How much do you get paid
per hour?
Read Pay Rate
Multiply Hours by Pay Rate. Store
result in Gross Pay.
Display Gross Pay
END
Variable Contents: Hours: ? Pay Rate: ? Gross Pay: ?
Output Operation
Stepping Through the Flowchart
How many hours did you work?
40
START
Display message How many hours
did you work?
Read Hours
Display message How much do you get paid
per hour?
Read Pay Rate
Multiply Hours by Pay Rate. Store
result in Gross Pay.
Display Gross Pay
END
Variable Contents: Hours: 40 Pay Rate: ? Gross Pay: ?
Input Operation
(User types 40)
Stepping Through the Flowchart
How much do you get paid per hour?
START
Display message How many hours did
you work?
Read Hours
Display message How much do you get paid per hour?
Read Pay Rate
Multiply Hours by Pay Rate. Store
result in Gross Pay.
Display Gross Pay
END
Variable Contents: Hours: 40 Pay Rate: ? Gross Pay: ?
Output Operation
Stepping Through the Flowchart
How much do you get paid per hour? 20
START
Display message How many hours
did you work?
Read Hours
Display message How much do you get paid per hour?
Read Pay Rate
Multiply Hours by Pay Rate. Store result
in Gross Pay.
Display Gross Pay
END
Variable Contents: Hours: 40 Pay Rate: 20 Gross Pay: ?
Input Operation
(User types 20)
Stepping Through the Flowchart
How much do you get paid
per hour?
START
Display message How many hours
did you work?
Read Hours
Display message How much do you get paid per hour?
Read Pay Rate
Multiply Hours by Pay Rate. Store
result in Gross Pay.
Display Gross Pay
END
Variable Contents: Hours: 40 Pay Rate: 20 Gross Pay: 800
Process: The product of 40 times 20 is stored in Gross Pay
Stepping Through the Flowchart
Your gross pay is 800
START
Display message How many hours
did you work?
Read Hours
Display message How much do you get paid per hour?
Read Pay Rate
Multiply Hours by Pay Rate. Store
result in Gross Pay.
Display Gross Pay
END
Variable Contents: Hours: 40 Pay Rate: 20 Gross Pay: 800
Output Operation
Stepping Through the Flowchart
PSEUDO CODE i) an
abbreviated version of
actual computer code
ii) geometric symbols used in flowcharts are replaced by English-like statements that outline the process
iii) allows programmer to
focus on the steps required
to solve a problem rather than on how to use computer
language.
Program: 1- Enter hours work - input 2- Enter rate paid per hour input 3. Gross pay=hour * pay rate - process 4. Display gross pay - output
DEBUGGED PROGRAMME SOURCES
CODE
SYNTAX ERROR
The most common error a programmer makes. Usually a miss spelled word.
A program will not compile until all syntax errors are corrected.
For interpreted languages however syntax errors cannot be detected until runtime and it is not necessarily simple to differentiate a syntax error from a semantic error.
RUN-TIME ERROR Run-time errors are errors that occur while your
program runs.
These typically occur when your program attempts an operation that is impossible to carry out.
LOGICAL ERROR These errors solely depend on the logical thinking of the programmer and are easy to detect if we follow the line of execution and determine why the program takes that path of execution.
SUMMARY
Design tools for problem solving:
Flowchart
Pseudo code
Various types of errors:
Syntax error
Run-time error
Logical Error
Element of problems analysis:
Input
Process
output
LETS DO AN EXCERCISES
Analyze the problem given, state all the possible variables and
develop a flowchart and pseudo code for each problems.
1. Students have to get at least 50 marks to PASS Fundamental Programming Subject. Calculate the average marks for the students. Their marks consist of two quizzes, one test and one assignment. Design a flowchart and pseudo-code.
Step 1 : Input : _______________________
Process: _____________________
Output: _______________________
Step 2 : List all posibble variables
___________________________________________
Step 3: Flowcahrt and pseudo-code
2) Write a flowchart and pseudo code to a program that will calculate the area of
rectangular.
Step 1 : Input : _______________________
Process: _____________________
Output: _______________________
Step 2 : List all posibble variables
___________________________________________
Step 3: Flowcahrt and pseudo-code
3) Calculate total parking fee that customer has to
pay at SOGO shopping complex. Given rate for
parking is RM2 per hour. Design the flowchart and
pseudo code for these program.
Step 1 : Input : _______________________
Process: _____________________
Output: _______________________
Step 2 : List all posibble variables
___________________________________________
Step 3: Flowcahrt and pseudo-code