Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Structured Programming: Problem Solving, Algorithm Development, and Implementation, Lecture notes of Differential and Integral Calculus

An overview of structured programming, focusing on the problem-solving and implementation phases. It introduces the concept of algorithms, their properties, and the challenges in writing them. The document also covers the development and understanding of algorithms using flowcharts and a problem example.

What you will learn

  • What are the basic control structures in structured programming?
  • What is the role of flowcharts in understanding algorithms?
  • What are the two main phases of programming according to structured programming?
  • What are the steps involved in the problem-solving phase?
  • How do you develop an algorithm?

Typology: Lecture notes

2019/2020

Uploaded on 01/29/2020

doireann-a
doireann-a 🇨🇦

4 documents

1 / 17

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lecture 1
ENG 224
STRUCTURED PROGRAMMING
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Structured Programming: Problem Solving, Algorithm Development, and Implementation and more Lecture notes Differential and Integral Calculus in PDF only on Docsity!

Lecture 1

ENG 224

STRUCTURED PROGRAMMING

PROBLEM SOLVING & PROGRAM

DESIGN

Two phases involved in the design of any program: (i) Problem Solving Phase (ii) Implementation Phase

  1. In the problem-solving phase the following steps are carried out: Define the problem Outline the solution Develop the outline into an algorithm Test the algorithm for correctness
  2. The implementation phase comprises the following steps: Code the algorithm using a specific programming language Run the program on the computer Document and maintain the program

ALGORITHMS

  • An algorithm is a sequence of precise instructions for solving a problem in a finite amount of time.

e.g. preparing a meal or student daily routine

Properties of an Algorithm:

  • It must be precise and unambiguous
  • It must give the correct solution in all cases
  • It must eventually end.

Algorithms and Humans

Algorithms are not a natural way of stating a problem’s solution, because we do not normally state our plan of action.

  • We tend to execute as we think about the problem. Hence, there areinherent difficulties when writing an algorithm.
  • We normally tailor our plans of action to the particular problem at handand not to a general problem (i.e. a nearsighted approach to problem solving)
  • We usually do not write out our plan, because we are usually unaware ofthe basic ideas we use to formulate the plan. We hardly think about it – we just do it.
  • Computer programmers need to adopt a scientific approach to problem solving, i.e. writing algorithms that are comprehensive and precise.
  • We need to be aware of the assumptions we make and of the initialconditions.
  • Be careful not to overlook a step in the procedure just because it seems obvious.
  • Remember, machines do not have judgment, intuition or common sense!

Understanding the Algorithm

Possibly the simplest and easiest method to understand the steps in analgorithm, is by using the flowchart method. This algorithm is composed of block symbols to represent each step in the solution process as well as the directed paths of each step. The most common block symbols are:

  • Start/Stop
  • Decision
  • Process
  • Connector
  • Input/output
  • Flow Direction

There are many other block symbols, used in flow charting, but for the purposes of this course, we will restrict our usage to the symbols described above. They are sufficientto illustrate the steps in developing solutions to the simple problems we will be dealing with.

Problem Example 1

(i) Find the average of a given set of numbers.

  1. Develop a plan:

Make note of what you did in steps (i) through (iv), but how you did it. In doing so,

you will begin to develop the algorithm.

e.g. How do we count the numbers?

  • Starting at 0 i.e. set COUNTER to 0
  • Look at 1st number, add 1 to COUNTER
  • Look at 2nd number, add 1 to COUNTER

and so on , until you reach the end of the list

How do we add numbers?

  • Let SUM be the sum of numbers in list. Set SUM to 0
  • Look at 1st number, add number to SUM
  • Look at 2nd number, add number to SUM
  • and so on, until we reach end of list

How do we compute the average?

  • Let AVE be the average then AVE = total sum of items/number of items i.e. SUM / COUNTER
  1. Carry out the plan Check each step Consider special cases Check result Check boundary conditions: i.e. what if the list is empty? Division by 0? Are all numbers within the specified range? In this example, no range is specified - No special cases. Check result by tracing the algorithm with a list of numbers e.g. 7, 12, 1, 5,13.

If list is empty, we do not want to compute average.

Therefore, before calculating AVE, check if COUNTER = 0

i.e. If COUNTER = 0 then AVE = 0 else AVE = SUM/COUNTER

  1. The Algorithmic Language During development of an algorithm, the language gradually progresses from English towards a programming language notation. An intermediate notation called pseudo- code is commonly used to express algorithms.

Algorithmic Structure Every algorithm should have the following sections, in the stated order:

  • Header : Algorithm’s name or title.
  • Declaration : A brief description of algorithm and variables. i.e. a statement of the purpose.
  • Body : Sequence of steps
  • Terminator : End statement

Note

  • Once the problem has been properly defined, making sure that no assumptions are made and every action required is stated in the Processing column, we can proceed to develop the algorithm. To do this, simply focus on the actions in the processing column, then write down the steps that specify how to perform each action and in what sequence