Instructor Özgür ZEYDAN (PhD) CIV 112 Computer Programming http://cevre.beun.edu.tr/zeydan/



Similar documents
PROG0101 Fundamentals of Programming PROG0101 FUNDAMENTALS OF PROGRAMMING. Chapter 3 Algorithms

ALGORITHMS AND FLOWCHARTS. By Miss Reham Tufail

Notes on Algorithms, Pseudocode, and Flowcharts

ALGORITHMS AND FLOWCHARTS

Algorithm & Flowchart & Pseudo code. Staff Incharge: S.Sasirekha

Chapter 1 An Introduction to Computers and Problem Solving

2 SYSTEM DESCRIPTION TECHNIQUES

Flowchart Techniques

Instructor Özgür ZEYDAN BEU Dept. of Enve. Eng. CIV 112 Computer Programming Lecture Notes (1)

KS3 Computing Group 1 Programme of Study hours per week

Chapter 2: Algorithm Discovery and Design. Invitation to Computer Science, C++ Version, Third Edition

Computer Programming Lecturer: Dr. Laith Abdullah Mohammed

JavaScript: Control Statements I

Algorithms, Flowcharts & Program Design. ComPro

CSI 333 Lecture 1 Number Systems

COMPUTER SCIENCE TRIPOS

Chapter 12 Programming Concepts and Languages

1. Process Modeling. Process Modeling (Cont.) Content. Chapter 7 Structuring System Process Requirements

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be...

Total Quality Management (TQM) Quality, Success and Failure. Total Quality Management (TQM) vs. Process Reengineering (BPR)

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

VB Controls and Events. Introduc)on. Program Planning and Flowcharts Visual Basic Visual basic Interface VB Controls CreaGng a Project

Software development and programming. Software

Specimen 2015 am/pm Time allowed: 1hr 30mins

Flowcharting, pseudocoding, and process design

Prentice Hall Mathematics: Course Correlated to: Arizona Academic Standards for Mathematics (Grades 6)

MATLAB Programming. Problem 1: Sequential

Sources: On the Web: Slides will be available on:

EKT150 Introduction to Computer Programming. Wk1-Introduction to Computer and Computer Program

Chapter 13: Program Development and Programming Languages

Lecture 1 Introduction to Java

Chapter 13: Program Development and Programming Languages

Algorithms are the threads that tie together most of the subfields of computer science.

Chapter 14. Programming and Languages. McGraw-Hill/Irwin. Copyright 2008 by The McGraw-Hill Companies, Inc. All rights reserved.

River Dell Regional School District. Computer Programming with Python Curriculum

Visual Logic Instructions and Assignments

Describe the process of parallelization as it relates to problem solving.

Modeling, Computers, and Error Analysis Mathematical Modeling and Engineering Problem-Solving

Chapter One Introduction to Programming

Notes on Assembly Language

Mathematics. What to expect Resources Study Strategies Helpful Preparation Tips Problem Solving Strategies and Hints Test taking strategies

How To Understand Programming Languages And Programming Languages

RARITAN VALLEY COMMUNITY COLLEGE COURSE OUTLINE. CISY 103 Computer Concepts and Programming

QUIZ-II QUIZ-II. Chapter 5: Control Structures II (Repetition) Objectives. Objectives (cont d.) 20/11/2015. EEE 117 Computer Programming Fall

THE UNIVERSITY OF TRINIDAD & TOBAGO

Chapter 3 Problem Solving

MACMILLAN/McGRAW-HILL. MATH CONNECTS and IMPACT MATHEMATICS WASHINGTON STATE MATHEMATICS STANDARDS. ESSENTIAL ACADEMIC LEARNING REQUIREMENTS (EALRs)

Fourth Grade Math Standards and "I Can Statements"

Programmable Logic Controllers Definition. Programmable Logic Controllers History

A Correlation of Pearson Texas Geometry Digital, 2015

Problem Solving Basics and Computer Programming

Grade 4 Unit 3: Multiplication and Division; Number Sentences and Algebra

Mathematics B (2008) Sample assessment instrument and student responses

Using Visual Logic with Pseudocode to Teach an Introductory Programming Course

Excel: Introduction to Formulas

Unit 1 Number Sense. In this unit, students will study repeating decimals, percents, fractions, decimals, and proportions.

Algorithm and Flowchart Structured Programming 1

2014 New Jersey Core Curriculum Content Standards - Technology

2. Capitalize initial keyword In the example above, READ and WRITE are in caps. There are just a few keywords we will use:

Kolbe Academy Home School

1 BPS Math Year at a Glance (Adapted from A Story of Units Curriculum Maps in Mathematics P-5)

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements

Overview. Essential Questions. Precalculus, Quarter 4, Unit 4.5 Build Arithmetic and Geometric Sequences and Series

ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 6 Program Control

Grade 5 Common Core State Standard

Guide to Leaving Certificate Mathematics Ordinary Level

