PROG0101 Fundamentals of Programming PROG0101 FUNDAMENTALS OF PROGRAMMING. Chapter 3 Algorithms



Similar documents
Chapter One Introduction to Programming

Chapter 1 An Introduction to Computers and Problem Solving

Algorithm & Flowchart & Pseudo code. Staff Incharge: S.Sasirekha

Algorithms, Flowcharts & Program Design. ComPro

2 SYSTEM DESCRIPTION TECHNIQUES

Instructor Özgür ZEYDAN (PhD) CIV 112 Computer Programming

Computer Programming Lecturer: Dr. Laith Abdullah Mohammed

ALGORITHMS AND FLOWCHARTS

ALGORITHMS AND FLOWCHARTS. By Miss Reham Tufail

Flowchart Techniques

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Sources: On the Web: Slides will be available on:

Process / Operation Symbols

Flowcharting, pseudocoding, and process design

Notes on Algorithms, Pseudocode, and Flowcharts

Problem Solving Basics and Computer Programming

2. Capitalize initial keyword In the example above, READ and WRITE are in caps. There are just a few keywords we will use:

Chapter 2: Algorithm Discovery and Design. Invitation to Computer Science, C++ Version, Third Edition

Software development and programming. Software

POLYNOMIAL FUNCTIONS

EKT150 Introduction to Computer Programming. Wk1-Introduction to Computer and Computer Program

Chapter 13: Program Development and Programming Languages

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

KS3 Computing Group 1 Programme of Study hours per week

Pseudo code Tutorial and Exercises Teacher s Version

COMPUTER SCIENCE TRIPOS

Instructor Özgür ZEYDAN BEU Dept. of Enve. Eng. CIV 112 Computer Programming Lecture Notes (1)

Unit 1 Number Sense. In this unit, students will study repeating decimals, percents, fractions, decimals, and proportions.

Chapter 13: Program Development and Programming Languages

WESTMORELAND COUNTY PUBLIC SCHOOLS Integrated Instructional Pacing Guide and Checklist Computer Math

MONROE TOWNSHIP PUBLIC SCHOOLS WILLIAMSTOWN, NEW JERSEY. Computer Animation. Grade 8

CBA Fractions Student Sheet 1

Using Casio Graphics Calculators

EMC Publishing. Ontario Curriculum Computer and Information Science Grade 11

Prentice Hall Mathematics: Course Correlated to: Arizona Academic Standards for Mathematics (Grades 6)

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

CALCULATIONS & STATISTICS

Notes on Assembly Language

COWLEY COLLEGE & Area Vocational Technical School

Lab Experience 17. Programming Language Translation

Formulas, Functions and Charts

Chapter 3 Problem Solving

A flowchart is not a state machine

Visual Logic Instructions and Assignments

General Certificate of Education Advanced Subsidiary Examination June 2015

Specimen 2015 am/pm Time allowed: 1hr 30mins

SECTION 2 PROGRAMMING & DEVELOPMENT

An Introduction to Computer Science and Computer Organization Comp 150 Fall 2008

NUMBER SYSTEMS. William Stallings

Welcome to Basic Math Skills!

Vector storage and access; algorithms in GIS. This is lecture 6

COMPUTER PROGRAMMING DCSA 1303 SCHOOL OF SCIENCE AND TECHNOLOGY

what operations can it perform? how does it perform them? on what kind of data? where are instructions and data stored?

VB Controls and Events. Introduc)on. Program Planning and Flowcharts Visual Basic Visual basic Interface VB Controls CreaGng a Project

Programming and Software Development CTAG Alignments

PIC 10A. Lecture 7: Graphics II and intro to the if statement

Formal Languages and Automata Theory - Regular Expressions and Finite Automata -

MATLAB Programming. Problem 1: Sequential

Course MS10975A Introduction to Programming. Length: 5 Days

COMPUTER SCIENCE (5651) Test at a Glance

JavaScript: Control Statements I

Introduction. Appendix D Mathematical Induction D1

ChE-1800 H-2: Flowchart Diagrams (last updated January 13, 2013)

Lecture 2 Mathcad Basics

ALGEBRA. sequence, term, nth term, consecutive, rule, relationship, generate, predict, continue increase, decrease finite, infinite

ASSEMBLY PROGRAMMING ON A VIRTUAL COMPUTER

VHDL Test Bench Tutorial

Number Sense and Operations

IV. ALGEBRAIC CONCEPTS

Radius, Diameter, Circumference, π, Geometer s Sketchpad, and You! T. Scott Edge

Glencoe. correlated to SOUTH CAROLINA MATH CURRICULUM STANDARDS GRADE 6 3-3, , , 4-9

A Short Guide to Significant Figures

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Decimals and Percentages

Quality Improvement Works on Existing Processes

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

Developing Conceptual Understanding of Number. Set J: Perimeter and Area

