CS 240 Computer Programming 1

Slides:



Advertisements
Similar presentations
TWO STEP EQUATIONS 1. SOLVE FOR X 2. DO THE ADDITION STEP FIRST
Advertisements

2. Getting Started Heejin Park College of Information and Communications Hanyang University.
4 Control Statements: Part 1.
1 Vorlesung Informatik 2 Algorithmen und Datenstrukturen (Parallel Algorithms) Robin Pomplun.
© 2008 Pearson Addison Wesley. All rights reserved Chapter Seven Costs.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Chapter 1 The Study of Body Function Image PowerPoint
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 6 Author: Julia Richards and R. Scott Hawley.
Author: Julia Richards and R. Scott Hawley
1 Copyright © 2013 Elsevier Inc. All rights reserved. Appendix 01.
UNITED NATIONS Shipment Details Report – January 2006.
and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action
Writing Pseudocode And Making a Flow Chart A Number Guessing Game
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 5: Repetition and Loop Statements Problem Solving & Program.
Chapter 3: Top-Down Design with Functions Problem Solving & Program Design in C Sixth Edition By Jeri R. Hanly & Elliot B. Koffman.
1 RA I Sub-Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Casablanca, Morocco, 20 – 22 December 2005 Status of observing programmes in RA I.
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
Year 6 mental test 10 second questions
Excel Functions. Part 1. Introduction 2 An Excel function is a formula or a procedure that is performed in the Visual Basic environment, outside the.
Solve Multi-step Equations
REVIEW: Arthropod ID. 1. Name the subphylum. 2. Name the subphylum. 3. Name the order.
Chapter 11: Models of Computation
2 |SharePoint Saturday New York City
VOORBLAD.
Name Convolutional codes Tomashevich Victor. Name- 2 - Introduction Convolutional codes map information to code bits sequentially by convolving a sequence.
1 RA III - Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Buenos Aires, Argentina, 25 – 27 October 2006 Status of observing programmes in RA.
Factor P 16 8(8-5ab) 4(d² + 4) 3rs(2r – s) 15cd(1 + 2cd) 8(4a² + 3b²)
Basel-ICU-Journal Challenge18/20/ Basel-ICU-Journal Challenge8/20/2014.
1..
CONTROL VISION Set-up. Step 1 Step 2 Step 3 Step 5 Step 4.
© 2012 National Heart Foundation of Australia. Slide 2.
Lecture 7: Software Design (Part II)
Understanding Generalist Practice, 5e, Kirst-Ashman/Hull
Model and Relationships 6 M 1 M M M M M M M M M M M M M M M M
25 seconds left…...
Chapter 10: The Traditional Approach to Design
Analyzing Genes and Genomes
Systems Analysis and Design in a Changing World, Fifth Edition
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Essential Cell Biology
Intracellular Compartments and Transport
PSSA Preparation.
Essential Cell Biology
Energy Generation in Mitochondria and Chlorplasts
Chapter 30 Induction and Inductance In this chapter we will study the following topics: -Faraday’s law of induction -Lenz’s rule -Electric field induced.
1 Decidability continued…. 2 Theorem: For a recursively enumerable language it is undecidable to determine whether is finite Proof: We will reduce the.
Benchmark Series Microsoft Excel 2013 Level 2
CS 240 Computer Programming 1
INTRODUCTION TO PROGRAMMING
Chapter 2- Visual Basic Schneider
Review Algorithm Analysis Problem Solving Space Complexity
Algorithm & Flowchart.
Flowcharts.
Visual Basic Programming
Basic problem solving CSC 111.
PROGRAM DEVELOPMENT CYCLE. Problem Statement: Problem Statement help diagnose the situation so that your focus is on the problem, helpful tools at this.
Fundamentals of Algorithms MCS - 2 Lecture # 5. Representation of Algorithms (continued) Flowcharts.
CSC 111. Solving Problems with Computers Java Programming: From Problem Analysis to Program Design, Third Edition3 Solving Problems Stages 1.Problem.
Flowcharts C++ Lab. Algorithm An informal definition of an algorithm is: a step-by-step method for solving a problem or doing a task. Input data A step-by-step.
Lesson 2 Flowcharting.
Lecture 2 Introduction to Programming
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.
Unit# 9: Computer Program Development
Chapter 2- Visual Basic Schneider
Presentation transcript:

CS 240 Computer Programming 1 Flowcharts

An informal definition of an algorithm is: a step-by-step method for solving a problem or doing a task.

Algorithm A step-by-step problem-solving procedure An algorithm is a sequence of unambiguous instructions for solving a problem. The number of steps of an algorithm will be countable and finite. It is a sequence of instructions (or set of instructions) to make a program more readable; a process used to answer a question.

How to understand the problem? Define the problem Analyze the problem Develop an algorithm/method of solution Write a computer program corresponding to the algorithm Test and debug the program Document the program (how it works and how to use it)

Tools Flowcharts Pseudo code There are two commonly used tools to help to document program logic (the algorithm) Flowcharts Pseudo code

A flowchart indicates: Definition The production flowchart is a visual representation of the sequence of the program. It shows what comes first, second, third, etc A flowchart indicates: The steps to be taken in order to solve a problem. The order or the sequence of these steps.

Flowchart Rules 1. Use only one start and one stop per flowchart, --that is, one way in and one way out of the flowchart. 2. The logic flow of the solution is displayed from top to bottom and from left to right. 3. Use the appropriate symbol for each type of operation. 4. Use arrows when moving to another part of the flowchart rather than lines. 5. Do not leave dead-ends--that is, a part of a question unanswered.

