Lecture 2 Introduction to Programming

Slides:



Advertisements
Similar presentations
CS 240 Computer Programming 1
Advertisements

Flowcharts Amir Haider Lecturer NFC IEFR. Introduction The flowchart is a means of visually presenting the flow of data through an information processing.
Chapter 1 - An Introduction to Computers and Problem Solving
Reference :Understanding Computers
INTRODUCTION TO PROGRAMMING
Flowcharts.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming The software development method algorithms.
Programming Fundamentals (750113) Ch1. Problem Solving
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
Chapter 1 Program Design
Chapter 3 Planning Your Solution
Programming Logic and System Analysis
Algorithm & Flowchart.
Fundamentals of C programming
สาขาวิชาเทคโนโลยี สารสนเทศ คณะเทคโนโลยีสารสนเทศ และการสื่อสาร.
CSC141 Introduction to Computer Programming
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.
Programming Concepts Chapter 3.
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
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.
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.
How Are Computers Programmed? CPS120: Introduction to Computer Science Lecture 5.
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.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 4: Introduction to C: Control Flow.
Algorithms and Pseudocode
Lecture #1: Introduction to Algorithms and Problem Solving Dr. Hmood Al-Dossari King Saud University Department of Computer Science 6 February 2012.
PROGRAMMING FUNDAMENTALS INTRODUCTION TO PROGRAMMING. Computer Programming Concepts. Flowchart. Structured Programming Design. Implementation Documentation.
Program Program is a collection of instructions that will perform some task.
How Computers Solve Problems Computers also use Algorithms to solve problems, and change data into information Computers can only perform one simple step.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Victoria Ibarra Mat:  Generally, Computer hardware is divided into four main functional areas. These are:  Input devices Input devices  Output.
 Problem Analysis  Coding  Debugging  Testing.
Tools Of Structured Analysis
Introduction to Programming / chapter 3 / COM1022
Programming Languages
Flowcharting Guidelines
Chapter 2- Visual Basic Schneider
Algorithms and Flowcharts
Algorithms An algorithm is a sequence of steps written in the form of English phrases that specific the tasks that are performed while solving the problem.It.
Introduction To Flowcharting
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
Algorithm Algorithm is a step-by-step procedure or formula or set of instruction for solving a problem Its written in English language or natural language.
Programming Logic n Techniques
ALGORITHMS AND FLOWCHARTS
PROBLEM SOLVING AND OFFICE AUTOMATION
Designing and Debugging Batch and Interactive COBOL Programs
Unit# 9: Computer Program Development
Programming Fundamentals (750113) Ch1. Problem Solving
Programming Fundamentals (750113) Ch1. Problem Solving
ALGORITHMS AND FLOWCHARTS
SME1013 PROGRAMMING FOR ENGINEERS
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
SME1013 PROGRAMMING FOR ENGINEERS
Understanding Problems and how to Solve them by using Computers
Programming Fundamentals (750113) Ch1. Problem Solving
Lecture 7 Algorithm Design & Implementation. All problems can be solved by employing any one of the following building blocks or their combinations 1.
Programming Fundamentals (750113) Ch1. Problem Solving
Basic Concepts of Algorithm
Introduction to Programming
Presentation transcript:

Lecture 2 Introduction to Programming Ashar

Program Program : A collection of sequential instructions given to computer to carry out certain task.

Programming Language A language used for expressing a set of computer instructions. A language medium between the computer and the user in order to understand each other. Responsible for the human – computer system communication. Consists of necessary symbols, characters and grammar rules. 

Categories of Programming Languages

Level of programming language Translator (Compilers and Interpreters) Computer understands Machine Language only Translator - Program that translates a code from one programming language to another (usually machine code). Compiler – Program that translates High Level Language into machine code.   Translator (Compilers and Interpreters) - Source program – the program written in a high-level- language - Object program – the machine code equivalent translated by the compiler. - In a compiler – translation and execution are two separate distinct phases.  Interpreter – A program execution environment that accepts high-level language statements and performs desired operations immediately without compilation. Source programCompilerObject program 

Translator (Compilers and Interpreters) Computer understands Machine Language only. Translator - Program that translates a code from one programming language to another (usually machine code). Compiler – Program that translates High Level Language into machine code. 

Program Development Cycle Any program to be developed to solve certain problem should follow the development cycle:- Defining the problem Analyzing the problem Designing a solution (Pseudo code, Algorithm, Flowchart) Coding the solution Testing and debugging the program Documenting the program  Defining the problem Clearly define the problem for which a program is to be develop. Explain in statements that are clearly understood. E.g., Write a program which a) Requests the user to enter a temperature in degree centigrade. b) Calculates the corresponding temperature in degrees Fahrenheit. c) Prints the given temperature and the converted value.  Analyzing the problem Clearly analyze the problem to make sure that we have a clear understanding of the problem. Should be clear about general requirement such as the main inputs to the program, necessary processing and the main outputs from the program. E.g., In our example, the input is the Centigrade temperature C entered using a keyboard, the necessary processing is to convert C by using the formula F = 32 + (9 C / 5). The output will be displayed on the monitor.  Designing a solution (Pseudo code, Algorithm, Flowchart) More than one solution - Different ways of solving a problem. Choose the best and efficient one. Pseudo code, Algorithm, Flowchart to produce a solution to a given problem. More than one Algorithm to solve the problem with its own advantages and disadvantages. Programmer should decide the best and efficient algorithm. 

(3)Designing a solution (Pseudo code, Algorithm, Flowchart) E.g., Searching a word in a dictionary. Search from the beginning ? Search from the end ? Best solution – we use in practice based on the fact that the words in a dictionary are in an alphabetical order. So the first and second solutions are not the best solutions. 