DELAWARE MATHEMATICS CONTENT STANDARDS GRADES PAGE(S) WHERE TAUGHT (If submission is not a book, cite appropriate location(s))

ChE-1800 H-2: Flowchart Diagrams (last updated January 13, 2013)

BPS Math Year at a Glance (Adapted from A Story Of Units Curriculum Maps in Mathematics K-5) 1

Greatest Common Factors and Least Common Multiples with Venn Diagrams

Programming Languages The McGraw-Hill Companies, Inc. All rights reserved.

Open-Ended Problem-Solving Projections

Binary Number System. 16. Binary Numbers. Base 10 digits: Base 2 digits: 0 1

Grade 6 Mathematics Assessment. Eligible Texas Essential Knowledge and Skills

Programming and Software Development CTAG Alignments

Handout #1: Mathematical Reasoning

Introduction to Programming (in C++) Loops. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC

Example. Introduction to Programming (in C++) Loops. The while statement. Write the numbers 1 N. Assume the following specification:

Creating a Simple Macro

CCSS Mathematics Implementation Guide Grade First Nine Weeks

General Certificate of Education Advanced Subsidiary Examination June 2015

CALCULATIONS & STATISTICS

Figure 1: Graphical example of a mergesort 1.

Curriculum Map. Discipline: Computer Science Course: C++

Pseudo code Tutorial and Exercises Teacher s Version

EMC Publishing. Ontario Curriculum Computer and Information Science Grade 11

Fundamentals of Programming and Software Development Lesson Objectives

Conditionals: (Coding with Cards)

Grade descriptions Computer Science Stage 1

Sudoku puzzles and how to solve them

How Do I Evaluate Workflow?

IV. ALGEBRAIC CONCEPTS

24 Uses of Turing Machines

PROGRAMMABLE LOGIC CONTROLLERS Unit code: A/601/1625 QCF level: 4 Credit value: 15 OUTCOME 3 PART 1

Tuesday, October 18. Configuration Management (Version Control)

Outline. hardware components programming environments. installing Python executing Python code. decimal and binary notations running Sage

2.3 WINDOW-TO-VIEWPORT COORDINATE TRANSFORMATION

Requirements Analysis Concepts & Principles. Instructor: Dr. Jerry Gao

Transcription:

Algorithms Pseudocode Flowcharts (PhD) CIV 112 Computer Programming http://cevre.beun.edu.tr/zeydan/ Why do we have to learn computer programming? Computers can make calculations at a blazing speed without any error as compared to the humans. Example: calculate the prime numbers until 121. How long does it take? Do you do any error? Prime numbers: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 109, 113 Such a problem is so easy for a computer 1

Calculate the prime numbers until 121 http://en.wikipedia.org/wiki/file:sieve_of_eratosthenes_animation.gif Performing a Task on The Computer The first step in writing instructions to carry out a task is to determine what the outputshould be that is, exactly what the task should produce. The second step is to identify the data, orinput, necessary to obtain the output. The last step is to determine how to processthe inputto obtain the desired output, that is, to determine what formulas or ways of doing things canbe used to obtain the output. 2

A pictorial representation of problem-solving Program Development Cycle 1. Analyze: Define the problem. Be sure you understand what the program should do, that is, what the outputshould be. Have a clear idea of what data (or input) are given and the relationship between the input and the desired output. 2.Design: Plan the solution to the problem. Find a logical sequence of precise steps that solve the problem. Such a sequenceof steps is called an algorithm. Every detail, including obvious steps, should appear in the algorithm. 3

Program Development Cycle 3. Choose the interface: Select the objects. Determine how the input will be obtained and how the output will be displayed.then create appropriate commands to allow the user to control the program. 4. Code: Translate the algorithm into a programming language. Coding is the technical word for writing the program. 5. Test and debug: Locate and remove any errors in the program. Testing is the process of finding errors in a program, and debugging is theprocess of correcting errors that are found. (An error in a program is called a bug.) Program Development Cycle 6. Complete the documentation: Organize all the material that describes the program. Documentation is intended to allow another person, or the programmer at alater date, to understand the program. Internal documentation consists of statements in the program that are not executed, but point out the purposes of various parts of the program. Documentation might also consist of a detailed description of what the program does and how to use the program (for instance, what type of input is expected). For commercial programs, documentation includes an instruction manual. Other types of documentation are the flowchartand pseudocode. 4

5

Programming Tools Tools used to convert algorithmsinto computer programs: Pseudocode: An informal high-level description of the operating principle of a computer program. It uses the structural conventions of a programming language, but is intended for human reading rather than machine reading. Flowcharts: Graphically depict the logical steps to carry out a task and show how the stepsrelate to each other. Pseudocode vs Flowcharts Artificial and Informal language Helps programmers to plan an algorithm Similar to everyday English Not an actual programming language A graphical way of writing pseudocode Rounded rectangle terminal Parallelogram input / output Rectangle actions Diamonds decision / conditional Circles connector 6

