Presentation is loading. Please wait.

Presentation is loading. Please wait.

Algorithms and flow charts 1. Programming language Programming language is an artificial language that specifies instruction to be executed on a computer.

Similar presentations


Presentation on theme: "Algorithms and flow charts 1. Programming language Programming language is an artificial language that specifies instruction to be executed on a computer."— Presentation transcript:

1 Algorithms and flow charts 1

2 Programming language Programming language is an artificial language that specifies instruction to be executed on a computer. There are two types of programming languages: 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 2 Prepared by Department of Preparatory year

3 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. 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. 3 Prepared by Department of Preparatory year

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

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

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

7 Computer Languages: b)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:- i.BASIC (Beginners All Purpose Symbolic Instruction Code) ii.COBOL (Common Business Oriented Language) iii.FORTRAN (Formula Translator) iv.C etc. 7 Prepared by Department of Preparatory year

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

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

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

11 Language Translators: 1)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. 11 Prepared by Department of Preparatory year

12 Language Translators: 2)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. 12 Prepared by Department of Preparatory year

13 Language Translators: 3)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. 13 Prepared by Department of Preparatory year

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

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

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

17 What is algorithm for solving a first degree equation? 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). 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 Example: 17 Prepared by Department of Preparatory year

18 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: programming. The techniques that will study are: Flowchart Flowchart Pseudocde Pseudocde 18 Prepared by Department of Preparatory year

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

20 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. 20 Prepared by Department of Preparatory year

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

22 1.Simple sequential flowchart. 2.Branched flowchart. 3.Simple-loop flowchart. 4.Multi-loop flowchart. Levels of Program Flowchart 22 Prepared by Department of Preparatory year

23 NoNameSymbolUsage1EllipseStart/Stop 2RectangleExpressions 3 Parallelogra m Input (Read) / Output(Print) 4Rhombus Conditional checking 5Arrow Flow of solution 6CircleConnector 7 Elongated Hexagon Continue 8 Rectangle with bars Procedure / Function call 23

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

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

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

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

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

29 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. 29 Prepared by Department of Preparatory year

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

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

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

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

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


Download ppt "Algorithms and flow charts 1. Programming language Programming language is an artificial language that specifies instruction to be executed on a computer."

Similar presentations


Ads by Google