INTRODUCTION – Problem Solving Techniques, Programming Language - PYTHON KIT-KalaignarKarunanidhi Institute of Technology
INTRODUCTION I. Introduction: Fundamentals of digital computers. II. Problem Solving Techniques: Algorithm, Flow Chart, Pseudo code, Program Control Structures, Programming Paradigms. III. Programming languages: Generations of Programming Languages, Language Translators, and Features of a Good Programming Languages. 2
II.Problem Solving Techniques ALGORITHM Definition • Algorithm is defined as a step by step procedure for solving any problem. • It is also a precise rule (or set of rules) specifying how to solve a problem. • An algorithm is a sequence of finite instructions, often used for calculation and data processing. 3
• After the preparation of a suitable plan for developing the program by its logic. • i.e., the correct sequence and procedure of instructions required to carryout the task, the algorithms is often used to refer the logic of a program. 4
Representation of Algorithm • Algorithm has a starting point and a final point. Between these two points are the instructions that solve the problem. • Algorithms often have steps that repeat or require decisions (such as logic or comparison). • Algorithms can be expressed in any language from natural languages (like English, French, etc.) to programming languages (like Basic, Fortran, python, etc..) • Algorithm is the basis for most of the programs. Each rule in an algorithm is written in a programming language. All these rules are collectively called a Program. 5
Algorithm (Find the Area) 1. Start 2. Read the value of radius r 3. Calculate - Area=3.14*r*r 4. Print the Area of the circle 5. Stop Now test the algorithm with sample data Consider the value of radius r=5 Area=3.14*5*5 =78.5 6
Characteristic Of Algorithm • Algorithm has a finite number of inputs. • Every instruction should be precise and unambiguous. • Ensure that the algorithm has proper termination. • Effectiveness of each step is very important. • The desired output must be obtained only after the algorithm • The algorithm should be written in sequence. 7
Qualities of an Algorithm • Accuracy : Algorithm should provide accurate result than others. • Memory : It should require minimum computer memory. • Time : The time taken to execute any program is considered as a main quality. Lesser the time taken better the quality. • Sequence : The procedure of an algorithm must be in a sequential form. 8
BUILDING BLOCKS OF ALGORITHM • Statements 1. Simple Statement 2. Compound Statement • State • Control flow • Functions 9
Instruction/Statements • In computer programming, a statement is the smallest standalone element that expresses some action to be carried out. • It is an instruction written in a high-level language that commands the computer to perform a specified action. • A statement may have internal components (e.g., expressions). 10
Simple statements • assignment: A:= A + 5 • goto: goto next; • return: return 5; • call: function() 11
Compound statements • block: begin ------- end • do-loop: do -------- while (i < 10); • for-loop: for (…) • if-statement: if ---- • else---- • switch-statement: switch (c) { case ‘a’: alert(); break; case ‘q’: quit(); break; } • while-loop: while (…) DO ----- 12
State • An algorithm is deterministic automation for accomplishing a goal which, given an initial state, will terminate in a defined end-state. • Data is read from an input source or device, written to an output sink or device, and/or stored for further processing. 13
Control flow • The order function calls, instructions, and statements are executed or evaluated when a program is running. 1. Sequence Control Structure 2. Selection Control Structures 14
Sequence Control Structure • The sequential control structure is used to perform the actions one after another. • It performs process A and then performs process B and so on. • This structure is represented by writing one process after another. • The logic flow is top to bottom approach. 15
Selection Control Structures • Selection control structures (or) Decision structures allows the program to make a choice between two alternate paths whether it is true or false. • IF...THEN or IF..THEN..ELSE or a case structures are the selection structures. • This logic is used for making decisions. 16
Functions • Functions are “self contained” modules of code that accomplish a specific task. • Functions usually “take in” data, process it, and “return” a result. • Once a function is written, it can be used over and over and over again. • Functions can be “called” from the inside of other functions. 17
Contin.. • When a function is “called” the program “leaves” the current section of code and begins to execute the first line inside the function. Thus the function “flow of control” is: • The program comes to a line of code containing a “function call”. • The program enters the function (starts at the first line in the function code). • All instructions inside of the function are executed from top to bottom. • The program leaves the function and goes back to where it started from. • Any data computed and RETURNED by the function is used in place of the function in the original line of code. 18
Functions contain: • Name - describes the purpose of the function. such as “compute Average”, or just “average”. • Inputs - called parameters (Formal/Actual parameters). Describe what data is necessary for the function to work and gives each piece of data a Symbolic Name for use in the function. • Calculation - varies for each function • Output - Usually one (but sometimes zero or sometimes many) values that are calculated inside the function and “returned” via the output variables. 19
Eg:1 def add(x,y): sum=x+y return sum x=5 y=6 print(‘sum is’,add(x,y)) (OR) a=10 b=20 def add(a,b): return(a+b) print('the addition of two nos is',add(a,b)) 20
NOTATION • PESUOCODE • FLOWCHARTS • PROGRAMMING LANGUAGE 22
• Pseudocode is a kind of structure english for designing algorithm. • Pseudocodes came from two words. Pseudo and code pseudo means imitation and code refer to instructions, written in a programming language. • Pseudocode cannot be compiled nor executed, and there are no real formatting or syntax rules • The benefit of pseudo code is that it enables the programmer to concentrate on the algorithms without worrying about all the syntactic details of a particular programming language. 23
Guidelines for Writing Pseudocode • Write only one Statement per Line • Capitalize initial keyword : Few keywords we use:- READ,WRITE,IF, ELSE, ENDIF, WHILE, ENDWHILE, REPEAT, UNTIL • Indent to show hierarchy : Indentation is a process of showing the boundaries of the structure. 24
Pseudocode is made up of the following logic structure , • Sequential logic • Selection logic • Iteration logic 25
26
Sequence Logic : • It is used to perform instructions in a sequence,that is one after another • Thus,for sequence logic ,pseudocode instructions are written in an order in which they are to be performed. • The logic flow of pseudocode is from top to bottom. Eg:1 A pseudocode to add two numbers and display the results: READ num1, num2 result = num1 + num2 WRITE result.  Sequence logic 27
Selection Logic • It is used for making decisions and for selecting the proper path out of two or more alternative paths in program logic. • It is also known as decision logic. • Selection logic is depicted as either an IF..THEN or an IF…THEN..ELSE Structure. 28
Eg.: Pseudocode greatest of two numbers START READ a and b IF a>b THEN PRINT “A is big” ELSE PRINT “B is big” ENDIF STOP 29
Repetition Logic • It is used to produce loops when one or more instructions may be executed several times depending on some conditions . • It uses structures called DO_WHILE,FOR and REPEAT__UNTIL 30
Pseudocode to print first 10 natural numbers START INITIALIZE a = 0 WHILE a<10 PRINT a a=a+1 ENDWHILE STOP 31
Guess its Type!!! Swapping using temporary variables. READ the value of a, b Interchange the values using a variable t t = a a = b b = t WRITE the swapped value of a, b Stop 32
FLOWCHART • A flow chart is a diagrammatic representation, that illustrates the sequence of operations to be performed to arrive at the solution. • Each step in the process is represented by a different symbol and contains a short description of the process step. • The flow chart symbols are linked together with arrows showing the flow direction of the process. 33
34
GUIDELINES FOR DRAWING FLOWCHARTS 35
36
Advantages of Flowcharts • Communication • Effective analysis • Proper documentation • Efficient Coding • Proper Testing & Debugging • Efficient Program Maintenance 37
Flowchart and Pseudocode is made up of the following logic structure • Sequential logic • Selection logic • Iteration logic 38
Sequence Logic • In a computer program or an algorithm, sequence involves simple steps which are to be executed one after the other. • The steps are executed in the same order in which they are written. 39
Example 1 Sum of two numbers 40
Selection Logic • Selection is used in a computer program or algorithm to determine which particular step or set of steps is to be executed. This is also referred to as a ‘decision’. • A selection statement can be used to choose a specific path dependent on a condition. 41
Find biggest among two numbers 42
Repetition Logic • Repetition allows for a portion of an algorithm or computer program to be executed any number of times dependent on some condition being met. • An occurrence of repetition is usually known as a loop. • The termination condition can be checked or tested at the beginning or end of the loop, and is known as a pre-test or post-test, respectively. 43
Pre test loop- Example Factorial 44
Post test loop- Eg print all natural numbers up to n 45
Algorithm,Flowchart,Pseudocode Comparison 46
Few Examples 47
48
Find the area of a triangle. 49
50
Programming Paradigm • A programming paradigm is a fundamental style of computer programming, serving as a way of building the structure and elements of computer programs. • Comparing with a software development methodology, it is a style of solving specific software engineering problems. 51
History • Different approaches to programming have developed over time. • The concept of a "programming paradigm" as such dates at least to 1978. • The lowest-level programming paradigms are machine code. • In the 1960s, assembly languages were developed followed by development of procedural languages. 52
Why study so many programming languages ? • To Improve our ability to Develop Effective algorithms. • To improve Use of Existing Programming Languages. • To allow a better choice of Programming Language. • To make it Easier to design a new language. 53
Imperative Programming (C) Object-Oriented Programming (C++) Logic/Declarative Programming (Prolog) Functional/Applicative Programming (Lisp) Programming Paradigm - Types 54
1. Procedural Programming • Often thought as a synonym for imperative programming. • Specifying the steps the program must take to reach the desired state. • Based upon the concept of the procedure call. • Procedures, also known as routines, subroutines, methods, or functions that contain a series of computational steps to be carried out. 55
Contin., • The syntax of such languages generally has the form statement 1; statement 2; -------------- statement n; 56
Contin., • The ability to re-use the same code at different places in the program without copying it. • The ability to be strongly modular or structured. • Example of procedural programming are C, Pascal, Basic, FORTRAN etc. 57
2. Functional Programming • Functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state changes and mutable data. • Programs written using the functional programming paradigm are much more easily representable using mathematical concepts. 58
Contin., • The syntax of such languages is : functionn { …function2 { function1 (data)} …} • LISP was the first operational functional programming language. • The Haskell programming language was released in the late 1980s in an attempt to gather together many ideas in functional programming research 59
Contin., • Not been very popular except for a restricted number of application areas, such as artificial intelligence. • Examples of Functional Programming are C, LISP, ML . 60
3.Logical Programming • Also known as Rule based programming and Declarative programming. • Rule based programming checks for presence for a certain condition and when present execute an appropriate action 61
Contin., • The syntax of such Languages generally is similar to the following. enabling condition1→action1 enabling condition2→action2 .......................... enabling conditionn→actionn 62
4.Object Oriented Programming • Object-oriented programming (OOP) is a programming paradigm that uses "objects" – data structures encapsulating data fields and procedures together with their interactions – to design applications and computer programs • Programming techniques may include features such as data abstraction, encapsulation, modularity, polymorphism, and inheritance. 63
Contin., • Though it was invented with the creation of the Simula language in 1965, and further developed in Smalltalk in the 1970s, it was not commonly used in mainstream software application development until the early 1990s. • Many modern programming languages now support OOP. • Examples of Object oriented Programming are C++, java, Smalltalk, simula etc. 64
III. Programming languages - Generations of Programming Languages 65
A programming language is a set of rules that provides a way of telling a computer what operations to perform. A programming language is a set of rules for communicating an algorithm It provides a linguistic framework for describing computations 66
A programming language is a notational system for describing computation in a machine-readable and human-readable form. A programming language is a notational system for describing computation in a machine-readable and human-readable form. 67 A programming language is a tool for developing executable models for a class of problem domains. A programming language is a tool for developing executable models for a class of problem domains.
• English is a natural language. • It has words, symbols and grammatical rules. • A programming language also has words, symbols and rules of grammar. • The grammatical rules are called syntax. • Each programming language has a different set of syntax rules. 68
Why does some people speak French? Programming languages have evolved over time as better ways have been developed to design them. 69 ◦ First programming languages were developed in the 1950s ◦ Since then thousands of languages have been developed Different programming languages are designed for different types of programs.
High-level program 70 class Triangle { ... float surface() return b*h/2; } Low-level program LOAD r1,b LOAD r2,h MUL r1,r2 DIV r1,#2 RET Executable Machine code 0001001001000101 0010010011101100 10101101001...
71
• First Generation Languages •Second Generation Languages •Third Generation Languages •Fourth Generation Languages •Fifth Generation Languages 72
Machine language 73 ◦ Operation code – such as addition or subtraction. ◦ Operands – that identify the data to be processed. ◦ Machine language is machine dependent as it is the only language the computer can understand. ◦ Very efficient code but very difficult to write.
Assembly languages 74 ◦ Symbolic operation codes replaced binary operation codes. ◦ Assembly language programs needed to be “assembled” for execution by the computer. ◦ Each assembly language instruction is translated into one machine language instruction. ◦ Very efficient code and easier to write.
 Closer to English but included simple mathematical notation. 75 ◦ Programs written in source code which must be translated into machine language programs called object code. ◦ The translation of source code to object code is accomplished by a machine language system program called a compiler.
 Alternative to compilation is interpretation which is accomplished by a system program called an interpreter. Common third generation languages 76 ◦ FORTRAN ◦ COBOL ◦ C and C++ ◦ Visual Basic
