Algorithms and flow charts

Slides:



Advertisements
Similar presentations
CS 240 Computer Programming 1
Advertisements

CHAPTER 2 GC101 Program’s algorithm 1. COMMUNICATING WITH A COMPUTER  Programming languages bridge the gap between human thought processes and computer.
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
Algorithms and flow charts
Chapter 2- Visual Basic Schneider
Program Flow Charting How to tackle the beginning stage a program design.
Program Flow Charting How to tackle the beginning stage a program design.
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
1 Chapter 2 Problem Solving Techniques INTRODUCTION 2.2 PROBLEM SOLVING 2.3 USING COMPUTERS IN PROBLEM SOLVING : THE SOFTWARE DEVELOPMENT METHOD.
Chapter 3 Planning Your Solution
Review Algorithm Analysis Problem Solving Space Complexity
PRE-PROGRAMMING PHASE
ALGORITHMS AND FLOW CHARTS 1 Adapted from the slides Prepared by Department of Preparatory year Prepared by: lec. Ghader Kurdi.
Algorithm & Flowchart.
Chapter 1 Pseudocode & Flowcharts
ALGORITHMS AND FLOWCHARTS
Your Interactive Guide to the Digital World Discovering Computers 2012.
CS102 Introduction to Computer Programming
Programming Languages Lecture 12. What is Programming?  The process of telling the computer what to do  Also known as coding.
Introduction to Programming Lecture Number:. What is Programming Programming is to instruct the computer on what it has to do in a language that the computer.
สาขาวิชาเทคโนโลยี สารสนเทศ คณะเทคโนโลยีสารสนเทศ และการสื่อสาร.
PROGRAMMING LANGUAGES Prof. Lani Cantonjos. PROGRAM - set of step-by-step instructions that tells or directs the computer what to do. PROGRAMMING LANGUAGE.
TMF1013 : Introduction To Computing Lecture 1 : Fundamental of Computer ComputerFoudamentals.
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
Software Life Cycle What Requirements Gathering, Problem definition
Problem Solving Techniques. Compiler n Is a computer program whose purpose is to take a description of a desired program coded in a programming language.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
IXA 1234 : C++ PROGRAMMING CHAPTER 1. PROGRAMMING LANGUAGE Programming language is a computer program that can solve certain problem / task Keyword: Computer.
INTRODUCTION TO COMPUTING CHAPTER NO. 04. Programming Languages Program Algorithms and Pseudo Code Properties and Advantages of Algorithms Flowchart (Symbols.
Chapter 1 Introduction Chapter 1 Introduction 1 st Semester 2015 CSC 1101 Computer Programming-1.
Pseudocode. Simple Program Design, Fourth Edition Chapter 2 2 Objectives In this chapter you will be able to: Introduce common words, keywords, and meaningful.
The Programming Process Define the problem* Make or buy software? Design the program * Code (write) the program Test (debug) the program Document the.
Chapter 2: General Problem Solving Concepts
Basic Control Structures
CHAPTER 1 INTRODUCTION 1 st semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
PROGRAM DEVELOPMENT CYCLE. Problem Statement: Problem Statement help diagnose the situation so that your focus is on the problem, helpful tools at this.
1 Program Planning and Design Important stages before actual program is written.
Structured Programming (4 Credits)
Programming and Languages Dept. of Computer and Information Science IUPUI.
The Hashemite University Computer Engineering Department
LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that.
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
Flowchart. a diagram of the sequence of movements or actions of people or things involved in a complex system or activity. a graphical representation.
ALGORITHMS AND FLOWCHARTS. Why Algorithm is needed? 2 Computer Program ? Set of instructions to perform some specific task Is Program itself a Software.
STEP 3- DEVELOP AN ALGORITHM At this stage we break down the problem into simple manageable steps so that they can be handled easily.
Lecture #1: Introduction to Algorithms and Problem Solving Dr. Hmood Al-Dossari King Saud University Department of Computer Science 6 February 2012.
Evolution of C and C++ n C was developed by Dennis Ritchie at Bell Labs (early 1970s) as a systems programming language n C later evolved into a general-purpose.
PROGRAMMING FUNDAMENTALS INTRODUCTION TO PROGRAMMING. Computer Programming Concepts. Flowchart. Structured Programming Design. Implementation Documentation.
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
| MSC 8102:PROGRAMMING CONCEPTS By Vincent Omwenga, PhD. 1.
Flow Charts And Pseudo Codes Grade 12. An algorithm is a complete step-by- step procedure for solving a problem or accomplishing a task.
CHAPTER 2 GC101 Program’s algorithm 1. COMMUNICATING WITH A COMPUTER  Programming languages bridge the gap between human thought processes and computer.
Program design Program Design Process has 2 phases:
Programming Languages
Chapter One Problem Solving
Algorithm & Programming
ALGORITHMS AND FLOWCHARTS
Algorithms and Flowcharts
Introduction to Algorithm – part 1
ALGORITHMS AND FLOWCHARTS
Unit# 9: Computer Program Development
ALGORITHMS AND FLOWCHARTS
Chapter 2- Visual Basic Schneider
Introduction to Algorithms and Programming
Chapter 1 Introduction(1.1)
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING
Chapter 2- Visual Basic Schneider
Understanding Problems and how to Solve them by using Computers
Basic Concepts of Algorithm
Presentation transcript:

Algorithms and flow charts Ghader Kurdi Adapted from the slides Prepared by Department of Preparatory year

Prepared by Department of Preparatory year Programming language Programming language is an artificial language that specifies instruction to be executed on a computer. There are two types of programming languages: Low level languages High level languages Prepared by Department of Preparatory year

Prepared by Department of Preparatory year Computer Languages: The language which consists of a set of commands, understandable by computer directly or after translating, is known as computer programming language. Prepared by Department of Preparatory year

Prepared by Department of Preparatory year Computer Languages: There are many types of computer languages, which can be categorized into the following four types:- Low-Level Languages (1st & 2nd Generation Languages) High-Level Languages (3rd Generation Languages) User-Friendly Languages (4th Generation Languages) Object-Oriented Languages (5th Generation Languages) Prepared by Department of Preparatory year

Prepared by Department of Preparatory year Computer Languages: Low-Level Language: Languages, which computer can understand directly and are machine dependent are called Low-Level Languages. For Example: Machine Language & Assembly Language. Prepared by Department of Preparatory year

Prepared by Department of Preparatory year Low level languages A language that is machine-dependent and/or that offers few control instructions and data types. Each statement in a program written in a low-level language usually corresponds to one machine instruction. Prepared by Department of Preparatory year

Prepared by Department of Preparatory year Computer Languages: High-Level Language: The languages, which computer cannot understand directly and are not machine dependent are called High-Level Languages. Some of the high-level languages are:- BASIC (Beginners All Purpose Symbolic Instruction Code) COBOL (Common Business Oriented Language) FORTRAN (Formula Translator) C etc. Prepared by Department of Preparatory year

Prepared by Department of Preparatory year Computer Languages: User-Friendly Languages: These languages are very easy to codify and simplest to learn. Some of the common user-friendly languages are:- dBASE FoxPro Oracle MS Access Sybase etc. Prepared by Department of Preparatory year

Prepared by Department of Preparatory year Computer Languages: Object-Oriented Languages: The languages which are based on object oriented programming (OOP) approach are called as Object-Oriented languages. For example:- Smalltalk C++ Object COBOL JAVA Simula etc. Prepared by Department of Preparatory year

Language Translators: The software, which converts the codes of other languages into machine code are called Language Translator. Language Translators are categorized into three types:- Assemblers Interpreters Compilers Prepared by Department of Preparatory year

Language Translators: Assembler: Assembler translates the assembly language code (source program) into machine language code (object program). After assembling, a linker program is used to convert the object program into an executable program. The Microsoft assembler program (MASM) & Borland Turbo assembler program (TASM) are two popular assemblers. Assemblers are used mainly in development of system software. Prepared by Department of Preparatory year

Language Translators: Interpreters: Interpreters translate the high-level language code into machine language code, command by command. They are very slow for executing large programs, so interpreters are not suitable for most of applications development. Prepared by Department of Preparatory year

Language Translators: Compilers: As contrast to interpreters, compilers provide faster execution speed. Compilers translate the entire program (source code) into machine code (object code). By using linker, the object code is converted into executable code. Compilers are widely used in translating codes of high level languages. As compared to assemblers or interpreters, compilers are preferred in development of application software. Prepared by Department of Preparatory year

Main operation of high level language program Input operations: Like input, read Output operations; Like write, print Arithmetic operations: Like add, subtract, multiply etc.... control transferring operations: Like “GO TO”, conditional, non-conditional etc.... Looping: Like repeat, do while, for, etc... 4 Prepared by Department of Preparatory year

Main step in developing program Problem understanding Algorithm developing Program writing Program editing Program compiling Program running Testing and debugging Prepared by Department of Preparatory year

Prepared by Department of Preparatory year What an Algorithm is ??? “Sequence of precise instructions which leads to a solution is called an algorithm.” or “An algorithm is a set of steps that defines how a task is to performed.” Example: Steps (algorithm) for preparing a cake. Steps (algorithm) for calculating the area of a rectangle. Steps (algorithm) to solve a first degree equation. Steps (algorithm) to solve a second degree equation using delta. Prepared by Department of Preparatory year

Prepared by Department of Preparatory year Algorithm Representation There are many ways in which we may represent an algorithm; We use many techniques to represent an algorithm in computer programming. The techniques that will study are: Flowchart Pseudocode Prepared by Department of Preparatory year

Some verbs used in Pseudocode Get, Read  used when a computer is required to receive information or input from a particular source Put, Output, Display, Print  used when the computer is required to receive information or input from a particular source Compute, Calculate  used when when the computer is required to perform arithmetic Initialise, Set  used to give data an initial value If  used to select one of two alternate actions Dowhile, Enddo  used to repeat a group of actions Prepared by Department of Preparatory year

Prepared by Department of Preparatory year Pseudocode Example: What is algorithm for calculating the area of a rectangle ? 1. Get the values width, height 2. Calculate the value of area = width * height 3. Display the value of the area Prepared by Department of Preparatory year

Prepared by Department of Preparatory year Pseudocode Example: What is algorithm for solving a first degree equation (AX+B = 0) ? 1. Read the values A,B 2. Check if A=0 (if yes there is no equation) therefore no equation to be solved (end processing). 3. Check if B=0 (if yes X=0 and end processing). 4. Calculate the value of X= -B/A 5. Print the value of : X Prepared by Department of Preparatory year

Prepared by Department of Preparatory year Why Flowcharts: The flowchart is graphical representation of the steps required for an algorithm or program. The flowchart is characterized by: Clarify the program logic Identify alternative processing methods Serve as guide for program coding Serve as documentation Prepared by Department of Preparatory year

Prepared by Department of Preparatory year Principals of Flowchart 1. Simplicity: Easy to put on paper Easy to draw Readable and meaningful 2. Organization: - putting ideas together and organizing those ideas in logical way. 3. Planning: - flowchart helps for looking the program in deeper and global way. Prepared by Department of Preparatory year

Prepared by Department of Preparatory year General Concepts Flowchart must be characterized by the following: The major element of the project. Elements are clearly labeled. Sequence of element must be clear. No gap or dead ends. Sequence of elements must be in logical form. Flowchart must be used correctly. Prepared by Department of Preparatory year

Prepared by Department of Preparatory year Levels of Program Flowchart Simple sequential flowchart. Branched flowchart. Simple-loop flowchart. Multi-loop flowchart. Prepared by Department of Preparatory year

No Name Symbol Usage 1 Ellipse Start/Stop 2 Rectangle Expressions 3 Parallelogram Input (Read) / Output(Print) 4 Rhombus Conditional checking 5 Arrow Flow of solution 6 Circle Connector 7 Elongated Hexagon Continue 8 Rectangle with bars Procedure / Function call

Prepared by Department of Preparatory year Example:1 Algorithm for reading student name Start Read student name End start Read student name Stop Prepared by Department of Preparatory year

Prepared by Department of Preparatory year Example:2 Algorithm for calculate the area of circle start Start Read value of R Set PI equal to 3.14 Calculate Area=PI*R*R Print R, Area Stop Read R PI=3.14 Area=Pi*R*R Print R, Area Stop Prepared by Department of Preparatory year

Prepared by Department of Preparatory year Example:3 Draw flow chart for evaluating the following functions: F(X)=x if X>=0, F(X)= -X if X<0 start Start Read X If X>=0 then go to step 4, else step 5 Calculate F(X)=X than go to step 6 Calculate F(X)= -X Print X, F(X) Stop Read X X>=0 Yes No F(x)= -x F(x)=x A Print x, F(x) Stop Prepared by Department of Preparatory year

Prepared by Department of Preparatory year Example:4 Write an algorithm and draw the flow chart to add two numbers. Algorithm: Start Read a, b Calculate c=a + b Print c Stop Flow chart: Start c = a+ b Print c Read a, b Stop Prepared by Department of Preparatory year

Prepared by Department of Preparatory year Exercise 5: Write an algorithm and draw the flow chart to find the circumference of circle Algorithm: Start Read r Calculate c= 2*3.14 * r Print c Stop Start c =2 * 3.14 * r Print c Read r Stop Prepared by Department of Preparatory year

Prepared by Department of Preparatory year Flowchart Levels First Level of Flowchart It is simplest level which contain the sequence of steps without loops or branch and the flowchart comes in straight line from the beginning to the end. Prepared by Department of Preparatory year

Prepared by Department of Preparatory year Second Level of Flowchart It is branched flowchart, when there is a condition statement in the program. Look at the following example: condition operation No Yes operation Prepared by Department of Preparatory year

Prepared by Department of Preparatory year Third Level of Flowchart It is a flowchart which contain iteration or repetitions. It is usually called loop flowcharts. In this type we need to repeat some operation several times using the same set of operation. The general from for this type is as follows: condition No Yes operation Prepared by Department of Preparatory year

Prepared by Department of Preparatory year Exercise 6: write an algorithm and draw a flowchart for printing 10 integers starting from 1 Algorithm: Start Take the initial value of A=1 Check if A>=10 if yes and If no print the number and increment A by 1 start End Print A A>=10? A=A+1 A=1 Yes No Prepared by Department of Preparatory year

Prepared by Department of Preparatory year Looping When we need to use a loop a special symbol can be used Loop i = 0,N,M Instructions to be executed M Counter i Any Initial value Final Value (N) Increment or Decrement Value (M) Prepared by Department of Preparatory year

Prepared by Department of Preparatory year Homework Write an algorithm and draw a flowchart to calculate and print the sum of numbers from 1 to 100 . Prepared by Department of Preparatory year

Prepared by Department of Preparatory year Exercise 7: Write an algorithm and draw a flowchart to calculate and print the sum of numbers from 1 to 100 . start End Sum = Sum + A A<=100? A=A+1 A=1, Sum=0 no yes Algorithm: Start Take the initial value of A=1, Sum=0 Check if A<=100 if yes add the value of A to the Sum and increment A by 1 If no print the Sum and end Print sum Prepared by Department of Preparatory year

Prepared by Department of Preparatory year Homework Write an algorithm and draw a flowchart to calculate and print the sum of numbers from 1 to 100 . Prepared by Department of Preparatory year

Exercises Write algorithms and draw flowcharts to represent the logic of the following programs: Accepts a number and display “Even Number” if the number entered is even. Otherwise the program will display “Odd Number”. Asks the user to input the password “hello”. Only if the password is correct, will display “Welcome”. The user has three chances to input the password. Finds and prints the factorial of any number that is entered by the user. Compares two numbers to see if one is greater than the other and print the result of the comparison.