Symbols Description Symbol TERMINAL - To start or end a flowchart   TERMINAL - To start or end a flowchart INPUT / OUTPUT - Used with Read, Input, Print and other I/O commands. PROCESSING - Used for operations done inside the computer. Such as calculations, storing and moving of data. DECISION - Used to ask a question in programming. Questions are Yes/No format (Used with the If Statement). DIRECTION FLOW - Used to connect symbols and to represent the direction of flow. Lines should not cross each other. Arrowheads should be placed at the end close to the symbol. Connector - or joining of two parts of program

1.Simple sequential Flowchart Example 1 Construct a flow chart that prints "Hello, World"?

1.Simple sequential Flowchart Algorithm Step 1- Start Step 2- Print "Hello, World" Step 3- Stop

1.Simple sequential Flowchart Start Print “Hello, World” Stop

1.Simple sequential Flowchart Example 2 Construct a flow chart that finds the sum of two numbers.

1.Simple sequential Flowchart Variables Algorithm A: First Number Step 1- Start Step 2- Read A B: Second Number Step 3- Read B C: Sum (A+B) Step 4- Calculate C = A+B Step 5- Print C Step 6- Stop

1.Simple sequential Flowchart Start Read A Read B C= A+B Print C Stop Flowchart

1.Simple sequential Flowchart Example 3 Construct a flow chart that finds the sum, average and product of three numbers.

1.Simple sequential Flowchart Variables Algorithm X: First Number Step 1- Start Y: Second Number Step 2- Read X, Y, Z Step 3- Calculate S = X+Y+Z Z: Third Number Step 4- Calculate A = S/3 S: Sum (X+Y+Z) Step 5- Calculate P = X*Y*Z A: Average (S/3) Step 6- Print S, A, P P: Product (X*Y*Z) Step 7- Stop

1.Simple sequential Flowchart Start Read X,Y,Z S= X+Y+Z A=S/3 P=X*Y*Z Print S,A,P Stop

1.Simple sequential Flowchart Example 4 Construct a flow chart that finds the difference and the division of two numbers and display the result

1.Simple sequential Flowchart Variables Algorithm N1 : First Number Step 1- Start N2 : Second Number Step 2- Read N1, N2 Step 3- Calculate D = N1-N2 D: Difference Step 4- Calculate V = N1/N2 V: Division Step 5- Print D,V Step 6- Stop

1.Simple sequential Flowchart Start Read N1, N2 D= N1 –N2 V=N1/N2 Print D,V Stop

1.Simple sequential Flowchart Example 5 Exercise Construct a flow chart that finds the circle area and circumference of a circle where R (radius) is given

1.Simple sequential Flowchart Variables Algorithm R : Radius Step 1- Start PI: PI = 3.14 Step 2- Read R Step 3- Calculate A = PI*(R)2 A: Area Step 4- Calculate C = 2*PI*R C: Circumference Step 5- Print R, A, C Step 6- Stop

Construct a flow chart for the following function 2. Branched Flowcharts Example 1 Construct a flow chart for the following function F(x) = { X X>=0 -X X<0

2. Branched Flowcharts Variables Algorithm X : Number Step 1- Start F: function of X Step 2- Read X Step 3- if X >=0 then F =X Step 4- if X <0 then F =-X Step 5- Print F Step 6- Stop

2. Branched Flowcharts Flowchart Start Read X YES NO X>=0 F=X F=-X Print F Stop F=-X F=X X>=0 YES NO Flowchart

Trace the following flowchart and write the output of it. 2. Branched Flowcharts Example 2 Trace the following flowchart and write the output of it. 1. When X = 20 2. When X = -10

2. Branched Flowcharts Flowchart Start Read X >0 0> X? =0 W=X+1 Print X,W Stop W=2*X-1 W=X+1 X? >0 0> =0 W=SIN(X)+5 Flowchart

2. Branched Flowcharts Result When X=20 When X=-10 X= 20 X= -10 W= 21

Draw a flowchart that shows the traffic light processing 2. Branched Flowcharts Example 3 Exercise Draw a flowchart that shows the traffic light processing

2. Branched Flowcharts Variables Algorithm C : Traffic light color Step 1- Start Step 2- Read C Step 3- make a Decision (what is c) Step 4- if C is RED then Print STOP Step 5- if C is YELLOW then Print WAIT Step 6- if C is GREEN then Print PASS Step 7- Stop

Trace the following flowchart and write the output of it. 3. Loop Flowcharts Example 1 Trace the following flowchart and write the output of it.

3. Loop Flowcharts Flowchart Start N=1 Print N F While N>=7 Stop T N=N+3 While N>=7 F T N=1 Print N

3. Loop Flowcharts Result N Loop 1 4 2 7 3

Trace the following flowchart and write the output of it. 3. Loop Flowcharts Example 2 Trace the following flowchart and write the output of it.

3. Loop Flowcharts Flowchart Start i=0 Sum=0 F While i<10 Print avg Stop Sum= X + Sum Increment i avg=Sum/10 While i<10 F T i=0 Sum=0 Read X Flowchart

3. Loop Flowcharts Result Avg =50/10 =5 Loop Read X Sum i 1 3 2 4 7 8 18 5 25 6 30 33 41 9 45 50 Avg =50/10 =5