A high level language (4GL) that requires fewer instructions to accomplish a task than a third generation language. Used with databases 77 ◦ Query languages ◦ Report generators ◦ Forms designers ◦ Application generators
Declarative languages 78 Functional(?): Lisp, Scheme, SML ◦ Also called applicative ◦ Everything is a function Logic: Prolog ◦ Based on mathematical logic ◦ Rule- or Constraint-based
79
Two broad groups 80 ◦ Traditional programming languages  Sequences of instructions  First, second and some third generation languages ◦ Object-oriented languages  Objects are created rather than sequences of instructions  Some third generation, and fourth and fifth generation languages
 FORTRAN 81 ◦ FORmula TRANslation. ◦ Developed at IBM in the mid-1950s. ◦ Designed for scientific and mathematical applications by scientists and engineers.
 COBOL 82 ◦ COmmon Business Oriented Language. ◦ Developed in 1959. ◦ Designed to be common to many different computers. ◦ Typically used for business applications.
BASIC 83 ◦ Beginner’s All-purpose Symbolic Instruction Code. ◦ Developed at Dartmouth College in mid 1960s. ◦ Developed as a simple language for students to write programs with which they could interact through terminals.
 C ◦ Developed by Bell Laboratories in the early 1970s. ◦ Provides control and efficiency of assembly language while having third generation language features. ◦ Often used for system programs. ◦ UNIX is written in C. 84
 Simula 85 ◦ First object-oriented language ◦ Developed by Ole Johan Dahl in the 1960s. Smalltalk ◦ First purely object-oriented language. ◦ Developed by Xerox in mid-1970s. ◦ Still in use on some computers.
 C++ 86 ◦ It is C language with additional features. ◦ Widely used for developing system and application software. ◦ Graphical user interfaces can be developed easily with visual programming tools.
 JAVA 87 ◦ An object-oriented language similar to C++ that eliminates lots of C++’s problematic features ◦ Allows a web page developer to create programs for applications, called applets that can be used through a browser. ◦ Objective of JAVA developers is that it be machine, platform and operating system independent.
