CHTP5e 03-Structured Program
CHTP5e 03-Structured Program
3
Structured Program
Development in C
2
OBJECTIVES
In this chapter you will learn:
Basic problem-solving techniques.
To develop algorithms through the process of
top-down, stepwise refinement.
To use the if selection statement and if...else
selection statement to select actions.
To use the while repetition statement to execute
statements in a program repeatedly.
Counter-controlled repetition and sentinel-controlled
repetition.
Structured programming.
The increment, decrement and assignment operators.
3
3.1 Introduction
3.2 Algorithms
3.3 Pseudocode
3.4 Control Structures
3.5 The if Selection Statement
3.6 The if...else Selection Statement
3.7 The while Repetition Statement
3.8 Formulating Algorithms: Case Study 1
(Counter-Controlled Repetition)
3.9 Formulating Algorithms with Top-Down, Stepwise
Refinement: Case Study 2 (Sentinel-Controlled
Repetition)
3.10 Formulating Algorithms with Top-Down, Stepwise
Refinement: Case Study 3 (Nested Control Structures)
3.11 Assignment Operators
3.12 Increment and Decrement Operators
4
3.1 Introduction
Before writing a program:
– Have a thorough understanding of the problem
– Carefully plan an approach for solving it
While writing a program:
– Know what “building blocks” are available
– Use good programming principles
5
3.2 Algorithms
Computing problems
– All can be solved by executing a series of actions in a
specific order
Algorithm: procedure in terms of
– Actions to be executed
– The order in which these actions are to be executed
Program control
– Specify order in which statements are to be executed
6
3.3 Pseudocode
Pseudocode
– Artificial, informal language that helps us develop
algorithms
– Similar to everyday English
– Not actually executed on computers
– Helps us “think out” a program before writing it
- Easy to convert into a corresponding C++ program
- Consists only of executable statements
7
Enter grade: 98
Enter grade: 76
Enter grade: 71
Enter grade: 87
Enter grade: 83
Enter grade: 90
Enter grade: 57
Enter grade: 79
Enter grade: 82
Enter grade: 94
Class average is 81
34
5
6
6
65