(3)Designing a solution (Pseudo code, Algorithm, Flowchart) For the temperature conversion one possible algorithm will be: 1. Ask the user for the Centigrade temperature. 2. Store the value in a variable C 3. Calculate the corresponding Fahrenheit temperature 4. Store it in variable F. 5. Print the values of variable C and variable F, appropriately labeled. 6. Stop 

(4)Coding the solution The Algorithm or Flowchart is then converted into the instruction code understood by the computer to execute them to produce the desired output. Choice of language e.g., BASIC, C, C++, FORTRAN, COBOL etc. for coding the solution depends upon the requirement of the total software solution.  The coding of the temperature conversion problem looks like: PRINT “Enter temperature in Centigrade” INPUT C LET F = 32 + (9 * C) / 5 PRINT “ Centigrade “ + C PRINT “Converted into Fahrenheit ” + F END

(5)Testing and debugging the program Test the program for any Logical or Syntax Errors Bug – any error in the program Debugging – removing of errors from the program. Test data – testing data to the program for which we know the answer, to find out whether it is doing the intended job.

(5)Testing and debugging the program Testing and debugging the program E.g. some test data for above temperature conversion problem are 0, 100 and 10 for which the answers 32, 212, and 50 should be displayed. If the program does not display the desired output, then it contains at least one bug. We must debug it to give the correct output. E.g. suppose in the above program the code line was LET F = 22 + (9 * C) / 5 The logical place to look for the bug is the calculation statement, since the conversion is wrong. We can see 22 was mistakenly typed instead of 32. After correction the program works fine.

Documenting the program An explanation of how the program works ? How to use it ? It should be done at the same time along with all the activities. Each activity produces its portion of documentation.  It should include: I. Statement of the problem. II. Algorithm or flowchart for solving the problem. III. Program listing. IV. Test data and the output produced by the program.  Above document makes up a Technical documentation, which is useful to a programmer, perhaps to modify the program later. User documentation – document to help non-technical person to use the program without any need to know about the inner working of the program. 

Algorithm and Flowcharts Algorithm Algorithm – Sequential instructions needed to solve any problem. Algorithm is translated into Flowchart and program according to the requirement. Problem should be divided into smallest modules possible, while developing Algorithm. It is called the Modular approach, which makes the program more flexible for future modifications. Algorithm must be written in such a way that they can be easily converted into computer instructions. 

Algorithm and Flowcharts Algorithm The desired features of an algorithm are: Each step of the algorithm should be simple. It should be unambiguous in the sense that the logic is clear. It should be effective i.e., it must lead to a unique solution of the problem. It must end in a finite number of steps. It should be as efficient as possible. 

Algorithm and Flowcharts Flowcharts  Flowchart – A collection of diagrammatically represented symbols connected with arrowheads, which represents a sequence of instructions for information processing. John von Neumann – said to have made the first Flowchart in 1945. 

FLOWCHART Flow charts are easy-to-understand diagrams that show how the steps of a process fit together. It is nothing but a diagrammatic representation of the various steps involved in designing a system.  A flowchart is a diagrammatic representation that illustrates the sequence of operations to be performed to get the solution of a problem.

Flowchart Symbols Some of the boxes, which are used in flowcharts, are

GUIDELINES FOR DRAWING A FLOWCHART (1) The following are some guidelines in flowcharting: (a) In drawing a proper flowchart, all necessary requirements should be listed out in logical order. (b) The flowchart should be clear, neat and easy to follow. There should not be any room for ambiguity in understanding the flowchart. (c) The usual direction of the flow of a procedure or system is from left to right or top to bottom. (d) Only one flow line should come out from a process symbol. (e) Only one flow line should enter a decision symbol, but two or three flow lines, one for each possible answer, should leave the decision symbol.

GUIDELINES FOR DRAWING A FLOWCHART (2) (f) Only one flow line is used in conjunction with terminal symbol. (g) Write within standard symbols briefly. As necessary, you can use the annotation symbol to describe data or computational steps more clearly. (h)If the flowchart becomes complex, it is better to use connector symbols to reduce the number of flow lines. Avoid the intersection of flow lines if you want to make it more effective and better way of communication. (i) Ensure that the flowchart has a logical start and finish. (j) It is useful to test the validity of the flowchart by passing through it with a simple test data.

Example 1

Conditional Statements (If Condition)

Conditional Statements (If – Else Condition)

Counting and Looping (The while Statement)

Example 2 – Algorithm

Example 2 – Flowchart

Example …3

Example …4

Practice.. 1. Develop an Algorithm to add three numbers and convert it into Flowchart. 2. Develop an Algorithm to read two numbers and print the bigger number. Convert it into Flowchart. 3. Develop an Algorithm to find the biggest of the three given numbers and convert it into Flowchart. 4. Develop an Algorithm to find the sum of 10 given numbers and convert it into Flowchart. 5. Develop an Algorithm to find the average of 5 numbers and convert it into Flowchart. 

Problem ..1

Problem ..2

Problem ..3

Problem ..3 Alternative

Problem ..4

Problem ..4 Alternative

Problem ..5

Flowchart and Algorithm Exercise Using standard flowcharting diagrams: Draw a flowchart to convert a temperature in degree Celsius into degree Fahrenheit. Write an Algorithm and Draw a flowchart to find the largest number among ten numbers and display the largest number. Write an Algorithm and Draw a flowchart to get input from user and find its square and cube of the given number and display the result. Write an Algorithm and Draw a flowchart to find the middle number among three numbers and display it. Write an Algorithm and Draw a flowchart to find the volume of a box with given Length, Breadth and Height and display the input and the results. 

References http://whatsupnew.com/flowchart/ https://www.mindtools.com/pages/article/newTMC_9 7.htm http://www.functionx.com/cpp/Lesson09.htm