IDENTIFY WAYS OF REPRESENTING ALGORITHMS.

Similar documents
FLOW CHART AND PSEUDO CODE

Introduction to Flowcharting

ALGORITHMS AND FLOWCHARTS

Problem Solving Footer Text 10/30/2015 1

PSEUDOCODE AND FLOWCHARTS. Introduction to Programming

BIL101E: Introduction to Computers and Information systems Lecture 8

CSC 121 Spring 2017 Howard Rosenthal

Chapter Two: Program Design Process and Logic

CS 199 Computer Programming. Spring 2018 Lecture 2 Problem Solving

CHAPTER 2 PROBLEM SOLVING TECHNIQUES. Mr Mohd Hatta Bin Hj Mohamed Ali Computer Programming BFC2042

Pseudo Code and Flow Charts. Chapter 1 Lesson 2

An Introduction to Programming with C++ Sixth Edition. Chapter 2 Beginning the Problem-Solving Process

IT 1033: Fundamentals of Programming Loops

Chapter 1: Problem Solving Skills Introduction to Programming GENG 200

Computer System and programming in C

depicts pictorially schematic representation of an algorithm document algorithms. used in designing or documenting

UNDERSTANDING PROBLEMS AND HOW TO SOLVE THEM BY USING COMPUTERS

Chapter 4: Making Decisions

Class 8 ALGORITHMS AND FLOWCHARTS. The City School

1. The first step that programmers follow when they solve problems is to plan the algorithm.

Programming Logic and Design Sixth Edition

Computer Programming ECIV 2303 Chapter 6 Programming in MATLAB Instructor: Dr. Talal Skaik Islamic University of Gaza Faculty of Engineering

Com S 127x - Lab 6 1. READING FLOWCHARTS WITH CONDITIONAL ACTIONS!

SIF8035. Events and System Requirements

ENG 101 Lesson -21. neater and more readable flowchart is needed, the latter

(I m not printing out these notes! Take your own.)


Problem Solving FLOWCHART. by Noor Azida Binti Sahabudin Faculty of Computer Systems & Software Engineering

SNS COLLEGE OF ENGINEERING

BRANCHING if-else statements

Pseudocode. ARITHMETIC OPERATORS: In pseudocode arithmetic operators are used to perform arithmetic operations. These operators are listed below:

Engineering program development. Edited by Péter Vass

Method & Tools for Program Analysis & Design

Final Examination Semester 2 / Year 2010

4*4*4 2. What is the output of the following flowchart for the values given below: (25 p)

Fundamental of Programming (C)

Fundamentals of Programming

PROBLEM SOLVING AND OFFICE AUTOMATION. A Program consists of a series of instruction that a computer processes to perform the required operation.

CENTRAL SUSQUEHANNA INTERMEDIATE UNIT Application: Payroll

The sequence of steps to be performed in order to solve a problem by the computer is known as an algorithm.

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

The Further Mathematics Support Programme

SNS COLLEGE OF ENGINEERING,

FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING UNIT III. 2 Marks PROBLEM SOLVING AND OFFICE AUTOMATION

Flow Chart & Algorithms

Review. Input, Processing and Output. Review. Review. Designing a Program. Typical Software Development cycle. Bonita Sharif

CSC 1051 Data Structures and Algorithms I

Chapter 2: Input, Processing, and Output

Chapter 4: Programming with MATLAB

Chapter 1: An Overview of Computers and Logic

CS111: PROGRAMMING LANGUAGE1. Lecture 2: Algorithmic Problem Solving

UNIT-3 PROBLEM SOLVING AND OFFICE AUTOMATION

5. Selection: If and Switch Controls

Introduction to Computer Programming/Handout 01 Page 1 of 13

SOFTWARE ANALYSIS & DESIGN TOOLS

Conditional Programming

(4-2) Selection Structures in C H&K Chapter 4. Instructor - Andrew S. O Fallon CptS 121 (September 12, 2018) Washington State University

Slide 1. Slide 2. Slide 3. General Problem-Solving. Find the Weight of the Block. General_Problem_Solving_slides.docx 9/7/07 MET 107

Objectives. Chapter 4: Control Structures I (Selection) Objectives (cont d.) Control Structures. Control Structures (cont d.) Relational Operators

1. Introduction to Programming

Computers Programming Course 6. Iulian Năstac