Scripting Languages 88 ◦ JavaScript and VBScript ◦ Php and ASP ◦ Perl and Python Command Languages ◦ sh, csh, bash Text processing Languages ◦ LaTex, PostScript
 HTML 89 ◦ HyperText Markup Language. ◦ Used on the Internet and the World Wide Web (WWW). ◦ Web page developer puts brief codes called tags in the page to indicate how the page should be formatted.
 XML 90 ◦ Extensible Markup Language. ◦ A language for defining other languages.
Language Translators
92
93
94
95
96
97
98
99
100
101
Features of Good programming
Formerly: Run Time Performance (Computers were more expensive than programmers) Now: Life cycle (human) cost is more important Ease of designing,coding Debugging Maintenance Reusability 103
Writability: The quality of a language that enables a programmer to use it to express a computation clearly, correctly, concisely, and quickly. Readability: The quality of a language that enables a programmer to understand and comprehend the nature of a computation easily and accurately. Orthogonality: The quality of a language that features provided have as few restrictions as possible and be combinable in any meaningful way. Reliability: The quality of a language that assures a program will not behave in unexpected or disastrous ways during execution. Maintainability: The quality of a language that eases errors can be found and corrected and new features added. 104
Generality: The quality of a language that avoids special cases in the availability or use of constructs and by combining closely related constructs into a single more general one. Uniformity: The quality of a language that similar features should look similar and behave similar. Extensibility:The quality of a language that provides some general mechanism for the user to add new constructs to a language. Standardability: The quality of a language that allows programs written to be transported from one computer to another without significant change in language structure. Implementability: The quality of a language that provides a translator or interpreter can be written. This can address to complexity of the language definition. 105
106

