Presentation on theme: "Sub: 610001 : Fundamental of Programming(FOP) Chap: 1 : Introduction to Programming: Algorithms and Flowcharts Presented By Tejas Modi Asst. Professor,"— Presentation transcript:
Sub: : Fundamental of Programming(FOP) Chap: 1 : Introduction to Programming: Algorithms and Flowcharts Presented By Tejas Modi Asst. Professor, KIM, MCA Programme, kalol
2 Chap: 1 : Introduction To Programming Program and Programming Programming Language Compiler, Interpreter The Process of Compilation Linker, Relocation, Loader Generation of Languages Classification of Programming Languages Algorithms Flowcharts
3 Program and Programming Program –A program is set of logically related instruction that arranged in a sequence and guides the computer in solving a problem. Programming –The process of writing a program is called programming. There are two ways in which one can acquire a program. –Packaged Software –Customized Software
4 Computer Software Computer Software can classified into two categories System Software: it is a collection of programs that interface with the hardware. Application Software: it is written to enable the computer to solve a specific data processing task. Computer Software System SoftwareApplication Software Language Translator Operating System Utilities Special purpose Program (Loader, Linker) Pre – Written Software User – Written Application
5 Programming Language A programming language is composed of a set of instruction in a language understandable to the programmer and recognizable by a computer. System Programming Languages –O.S. Application Programming Languages –Business and Scientific application, Payroll, inventory etc. Low-level Languages: Machine Language (Machine Code) Assembly language (Mnemonic Code) High-level Language Basic C COBOL (Common Business Oriented Programming Language) FORTRAN (Formula Translation Language)
6 Compiler, Interpreter, Loader, Linker Compiler –A high level program source code transfer into a form of machine under standable code, this process is done by compiler. –It is Software. –Diagnostics The process of translating, the compiler the source program statement wise and check for errors. In case of any error, the computer generates a printout of same, this action is known as diagnostic. –Interpreter is another type of translation software. Source Program in High Level Compiler Object Code in Machine Language
7 Difference between Compiler Interpreter Compiler –Scans the entire program before translating it into machine code. –Convert the entire program to machine code and only when all the syntax errors are removed does execution take place. –Slow in debugging, i.e. removal of mistakes from a program. –Execution time is less. Interpreter –Translates and executes the program line by line. –Each time the program is executed, every line is checked for syntax error and the converted to the equivalent machine code. –Good for fast debugging. –Execution time is more.
8 Compiling and Executing High level Language program It consists two step –Analysis of the source program. –Synthesis (creation) of the object program in the machine language of specific machine. A Source language is described using lexical rules, syntax rules and semantic rules. –Lexical rules specify the valid syntactic element or word of language. (identifier, operator delimiter etc.) –Syntax rules specify the way in which valid syntactic elements are combined to form the statements of language. Syntax rules are often described using a notation known BNF (Backus Naur Form) grammar. –Semantic rules assign meanings to valid statements of language.
9 The Process of Compilation Source Program Lexical Analysis Syntactic Analysis Semantic Analysis Symbol Table Other Tables Code Generator Linker and Loader Lexical RulesSyntax RulesSemantic Rules Intermediate code Object Code Executable Code Object Code from Other Compilations
10 Linker & Loader Linker –Linking resolves symbolic references between object program. –Linking of the translated program with other object programs needed for execution. Loader –Loader means physically placing the machine instruction and data into main memory. A loader is a system program that accepts object programs and prepares them for execution and initiates the execution. The function of the loader are as follows: –Assignment of load-time storage area to the program. –Loading of program into assigned area. –Relocation of program to executed properly from its load time storage area. –Linking of programs with one another. A loader is program that places a program’s instruction and data into primary storage (RAM) locations. Linking Loader and Linkage Editor –The machine language program produced by the translator must normally be combined with other machine language program residing within the library to form a useful execution unit. –This process of program combination is called linking and the software that performs this operation is variously known as linking loader or a linkage editor.
11 Generation of Languages The 1GL are low – level languages that are machine language. The 2GL are also low-level languages that generally consist of assembly languages. The 3GL are high – level such as C. The 4GL are languages that consist of statements similar to statements in a human language. Fourth generation languages are commonly used in database programming. The 5GL are programming language which is based around solving problems using constrains given to the program, rather than using an algorithm written by a programmer. Most constraint- based and logic programming languages and some declarative languages are fifth-generation languages. A good example of a fifth generation language is artificial intelligence research. Prolog, OPS5(Official Production System), and Mercury are examples of fifth-generation languages.
12 Classification of Programming Languages Programming Languages High – level LanguagesLow – level Languages Algorithmic (COBOL, FORTAN, C ) ProceduralNon - ProceduralProblem Oriented Object Oriented ( C++, Java ) Scripting ( VB, PERL ) Functional ( LISP, ML ) Logic Based ( PROLOG ) Numerical ( MATLAB ) Symbolic ( MATHEMATICA ) Publishing ( LATEX )
13 Structure Programming Structure programming can be defined as a –Top – down analysis: Subdivision of a problem (First we solve smaller problem) Hierarchy of tasks –Modular Programming: It is a program that is divided into logically independent smaller section. –Structure Code: It is a method of coding, i.e. writing a program that produce a well organized module. (Never use GOTO). A high level language support some structured control statement. –The process of Programming: Understand the problem to be solved Think & design the solution logic Write the program in chosen programming language Translate the program into machine code Test the program with sample data Put the program into operation
14 Algorithms An algorithm is a part of the plan for computer program, an algorithm is ‘an effective procedure for solving a problem in a finite number of step’. Example of an algorithm, for making a pot of tea Key feature of an algorithm –Sequence (also known as process): each step or process in the algorithm is executed in the specified order. –Decision (also known as selection): outcome of the decision is based on some condition. –Repetition (also known as iteration or looping) Variables –A variable is a data name that may be used to store data value. –Variables and data types Numerical Alphabetic Logical data
15 Algorithms Different ways of Starting Algorithms 1.Step-form: Step-form is in written form, the written form is just normal language. Ex: Construct a algorithm for interchange the numeric value of two variable 1. START5. A=B 2. PRINT “ENTER THE VALUE OF A & B”6. B=C 3. INPUT A, B7. PRINT A, B 4. C=A8. END 2.Pseudo-Code Pseudo-code is also in human language but tends toward more precision by using a limited vocabulary. It is similar to 3GL. There is no standard for pseudo-code, it is generally quite easy to read and use. Ex: dowhile kettle_empty Add_water_to _kettle end dowhile
16 3. Flowcharts A flowchart provides appropriate step to be followed in order to arrive at solution to a problem. It is a program design tool which is used before writing the actual program. Flowchart are generally developed in the early stages of formulating computer solution. Standards for Flowcharts Flowcharts must be drawn on white, unlined 81/2” x 11” paper, on one side only. Flowcharts start on the top of the page and flow down and to right. Only standard flowcharting symbols should be used. A template to draw the final version of flowchart should be used. The contents of each symbols should be printed readable. English should be used in flowchart, not programming language. The flowchart for each subroutine, if any must appear on a separate page. Each subroutine begins with a terminals symbols with the subroutine name and a terminal symbols labeled return at the end. Draw arrow between symbols with a straight edge and use arrowheads to indicate the direction of the logic flow.
17 Flowcharts Symbols Add Comments or furnish clarifications Computational steps or processing Function of a program Input entry or Output display operation Decision making and branching operation Connects remote parts of flowchart on the same page A magnetic Tape A magnetic Disk Connects remote portion of the flowchart not on the same page Flow lines Start or end of the program of flowchart Display
18 Flowcharts Guidelines for flowcharting: –There should be logical Start and Stop. –Flow is from left to right or top to bottom. –Only one flow line should emerge from a process symbol. –Only one flow line should enter a decision symbol. –Only one flow line is used in conjunction with a terminal symbol. –If the flowchart becomes complex, connector symbols should ne used –In decision symbol only one input indicated by one incoming flow line and one output flowing out. The decision and process symbol are connected by flow lines. –Iteration or looping is depicted by a combination of process and decision symbols placed in proper order.
19 Ex: Give 5% bonus to employee whose salary is >5000 otherwise give Rs 250 as a bonus. START INPUT SALARY OF AN EMPLOYEE PRINT BONUS STOP IS SAL>=5000 BONUS=250 BONUS=0.05* SALARY
20 Flowcharts Advantages –Communication : Flowcharts are a better way of communicating the logic of a system to all concerned –Effective Analysis: With flowcharts, problem can be analyzed more effectively. –Proper Documentation : Program flowcharts serve as a good program documentation needed for various purposes. –Efficient Coding: Flowcharts act as a guide or blueprint during the systems analysis and program development phase. –Proper Debugging: Flowcharts help in the debugging process. –Efficient Program Maintenance : The maintenance of an operating program becomes easy with the help of a flowcharts Limitations –Complex logic: The program logic is quite complicated. In such a case, a flowchart become complex and clumsy. –Alterations and modifications: If alterations are required, the flowchart may need to be redrawn completely. –Reproduction: Since the flowcharts symbols cannot be typed in, the reproduction of a flowchart become a problem.