REPRESENTING ALGORITHMS. REPRESENTING ALGORITHMS IB DP Computer science Standard Level ICS3U

Chapter 2. Designing a Program. Input, Processing, and Output Fall 2016, CSUS. Chapter 2.1

Microsoft Visual Basic 2012: Reloaded

Mill Hill School. 13+ Entrance Examination Mathematics. January Time: 1 hour. School: Mark: Materials required for examination

An Introduction to Computer Problem Solving and the Programming Process

بسم اهلل الرمحن الرحيم

Microsoft Visual Basic 2005: Reloaded

Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

PROBLEM SOLVING AND PYTHON PROGRAMMING

Chapter 4: Control Structures I (Selection) Objectives. Objectives (cont d.) Control Structures. Control Structures (cont d.

Skill Area 306: Develop and Implement Computer Program

Software Development. Designing Software

Programming Logic - Beginning

Programming Logic Beginning

Chapter 4: Control Structures I (Selection)

Chapter 5 Conditional and Iterative Statements. Statement are the instructions given to the computer to perform any kind of action.

Procedural Programming

DECISION STRUCTURES: USING IF STATEMENTS IN JAVA

Procedural Programming

Problem Solving and Algorithms

Year 6 Term 1 and

Oral and Mental calculation

Number- Algebra. Problem solving Statistics Investigations

Introduction to Computer Science Unit 2. Notes

Algorithms. Abdelghani Bellaachia, CSCI 1121 Page: 1

Introduction to Programming

Lecture 9. Monday, January 31 CS 205 Programming for the Sciences - Lecture 9 1

LOOPS. 1- Write a program that prompts user to enter an integer N and determines and prints the sum of cubes from 5 to N (i.e. sum of 5 3 to N 3 ).

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

C++ Programming: From Problem Analysis to Program Design, Fourth Edition. Chapter 4: Control Structures I (Selection)

INTENDED LEARNING OUTCOMES

Java and Software Design

Problem Solving with Decisions. T.Fatin Alhila

Command-line interface DOS Graphical User interface (GUI) -- Windows

Selection. Chapter 6. Figure 6.1 The relational operators. = Equal to. < Less than. <= Less than or equal to. > Greater than

ITSE 1411 Beg. Web Programming

conditional statements

PROGRAM DESIGN TOOLS. Algorithms, Flow Charts, Pseudo codes and Decision Tables. Designed by Parul Khurana, LIECA.

Transcription:

IDENTIFY WAYS OF REPRESENTING ALGORITHMS.

OBJECTIVES: Identify ways of representing algorithms: Content Representation of algorithms as Pseudocode or Flowcharts; use of flow chart symbols: input/output process,decision,directional arrows. Use of: Read, Input, Store, Write, Output, Display, If Then; If Then Else; For loop; While loop (Questions which require nested conditionals or nested loops will not be asked)

THE ALGORITHMIC LANGUAGE During the development of an algorithm, the language gradually progresses from English towards a notation that resembles that of a programming language. An intermediate notation called pseudocode is commonly used to express algorithms. Algorithms can also be expressed as flowcharts. A flowchart is a pictorial representation of an algorithm.

Pseudocode Acceptable words for Input/Output in pseudocode: INPUT Get Accept Input Read OUTPUT Display Print Output

Flowcharts Flowcharts use special geometrical objects to designate steps of a program, which are : input, processing and output. A parallelogram is used to represent the input operation as well as the output operation, and a rectangle is used to represent a processing/assignment statement. A diamond is used to represent a decision (If Then Else) structure. An elliptical shape is used to represent the terminal indicators, START OR STOP. Directional arrows is used to indicate the flow of the logic in the algorithm.

Flowcharts Basic Shapes The four basic shapes are: Input/Output Processing/Assignment Decision Start/Stop

Sequence Below are examples of how the various control structures are depicted in a flowchart: Sequence A Do A B Do B

Selection (The If Then Else Construct) No C Yes If C is true then do E Else do D D E

Loop (Repetition) Loop F Yes G No While F is true do G

Pseudocode Version of the Average Algorithm Read Num, Num, Num Average = (Num Num Num Print Average Stop.

Flowchart version of the Average Algorithm Start Read Num, Num, Num Aver = (Num +Num +Num Print Aver Stop

Problem 10 Design an algorithm that accepts two values, the hourly rate and the number of hours worked by an employee. If the number of hours exceeds 40 then the excess hours should be paid at an overtime rate of twice the hourly rate. Calculate the wages (including overtime, if any) due to the employee.

Solution The first step is to define the solution as follows: INPUT PROCESSING OUTPUT Rate, HoursWorked 1) Calculate overtime pay if any 2) Calculate wages Wages

Solution Step 2 Possible Pseudocode version of the algorithm: This algorithm calculates the wages due to an employee. Read Rate, HoursWorked BasicPay = Rate * OvertimeHours = HoursWorked If (OvertimeHours > ) then Wages = BasicPay + (OvertimeHours * Else Wages = Rate * HoursWorked EndIf Print Wages Stop. * Rate)

Flowchart Version of the Wages Problem Start Read Rate, Hours worked BasicPay = HoursWorked *40 OvertimeHours= HoursWorked - 40 Wages = BasicPay + (OvertimeHours* 2 * Rate) Yes Overtime Hours> 0 No Wages = HoursWorked * Rate Print Wages Stop

Comparison/Selection/Decision Statements It sometimes becomes necessary when processing data to compare the value of a variable to the value of another variable or to compare the value of a variable to that of a constant. The following Relational Operators are used to make such comparisons: Relational Operator Meaning = Equal to <> Not equal to > Greater than < Less than > = Greater than or equal to < = Less than or equal to

Comparison/Selection/Decision Statements A Condition is an expression that when evaluated gives either a True or a False. This expression is called a Boolean expression. These conditions use the relational operators between two variables or between a variable and a constant. Examples: Boys in Class > = 35 NumberOfBoys <> NumberOfGirls

Boolean Operators When selection or decisions is based upon one or more expressions being True or False, it is possible to combine the expressions together using Boolean Operators AND or OR. If the AND operator is used both conditions must be met in order for the total expression to be true. If the OR expression is used either condition must be met in order for the total expression to be true.

Example of the AND Operator A club plays cricket only on Sundays and only if it is not raining. Write an algorithm to accept the day and weather and print Game on if it is a suitable day for playing. What happens with each of the two operators. Solution: Input Day, Weather If (Day= Sunday ) And (Weather= No Rain ) Then Print Game ON EndIF Stop If either condition is not met Game On would not be printed

Example of the OR Operator If we had used the or operator instead then the algorithm would read as follows: Input Day, Weather If (Day= Sunday ) OR (Weather= No Rain ) Then Print Game ON EndIF Stop If either condition is met Game On would be printed. That would mean that Game On would be printed If it is Sunday or on any other day of the week once there is no rain.

Question 1 Write an algorithm to enter the base and height of a triangle and find and print the area. Write a pseudocode version and a flowchart version of the solution.

Pseudocode version Algorithm AreaTriangle This algorithm accepts values for the Base and Height of a triangle and Prints the area. Read Base, Height Area = (Base * Height)/2 Print Area Stop.

Flowchart Version Start Read Base, Height Area = (Base * Height)/2 Print Area Stop

Question 2 Write an algorithm to enter a number, double the number and output the result. Write a pseudocode version and a flowchart version of the solution.

Pseudocode version Algorithm Double This algorithm accepts a number and doubles it and outputs the result. Read Num Double = Num * 2 Print Double Stop.

Flowchart Version Start Read Num Double = Num * 2 Print Double Stop

Question 3 Persons under 18 are not allowed in at Shutters Night Club.Write an algorithm to read a person s age and if it is under 18 the algorithm should output Underage person. If the person is 18 years or over the algorithm should output Person allowed. Write a pseudocode version and a flowchart version of the solution.

Pseudocode version Algorithm Shutters This algorithm checks a person s age and check to see if they are allowed in the night club. If (Age < 18) Then Print Underage Person Else Print Person Allowed EndIf Stop.

Flowchart Version Start Read Age No If (Age < 18) Then Yes Print Person Allowed Print Underage Person Stop

Question 4 Write a program to input a number N. If the number is greater than 50 subtract 10 from the number, otherwise multiply the number by 2 and add 5. Print the number and the result.

Pseudocode version Algorithm Number N This algorithm accepts a number N manipulates it and prints the result. Read N If (N > 50) Then N = N-10 Else N = N * 2 N = N + 5 EndIf Print N Stop.

Flowchart Version Start Read N No If (N > 50) Then Yes N = N * 2 N = N + 5 N = N - 10 Print N Stop