Flowchart Symbols Example Pseudocode Start Read A, B Calculate C = A*B Display C Stop Start- Terminal Read A, B Input Calculate C = A*B -Action Display C - Output Stop - Terminal 7

Example Flowchart S ta r t Start Terminal. Program start here R e a d A R e a d B Input. Enter values for A and B C a lc u la te R e s u t C = A * B Process D is p la y th e R e s u lt C Output S to p Stop Terminal Program end here User Friendly Pseudocode Start Use variables A,B and C Display write two numbers Read A, B Calculate C = A*B Display multiplication of numbers, C Stop 8

Question??? Structured Programming Structured programming was first suggested by Corrado Bohm and Guiseppe Jacopini. The two mathematicians demonstrated that any computer program can be written with just three structures: sequences, decisions, and loops. Sequences: one command is executed after previous one. Decisions (selections): statement(s) is (are) executed if certain condition gives TREU or FALSE value. Loops (repetition): statement(s) is (are) executed repeatedlyuntil certain conditiongives TREU or FALSE value. Corrado; B. and Jacopini, G. (May 1966). "Flow Diagrams, Turing Machines and Languages with Only Two Formation Rules". Communications of the ACM 9 (5): 366 371. 9

Sequences Ref: Deitel P J (Ed.) (2010) C How to Program, 6th Edition, Prentice Hall Decisions (selections) Three selection structure in C programming: If If else Switch Ref: Deitel P J (Ed.) (2010) C How to Program, 6th Edition, Prentice Hall 10

Decisions (selections) Ref: Deitel P J (Ed.) (2010) C How to Program, 6th Edition, Prentice Hall Loops (repetition) Three repetition structure in C programming: While Do while For Ref: Deitel P J (Ed.) (2010) C How to Program, 6th Edition, Prentice Hall 11

Loops (repetition) Ref: Deitel P J (Ed.) (2010) C How to Program, 6th Edition, Prentice Hall Pseudocode and Flowchart for a Decision Structure 12

Example - 2 Write an algorithm to determine a student s averagegrade and indicate whether heis successful or not. The averagegrade is calculated as the average of mid-term and final marks. Student will be successful if his average grade is grater or equals to 60. Pseudocode Start Use variables mid term, final and average Inputmid term and final Calculatethe averageby summing mid term and final and dividing by 2 if average is below 60 Print FAIL else Print SUCCESS Stop 13

Detailed Algorithm 1. Step: 2. Step: 3. Step: endif Input mid-term and final average = (mid-term + final)/2 if (average < 60) then Print FAIL else Print SUCCESS Flowchart START Input mid-term, final average =(mid-term + final)/2 N If average<60 Y PRINT SUCCESS PRINT FAIL STOP 14

Nested If Simply, if structure in if structure Example- 3: Both final and average grades must be grater than or equals to 35 for curve calculation in BEU. if (final >= 35) then { if (average>= 35) then execute curve calculation commands endif } else Print FF grade endif Pseudocode and Flowchart for a Loop 15

Example - 4 Write an algorithm whichcalculates the average exam gradefor a class of 5students. What are the program inputs? the exam grades Processing: Find the sum of the grades; count the number of students; (counter controlled) calculate average grade= sum of grades / number of students. What is the program output? the average exam grade Pseudocode Start Use variables total, counter, grade, average Initialize total = 0 Initialize counter= 1 While (counter <= 5) Input grade Calculate total = total + grade Calculate counter = counter + 1 End-while Calculateaverage= total / 5 Display average Stop 16

Flowchart Example - 5 Write an algorithm whichcalculates the average exam gradefor a class of unknown number of students. What are the program inputs? the exam grades Processing: Find the sum of the grades till sentinel valueis given; for example -99 to break loop (sentinel controlled) calculate average grade= sum of grades / number of students. What is the program output? the average exam grade 17

Pseudocode Start Use variables total, counter, grade, average Initializetotal = 0 Initializecounter= 0 While (grade!= -99) Input grade Calculate total = total + grade Calculate counter = counter + 1 End-while Calculate average = total / counter Display average Stop Example - 6 Write an algorithm whichcalculates the average exam gradefor a class of unknown number of students. This time, the number of students have been asked at the beginning of the program. Use counter controlled structure. 18

Pseudocode Start Use variables total, counter, grade, average, number_of_students Initialize total= 0, number_of_students= 0, counter= 1 Display write number of students Input number_of_students While (counter <= number_of_students) Input grade Calculate total = total + grade Calculate counter = counter + 1 End-while Calculate average = total / number_of_students Displayaverage Stop Question Draw a flowchart for example 6. 19

Fatal Error Memorizing Do not memorize any of the codes in programming. Read and try to understand what is given and what is asked in the question, then write your own codes. Fatal Error Memorizing If (memorize) then Display sure that you will fail this course!!! 20