Algebra Unit Plans. Grade 7. April Created By: Danielle Brown; Rosanna Gaudio; Lori Marano; Melissa Pino; Beth Orlando & Sherri Viotto

Introduction to Systems Analysis and Design

Fundamentals of Programming and Software Development Lesson Objectives

Computer Programming

This unit will lay the groundwork for later units where the students will extend this knowledge to quadratic and exponential functions.

I PUC - Computer Science. Practical s Syllabus. Contents

Chapter 4. Applying Linear Functions

To Evaluate an Algebraic Expression

Digital System Design Prof. D Roychoudhry Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Toothpick Squares: An Introduction to Formulas

Math Workshop October 2010 Fractions and Repeating Decimals

Algorithm and Flowchart Structured Programming 1

Chapter 4: Tools of Modern Systems Analysis

PROGRAMMABLE LOGIC CONTROLLERS Unit code: A/601/1625 QCF level: 4 Credit value: 15 OUTCOME 3 PART 1

Summary of the MARIE Assembly Language

WRITING PROOFS. Christopher Heil Georgia Institute of Technology

Using Rational Rose to Create Object-Oriented Diagrams

VISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0

Student Outcomes. Lesson Notes. Classwork. Exercises 1 3 (4 minutes)

Part I. The Picture class

7 Relations and Functions

GAP CLOSING. 2D Measurement. Intermediate / Senior Student Book

Transcription:

PROG0101 FUNDAMENTALS OF PROGRAMMING Chapter 3 1

Introduction to A sequence of instructions. A procedure or formula for solving a problem. It was created mathematician, Mohammed ibn-musa al-khwarizmi. Often used for calculation, data processing and programming. can be expressed in any language. 2

Topics Pseudocode Flowcharts 3

Introduction to for making things will often be divided into sections; the parts/components/ingredients (inputs) required to accomplish the task actions/steps/methods (processing) to produce the required outcome (output). For example to build a model car, the parts (inputs) are needed plus instructions on how to assemble the car (processing) and the result is the car (output). 4

Introduction to Two forms of Algorithm: Pseudocode Flow chart 5

Pseudocode Pseudocode (which means fake code, because its not really programming code) specifies the steps required to accomplish the task. Pseudocode is a type of structured English that is used to specify an algorithm. Pseudocode cannot be compiled nor executed, and there are no real formatting or syntax rules. 6

Pseudocode Example of Pseudocode: Ready and open subscriber file Get a record Do while more records If current subscriber subscription count is > 3 then Output the record Get another record end 7

Advantages of Pseudocode Reduced complexity. Increased flexibility. Ease of understanding. 8

Why is Pseudocode Necessary? The programming process is a complicated one. You must first understand the program specifications. Then you need to organize your thoughts and create the program. You must break the main tasks that must be accomplished into smaller ones in order to be able to eventually write fully developed code. Writing Pseudocode will save you time later during the construction & testing phase of a program's development. 9

How to Write Pseudocode Statements? There are six basic computer operations 1. A computer can receive information Read (information from a file) Get (information from the keyboard) 2. A computer can put out information Write (information to a file) Display (information to the screen) 10

How to Write Pseudocode Statements? There are six basic computer operations 3. A computer can perform arithmetic Use actual mathematical symbols or the words for the symbols Example: Add number to total Total = total + number +, -, *, / Calculate, Compute also used 11

How to Write Pseudocode Statements? There are six basic computer operations 4. A computer can assign a value to a piece of data 3 cases i. to give data an initial value Initialize, Set 12

How to Write Pseudocode Statements? There are six basic computer operations 4. A computer can assign a value to a piece of data 3 cases ii. to assign a value as a result of some processing = *x=5+y 13

How to Write Pseudocode Statements? There are six basic computer operations 4. A computer can assign a value to a piece of data 3 cases iii. to keep a piece of information for later use Save, Store 14

How to Write Pseudocode Statements? There are six basic computer operations 5. A computer can compare two piece of information and select one of two alternative actions IF condition THEN some action ELSE alternative action ENDIF 15

How to Write Pseudocode Statements? There are six basic computer operations 6. A computer can repeat a group of actions WHILE condition (is true) some action ENDWHILE FOR a number of times some action ENDFOR 16

Data Dictionaries The pseudo code by itself doesn't provide enough information to be able to write program code. Data Dictionaries are used to describe the data used in the Pseudo Code. The standard data types used in Pseudo Code are Integer, Double, String, Char and Boolean. 17

Data Dictionaries Name Data Type Description number1 Integer The first number to be added number2 Integer The second number to be added total Integer The total of number1 and number2 added together 18

Example 1: Program Specification: Write a program that obtains two integer numbers from the user. It will print out the sum of those numbers. Pseudocode: Prompt the user to enter the first integer Prompt the user to enter a second integer Compute the sum of the two user inputs Display an output prompt that explains the answer as the sum Display the result 19

Example 2: Finding average of any three numbers. We might usually specify the procedure of solving this problem as add the three numbers and divide by three. Here, Read (or Ask) and Write (or Say) are implied. However in an algorithm, these steps have to be made explicit. Thus a possible algorithm is: 20

Example 2: Step 1 Start Step 2 Read values of X, Y, Z Step 3 S = X + Y + Z Step 4 A = S / 3 Step 5 Write value of A Step 6 Stop 21

Example 2: Or you can write like this: Step 1 Start Step 2 Read values of X, Y, Z Step 3 S = X + Y + Z Step 4 A = S / 3 Step 5 Write value of A Step 6 Stop 22

Example 3: Finding square and cube. Step 1 Step 2 Step 3 Step 4 Step 5 Step 6 Start Read value of N S = N * N C = S * N Write values of S, C Stop 23

Example 4: Finding biggest of two numbers. Step 1 Step 2 Step 3 Step 4 Step 5 Start Read A, B If A > B, then BIG = A, otherwise BIG = B Write BIG Stop 24

Example 5: Calculate pay. Step 1 Step 2 Step 3 Step 4 Step 5 Step 6 Start Input hours Input rate pay = hours * rate Print pay End 25

Exercise: Write a Pseudocode for these problems. 1. S = (A + B + C) / Y 2. Convert from Celsius to Fahrenheit. 3. Area of Circle ( r 2 ) 4. Volume of Sphere ( r 3) 5. Average speed = (Multiply by 9, then divide by 5, then add 32 ) 4 3 Distance traveled Time taken 26

Flowchart A flowchart is a graphical representation of an algorithm. These flowcharts play a vital role in the programming of a problem and are quite helpful in understanding the logic of complicated and lengthy problems. Once the flowchart is drawn, it becomes easy to write the program in any high level language. 27

Flowchart A flowchart can therefore be used to: Define and analyze processes Build a step-by-step picture of the process for analysis, discussion, or communication Define, standardize or find areas for improvement in a process 28

Flowchart 29

Flowchart Symbols Start and end symbols Represented as lozenges, ovals or rounded rectangles Usually containing the word "Start" or "End", or another phrase signalling the start or end of a process, such as "submit enquiry" or "receive product". 30

Flowchart Symbols Arrows Showing what's called "flow of control" in computer science. An arrow coming from one symbol and ending at another symbol. Represents that control passes to the symbol the arrow points to. 31

Flowchart Symbols Processing steps Represented as rectangles. Examples: Add 1 to X"; "replace identified part"; "save changes" or similar. 32

Flowchart Symbols Input/Output Represented as a parallelogram. Examples: Get X from the user; display X. 33

Flowchart Symbols Conditional or decision Represented as a diamond (rhombus). These typically contain a Yes/No question or True/False test. 34

Flowchart Symbols Display Indicates a process flow step where information is displayed to a person (e.g., PC user, machine operator). 35

Rules for Flowchart 1. Every flow chart has a START symbol and a STOP symbol. 2. The flow of sequence is generally from the top of the page to the bottom of the page. This can vary with loops which need to flow back to an entry point. 3. Use arrow-heads on connectors where flow direction may not be obvious. 4. There is only one flow chart per page. 36

Rules for Flowchart 5. A page should have a page number and a title. 6. A flow chart on one page should not break and jump to another page 7. A flow chart should have no more than around 15 symbols (not including START and STOP). 37

Advantages of Using Flowcharts Communication: Flowcharts are better way of communicating the logic of a system to all concerned. Effective analysis: With the help of flowchart, problem can be analysed in more effective way. Proper documentation: Program flowcharts serve as a good program documentation, which is needed for various purposes. Efficient Coding: The flowcharts act as a guide or blueprint during the systems analysis and program development phase. 38

Advantages of Using Flowcharts Proper Debugging: The flowchart helps in debugging process. Efficient Program Maintenance: The maintenance of operating program becomes easy with the help of flowchart. It helps the programmer to put efforts more efficiently on that part. 39

Basic Control Structures Sequence Selection Loop 40

Basic Control Structures Sequence Steps that execute in sequence are represented by symbols that follow each other top to bottom or left to right. Top to bottom is the standard. 41

Basic Control Structures Sequence 42

Basic Control Structures Selection Once the condition is evaluated, the control flows into one of two paths. Once the conditional execution is finished, the flows rejoin before leaving the structure. 43

Basic Control Structures Selection 44

Basic Control Structures Loop Either the processing repeats or the control leaves the structure. Notice that the return line joins the entry line before the question. 45

Basic Control Structures Loop 46

Example 1: Algorithm: Input: two numbers x and y Output: the average of x and y Steps: 1. input x 2. input y 3. sum = x + y 4. average = sum /2 5. output average 47

Example 1: 48

Example 2: Draw a flowchart to find the largest of three numbers A, B, and C. 49

Example 2: 50