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 Lecture: Algorithms, Flowcharts, and Pseudo-codes, Lecture notes of Calculus for Engineers

A lecture note from ENG 224, Structured Programming course. It covers the basics of algorithms, flowcharts, and pseudo-codes. how to write algorithms using pseudo-code and find the average of a given set of numbers using flowcharts. It also introduces the systematic approach to defining a problem and explains top-down and bottom-up design approaches.

Typology: Lecture notes

2019/2020

Uploaded on 01/29/2020

doireann-a
doireann-a 🇨🇦

4 documents

1 / 28

Toggle sidebar

Related documents


Partial preview of the text

Download Structured Programming Lecture: Algorithms, Flowcharts, and Pseudo-codes and more Lecture notes Calculus for Engineers in PDF only on Docsity! Lecture 2 ENG 224 STRUCTURED PROGRAMMING Overview • Algorithm • Flowchart • Pseudo-codes • A Systematic Approach to Defining a Problem • Top-down design • Bottom-up design • State Diagrams • Modular Designs Find the average of a given set of numbers with flowcharts Pseudo code Definition Pseudo code is one of the tools that can be used to write a preliminary plan that can be developed into a computer program. Pseudo code is a generic way of describing an algorithm without use of any specific programming language syntax. How to write An algorithm can be written in pseudo code using six (6) basic computer operations: How to write Pseudo code • A computer can receive information. Typical pseudo code instructions to receive information are: Read name, Get name, Read number1, number2 • A computer can output (print) information. Typical pseudo code instructions are: Print name Write "The average is", ave • A computer can perform arithmetic operation Typical pseudo code instructions: Add number to total, or Total = Total + Number Ave = sum/total Algorithm Average This algorithm reads a list of numbers and computes their average. Let: SUM be the total of the numbers read COUNTER be the number of items in the list AVE be the average of all the numbers Set SUM to 0, Set COUNTER to 0. (i.e. initialize variables) While there is data do: Read number COUNTER = COUNTER + 1 (i.e. add 1 to COUNTER, storing result in COUNTER) SUM = SUM + number (i.e. add number to SUM, storing result in SUM) end-while if COUNTER = 0 then AVE = 0 else AVE = SUM/ COUNTER Stop. A Systematic Approach to Defining a Problem • Defining the problem is the first step towards a problem solution. A systematic approach to problem definition, leads to a good understanding of the problem. Here is a tried and tested method for defining (or specifying) any given problem: Divide the problem into three (3) separate components: (a) input or source data provided (b) output or end result required (c)processing - a list of what actions are to be performed • PROBLEM EXAMPLE 2: A program is required to read three (3) numbers, add them and print their total. PROBLEM SOLUTION 2 INPUT Read : Num1, Num2, Num3 PROCESSING Total = Num1 + Num2 + Num3 OUTPUT Print : Total Advantages of the Top-Down Design Method -It is easier to comprehend the solution of a smaller and less complicated problem than to grasp the solution of a large and complex problem. -It is easier to test segments of solutions, rather than the entire solution at once. This method allows one to test the solution of each sub-problem separately until the entire solution has been tested. -It is often possible to simplify the logical steps of each sub-problem, so that when taken as a whole, the entire solution has less complex logic and hence easier to develop. -A simplified solution takes less time to develop and will be more readable. -The program will be easier to maintain. Bottom Up Design Approach (Modularization) • In Bottom-up programming, functions without writing or knowing how they will be used. Typically, this will be a module. The theory is that by writing blocks of program that interact with other program we would have created program building blocks that can be used in many programs. Feature Bottom-up Approach • Bottom-up is hard to code. • This method is complicated because it's not easy to formulate simple problems and end up with a global problem. • It is result oriented State Diagram Algorithm • Draw circles to represent the states given. • For each of the states, scan across the corresponding row and draw an arrow to the destination state(s). There can be multiple arrows for an input character. • Designate a state as the START STATE. • Designate one or more states as ACCEPT STATE. This is also given in the formal definition. State Diagram l 1 RNA Explanation • From the state transition table given above, it is easy to see that if the machine is in S1 and the next input is character 1, the machine will stay in S1. If a character 0 arrives, the machine will transition to S2 as can be seen from the second column. In the diagram this is denoted by the arrow from S1 to S2 labelled with a 0. Merits of Modular Programming • Several smaller modules are built and usually compiled separately so that, when composed together, they construct the executable application program. • More reusable modules than a traditional monolithic design. • Facilitates the "breaking down" of projects (through "divide and conquer") into several smaller projects. Thank You For Your Attention! Note • Pre-Lecture 3 Requirements – Visual Studio 2008 – Visual basic 6 – Eclipse C++ Helios SR2 and Eclipse SDK – Lecture Venue – Laptops • Assignment 1 – State Machine, Pseudo Code and Flowchart
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved