We are working with Cambridge Assessment International Education towards endorsement of this title. Any references or material related to answers, grades, papers or examinations are based on the opinion of the author(s). 2 Algorithms
SUMMARY An algorithm consists of a series of actions. An algorithm uses logic constructs to define the order in which the algorithm actions are performed. The three logic constructs are: sequence, selection and iteration. Structured English can be used to define an initial design for an algorithm.
LE
Structured English contains brief statements, not full sentences.
The final stage of the design process should be the creation of a detailed design.
There should be sufficient detail in a detailed design to allow program code to be written. A detailed design for an algorithm can be presented as pseudocode or as a flowchart.
Pseudocode uses code components similar to ones used in a programming language and can be read and understood by programmers of any programming language.
P
A flowchart is a diagram which shows the order in which actions are performed in the algorithm.
END-OF-CHAPTER QUESTIONS
M
1 Give definitions for the following terms: i an algorithm ii a logic construct iii sequence iv selection v iteration. 2 State what the following flowchart symbols are used for:
S
A
3 Consider the following scenario: A shopkeeper needs a program to calculate the total bill for items bought by a customer. The program is to work as follows: • The following will be repeated for each different item bought: 1 The price for one item will be input. 2 The number of that type of item bought will then be input. 3 The price will be calculated for the number bought of this item. 4 This price will be added to a running total.
• The total price to pay will be output. For example, if you were to buy five pencils and some other items: 1 The price of one pencil will be input. 2 The input for the number of pencils bought will be 5. 3 The price for these five pencils will be calculated. 4 That price is added to a running total. Construct a flowchart for this program. You can use Structured English to label the symbols.
15 Original material © Cambridge University Press 2021. This material is not final and is subject to further changes prior to publication.