Introduction to Problem Solving Techniques- Python

  • 1.
    INTRODUCTION – Problem Solving Techniques,Programming Language - PYTHON KIT-KalaignarKarunanidhi Institute of Technology
  • 2.
    INTRODUCTION I. Introduction: Fundamentalsof digital computers. II. Problem Solving Techniques: Algorithm, Flow Chart, Pseudo code, Program Control Structures, Programming Paradigms. III. Programming languages: Generations of Programming Languages, Language Translators, and Features of a Good Programming Languages. 2
  • 3.
    II.Problem Solving Techniques ALGORITHM Definition •Algorithm is defined as a step by step procedure for solving any problem. • It is also a precise rule (or set of rules) specifying how to solve a problem. • An algorithm is a sequence of finite instructions, often used for calculation and data processing. 3
  • 4.
    • After thepreparation of a suitable plan for developing the program by its logic. • i.e., the correct sequence and procedure of instructions required to carryout the task, the algorithms is often used to refer the logic of a program. 4
  • 5.
    Representation of Algorithm •Algorithm has a starting point and a final point. Between these two points are the instructions that solve the problem. • Algorithms often have steps that repeat or require decisions (such as logic or comparison). • Algorithms can be expressed in any language from natural languages (like English, French, etc.) to programming languages (like Basic, Fortran, python, etc..) • Algorithm is the basis for most of the programs. Each rule in an algorithm is written in a programming language. All these rules are collectively called a Program. 5
  • 6.
    Algorithm (Find theArea) 1. Start 2. Read the value of radius r 3. Calculate - Area=3.14*r*r 4. Print the Area of the circle 5. Stop Now test the algorithm with sample data Consider the value of radius r=5 Area=3.14*5*5 =78.5 6
  • 7.
    Characteristic Of Algorithm •Algorithm has a finite number of inputs. • Every instruction should be precise and unambiguous. • Ensure that the algorithm has proper termination. • Effectiveness of each step is very important. • The desired output must be obtained only after the algorithm • The algorithm should be written in sequence. 7
  • 8.
    Qualities of anAlgorithm • Accuracy : Algorithm should provide accurate result than others. • Memory : It should require minimum computer memory. • Time : The time taken to execute any program is considered as a main quality. Lesser the time taken better the quality. • Sequence : The procedure of an algorithm must be in a sequential form. 8
  • 9.
    BUILDING BLOCKS OFALGORITHM • Statements 1. Simple Statement 2. Compound Statement • State • Control flow • Functions 9
  • 10.
    Instruction/Statements • In computerprogramming, a statement is the smallest standalone element that expresses some action to be carried out. • It is an instruction written in a high-level language that commands the computer to perform a specified action. • A statement may have internal components (e.g., expressions). 10
  • 11.
    Simple statements • assignment:A:= A + 5 • goto: goto next; • return: return 5; • call: function() 11
  • 12.
    Compound statements • block:begin ------- end • do-loop: do -------- while (i < 10); • for-loop: for (…) • if-statement: if ---- • else---- • switch-statement: switch (c) { case ‘a’: alert(); break; case ‘q’: quit(); break; } • while-loop: while (…) DO ----- 12
  • 13.
    State • An algorithmis deterministic automation for accomplishing a goal which, given an initial state, will terminate in a defined end-state. • Data is read from an input source or device, written to an output sink or device, and/or stored for further processing. 13
  • 14.
    Control flow • Theorder function calls, instructions, and statements are executed or evaluated when a program is running. 1. Sequence Control Structure 2. Selection Control Structures 14
  • 15.
    Sequence Control Structure •The sequential control structure is used to perform the actions one after another. • It performs process A and then performs process B and so on. • This structure is represented by writing one process after another. • The logic flow is top to bottom approach. 15
  • 16.
    Selection Control Structures •Selection control structures (or) Decision structures allows the program to make a choice between two alternate paths whether it is true or false. • IF...THEN or IF..THEN..ELSE or a case structures are the selection structures. • This logic is used for making decisions. 16
  • 17.
    Functions • Functions are“self contained” modules of code that accomplish a specific task. • Functions usually “take in” data, process it, and “return” a result. • Once a function is written, it can be used over and over and over again. • Functions can be “called” from the inside of other functions. 17
  • 18.
    Contin.. • When afunction is “called” the program “leaves” the current section of code and begins to execute the first line inside the function. Thus the function “flow of control” is: • The program comes to a line of code containing a “function call”. • The program enters the function (starts at the first line in the function code). • All instructions inside of the function are executed from top to bottom. • The program leaves the function and goes back to where it started from. • Any data computed and RETURNED by the function is used in place of the function in the original line of code. 18
  • 19.
    Functions contain: • Name- describes the purpose of the function. such as “compute Average”, or just “average”. • Inputs - called parameters (Formal/Actual parameters). Describe what data is necessary for the function to work and gives each piece of data a Symbolic Name for use in the function. • Calculation - varies for each function • Output - Usually one (but sometimes zero or sometimes many) values that are calculated inside the function and “returned” via the output variables. 19
  • 20.
    Eg:1 def add(x,y): sum=x+y return sum x=5 y=6 print(‘sumis’,add(x,y)) (OR) a=10 b=20 def add(a,b): return(a+b) print('the addition of two nos is',add(a,b)) 20
  • 21.
  • 22.
    • Pseudocode isa kind of structure english for designing algorithm. • Pseudocodes came from two words. Pseudo and code pseudo means imitation and code refer to instructions, written in a programming language. • Pseudocode cannot be compiled nor executed, and there are no real formatting or syntax rules • The benefit of pseudo code is that it enables the programmer to concentrate on the algorithms without worrying about all the syntactic details of a particular programming language. 23
  • 23.
    Guidelines for WritingPseudocode • Write only one Statement per Line • Capitalize initial keyword : Few keywords we use:- READ,WRITE,IF, ELSE, ENDIF, WHILE, ENDWHILE, REPEAT, UNTIL • Indent to show hierarchy : Indentation is a process of showing the boundaries of the structure. 24
  • 24.
    Pseudocode is madeup of the following logic structure , • Sequential logic • Selection logic • Iteration logic 25
  • 25.
  • 26.
    Sequence Logic : •It is used to perform instructions in a sequence,that is one after another • Thus,for sequence logic ,pseudocode instructions are written in an order in which they are to be performed. • The logic flow of pseudocode is from top to bottom. Eg:1 A pseudocode to add two numbers and display the results: READ num1, num2 result = num1 + num2 WRITE result.  Sequence logic 27
  • 27.
    Selection Logic • Itis used for making decisions and for selecting the proper path out of two or more alternative paths in program logic. • It is also known as decision logic. • Selection logic is depicted as either an IF..THEN or an IF…THEN..ELSE Structure. 28
  • 28.
    Eg.: Pseudocode greatestof two numbers START READ a and b IF a>b THEN PRINT “A is big” ELSE PRINT “B is big” ENDIF STOP 29
  • 29.
    Repetition Logic • Itis used to produce loops when one or more instructions may be executed several times depending on some conditions . • It uses structures called DO_WHILE,FOR and REPEAT__UNTIL 30
  • 30.
    Pseudocode to printfirst 10 natural numbers START INITIALIZE a = 0 WHILE a<10 PRINT a a=a+1 ENDWHILE STOP 31
  • 31.
    Guess its Type!!! Swappingusing temporary variables. READ the value of a, b Interchange the values using a variable t t = a a = b b = t WRITE the swapped value of a, b Stop 32
  • 32.
    FLOWCHART • A flowchart is a diagrammatic representation, that illustrates the sequence of operations to be performed to arrive at the solution. • Each step in the process is represented by a different symbol and contains a short description of the process step. • The flow chart symbols are linked together with arrows showing the flow direction of the process. 33
  • 33.
  • 34.
  • 35.
  • 36.
    Advantages of Flowcharts •Communication • Effective analysis • Proper documentation • Efficient Coding • Proper Testing & Debugging • Efficient Program Maintenance 37
  • 37.
    Flowchart and Pseudocodeis made up of the following logic structure • Sequential logic • Selection logic • Iteration logic 38
  • 38.
    Sequence Logic • Ina computer program or an algorithm, sequence involves simple steps which are to be executed one after the other. • The steps are executed in the same order in which they are written. 39
  • 39.
    Example 1 Sum oftwo numbers 40
  • 40.
    Selection Logic • Selectionis used in a computer program or algorithm to determine which particular step or set of steps is to be executed. This is also referred to as a ‘decision’. • A selection statement can be used to choose a specific path dependent on a condition. 41
  • 41.
    Find biggest amongtwo numbers 42
  • 42.
    Repetition Logic • Repetitionallows for a portion of an algorithm or computer program to be executed any number of times dependent on some condition being met. • An occurrence of repetition is usually known as a loop. • The termination condition can be checked or tested at the beginning or end of the loop, and is known as a pre-test or post-test, respectively. 43
  • 43.
    Pre test loop-Example Factorial 44
  • 44.
    Post test loop-Eg print all natural numbers up to n 45
  • 45.
  • 46.
  • 47.
  • 48.
    Find the areaof a triangle. 49
  • 49.
  • 50.
    Programming Paradigm • Aprogramming paradigm is a fundamental style of computer programming, serving as a way of building the structure and elements of computer programs. • Comparing with a software development methodology, it is a style of solving specific software engineering problems. 51
  • 51.
    History • Different approachesto programming have developed over time. • The concept of a "programming paradigm" as such dates at least to 1978. • The lowest-level programming paradigms are machine code. • In the 1960s, assembly languages were developed followed by development of procedural languages. 52
  • 52.
    Why study somany programming languages ? • To Improve our ability to Develop Effective algorithms. • To improve Use of Existing Programming Languages. • To allow a better choice of Programming Language. • To make it Easier to design a new language. 53
  • 53.
    Imperative Programming (C) Object-OrientedProgramming (C++) Logic/Declarative Programming (Prolog) Functional/Applicative Programming (Lisp) Programming Paradigm - Types 54
  • 54.
    1. Procedural Programming •Often thought as a synonym for imperative programming. • Specifying the steps the program must take to reach the desired state. • Based upon the concept of the procedure call. • Procedures, also known as routines, subroutines, methods, or functions that contain a series of computational steps to be carried out. 55
  • 55.
    Contin., • The syntaxof such languages generally has the form statement 1; statement 2; -------------- statement n; 56
  • 56.
    Contin., • The abilityto re-use the same code at different places in the program without copying it. • The ability to be strongly modular or structured. • Example of procedural programming are C, Pascal, Basic, FORTRAN etc. 57
  • 57.
    2. Functional Programming •Functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state changes and mutable data. • Programs written using the functional programming paradigm are much more easily representable using mathematical concepts. 58
  • 58.
    Contin., • The syntaxof such languages is : functionn { …function2 { function1 (data)} …} • LISP was the first operational functional programming language. • The Haskell programming language was released in the late 1980s in an attempt to gather together many ideas in functional programming research 59
  • 59.
    Contin., • Not beenvery popular except for a restricted number of application areas, such as artificial intelligence. • Examples of Functional Programming are C, LISP, ML . 60
  • 60.
    3.Logical Programming • Alsoknown as Rule based programming and Declarative programming. • Rule based programming checks for presence for a certain condition and when present execute an appropriate action 61
  • 61.
    Contin., • The syntaxof such Languages generally is similar to the following. enabling condition1→action1 enabling condition2→action2 .......................... enabling conditionn→actionn 62
  • 62.
    4.Object Oriented Programming •Object-oriented programming (OOP) is a programming paradigm that uses "objects" – data structures encapsulating data fields and procedures together with their interactions – to design applications and computer programs • Programming techniques may include features such as data abstraction, encapsulation, modularity, polymorphism, and inheritance. 63
  • 63.
    Contin., • Though itwas invented with the creation of the Simula language in 1965, and further developed in Smalltalk in the 1970s, it was not commonly used in mainstream software application development until the early 1990s. • Many modern programming languages now support OOP. • Examples of Object oriented Programming are C++, java, Smalltalk, simula etc. 64
  • 64.
    III. Programming languages- Generations of Programming Languages 65
  • 65.
    A programming languageis a set of rules that provides a way of telling a computer what operations to perform. A programming language is a set of rules for communicating an algorithm It provides a linguistic framework for describing computations 66
  • 66.
    A programming languageis a notational system for describing computation in a machine-readable and human-readable form. A programming language is a notational system for describing computation in a machine-readable and human-readable form. 67 A programming language is a tool for developing executable models for a class of problem domains. A programming language is a tool for developing executable models for a class of problem domains.
  • 67.
    • English isa natural language. • It has words, symbols and grammatical rules. • A programming language also has words, symbols and rules of grammar. • The grammatical rules are called syntax. • Each programming language has a different set of syntax rules. 68
  • 68.
    Why does somepeople speak French? Programming languages have evolved over time as better ways have been developed to design them. 69 ◦ First programming languages were developed in the 1950s ◦ Since then thousands of languages have been developed Different programming languages are designed for different types of programs.
  • 69.
    High-level program 70 class Triangle{ ... float surface() return b*h/2; } Low-level program LOAD r1,b LOAD r2,h MUL r1,r2 DIV r1,#2 RET Executable Machine code 0001001001000101 0010010011101100 10101101001...
  • 70.
  • 71.
    • First GenerationLanguages •Second Generation Languages •Third Generation Languages •Fourth Generation Languages •Fifth Generation Languages 72
  • 72.
    Machine language 73 ◦ Operationcode – such as addition or subtraction. ◦ Operands – that identify the data to be processed. ◦ Machine language is machine dependent as it is the only language the computer can understand. ◦ Very efficient code but very difficult to write.
  • 73.
    Assembly languages 74 ◦ Symbolicoperation codes replaced binary operation codes. ◦ Assembly language programs needed to be “assembled” for execution by the computer. ◦ Each assembly language instruction is translated into one machine language instruction. ◦ Very efficient code and easier to write.
  • 74.
     Closer toEnglish but included simple mathematical notation. 75 ◦ Programs written in source code which must be translated into machine language programs called object code. ◦ The translation of source code to object code is accomplished by a machine language system program called a compiler.
  • 75.
     Alternative tocompilation is interpretation which is accomplished by a system program called an interpreter. Common third generation languages 76 ◦ FORTRAN ◦ COBOL ◦ C and C++ ◦ Visual Basic
  • 76.
    A high levellanguage (4GL) that requires fewer instructions to accomplish a task than a third generation language. Used with databases 77 ◦ Query languages ◦ Report generators ◦ Forms designers ◦ Application generators
  • 77.
    Declarative languages 78 Functional(?): Lisp,Scheme, SML ◦ Also called applicative ◦ Everything is a function Logic: Prolog ◦ Based on mathematical logic ◦ Rule- or Constraint-based
  • 78.
  • 79.
    Two broad groups 80 ◦Traditional programming languages  Sequences of instructions  First, second and some third generation languages ◦ Object-oriented languages  Objects are created rather than sequences of instructions  Some third generation, and fourth and fifth generation languages
  • 80.
     FORTRAN 81 ◦ FORmulaTRANslation. ◦ Developed at IBM in the mid-1950s. ◦ Designed for scientific and mathematical applications by scientists and engineers.
  • 81.
     COBOL 82 ◦ COmmonBusiness Oriented Language. ◦ Developed in 1959. ◦ Designed to be common to many different computers. ◦ Typically used for business applications.
  • 82.
    BASIC 83 ◦ Beginner’s All-purposeSymbolic Instruction Code. ◦ Developed at Dartmouth College in mid 1960s. ◦ Developed as a simple language for students to write programs with which they could interact through terminals.
  • 83.
     C ◦ Developedby Bell Laboratories in the early 1970s. ◦ Provides control and efficiency of assembly language while having third generation language features. ◦ Often used for system programs. ◦ UNIX is written in C. 84
  • 84.
     Simula 85 ◦ Firstobject-oriented language ◦ Developed by Ole Johan Dahl in the 1960s. Smalltalk ◦ First purely object-oriented language. ◦ Developed by Xerox in mid-1970s. ◦ Still in use on some computers.
  • 85.
     C++ 86 ◦ Itis C language with additional features. ◦ Widely used for developing system and application software. ◦ Graphical user interfaces can be developed easily with visual programming tools.
  • 86.
     JAVA 87 ◦ Anobject-oriented language similar to C++ that eliminates lots of C++’s problematic features ◦ Allows a web page developer to create programs for applications, called applets that can be used through a browser. ◦ Objective of JAVA developers is that it be machine, platform and operating system independent.
  • 87.
    Scripting Languages 88 ◦ JavaScriptand VBScript ◦ Php and ASP ◦ Perl and Python Command Languages ◦ sh, csh, bash Text processing Languages ◦ LaTex, PostScript
  • 88.
     HTML 89 ◦ HyperTextMarkup Language. ◦ Used on the Internet and the World Wide Web (WWW). ◦ Web page developer puts brief codes called tags in the page to indicate how the page should be formatted.
  • 89.
     XML 90 ◦ ExtensibleMarkup Language. ◦ A language for defining other languages.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
    Formerly: Run TimePerformance (Computers were more expensive than programmers) Now: Life cycle (human) cost is more important Ease of designing,coding Debugging Maintenance Reusability 103
  • 103.
    Writability: The qualityof a language that enables a programmer to use it to express a computation clearly, correctly, concisely, and quickly. Readability: The quality of a language that enables a programmer to understand and comprehend the nature of a computation easily and accurately. Orthogonality: The quality of a language that features provided have as few restrictions as possible and be combinable in any meaningful way. Reliability: The quality of a language that assures a program will not behave in unexpected or disastrous ways during execution. Maintainability: The quality of a language that eases errors can be found and corrected and new features added. 104
  • 104.
    Generality: The qualityof a language that avoids special cases in the availability or use of constructs and by combining closely related constructs into a single more general one. Uniformity: The quality of a language that similar features should look similar and behave similar. Extensibility:The quality of a language that provides some general mechanism for the user to add new constructs to a language. Standardability: The quality of a language that allows programs written to be transported from one computer to another without significant change in language structure. Implementability: The quality of a language that provides a translator or interpreter can be written. This can address to complexity of the language definition. 105
  • 105.