Professional Documents
Culture Documents
C++ Programming
Developing Algorithms &
Flow Charts
Part 1
Introduction
Software is developed with programming
languages
Before programming, it is necessary to:
understand the problem and its elementary
components
determine what functionality each component
must embody
how the components logically fit together to
accomplish the task at hand.
2
Programming
Classic Life Cycle
Design an Algorithm
An algorithm is not a solution but a process
to obtain a solution
Divide the problem into subproblems.
Design an algorithm for each subproblem.
Check the correctness of each algorithm
Can test using sample data
Some mathematical analysis might be
required
4
Design an Algorithm
Two common methods for designing an
algorithm [program logic]
1. Pseudo-code a non standardized
language to define the sequence of steps
to obtain the solution to the problem.
2. Flowcharts a standardized set of
symbols to visually describe the logical
steps required to arrive at the solution to
the problem.
8
End of Part 1
11
Design an Algorithm
Flowcharting
A set of standard symbols used to describe
the variety of operations and interactions of
a logical set of steps.
Text within and accompanying the symbols
define the precise action to be taken.
The direction of flow is indicated by the use
of arrows.
Flowchart Symbols
13
Design an Algorithm
Flowcharting
Benefits:
The logic is visual you can see the flow
Standard logical structures are clearly identifiable
Can be drawn free-hand
Governed by standard rules
Disadvantages:
Governed by standard rules
May require software for formal documentation
14
Design an Algorithm
A Simple Problem
Design an Algorithm
Pseudo-code
Algorithm to Calculate Bathroom Flooring Cost
1.
2.
3.
4.
5.
6.
7.
8.
9.
Design an Algorithm
Flowchart
Flow Chart to Calculate Bathroom Flooring Cost
Start
Get [number]
of bathrooms
and [budget]
amount
{ Do Loop }
Get material
[price]
Display over
budget
message
[count] = 0
[total area] = 0
Total [cost] =
total area x price
{ While Loop }
count <
number
Total cost
> budget
T
Get [length]
and [width]
Display OK
to proceed
message
Stop
17
End of Part 2
18
In-Class Lab #1
Design an algorithm to perform the following task:
Obtain a number from the user
Calculate and display the square of the number
Repeat the process until the square of the number is 0
Submit the pseudo-code via the WebStudy In-Class
Lab assignment Lab 01 in the Assignments tab.
19
Assignment #1
Design an algorithm to meet the following specifications:
Calculate and display the sales bonus for the entered sales amount.
Prompt the user and get the sales amount.
Calculate and display the bonus amount as follows:
If the dollar value of the sales amount is less than 25000, the bonus is
1% of the sales amount otherwise the bonus is 5% of the sales amount
Display the bonus amount.
Ask the user if another salesmans bonus is to be calculated.
If the response is Y[es] repeat the process for the next salesman; if N[o],
end the program.
Name the file: SalesBonus
Submit a pseudo-code document via the WebStudy Assignment
Assignment #1 in the Assignments tab.
20