Chapter 3 Program Design and Branching Structures Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering.

Slides:



Advertisements
Similar presentations
Chapter 3 IF & SELECT. Control Constructs: Branches Definitions: Code: statements or expressions in a program Block: a group of codes Branching: selecting.
Advertisements

A number of MATLAB statements that allow us to control the order in which statements are executed in a program. There are two broad categories of control.
Chapter 3 Program Design And Branching Structures.
Chapter 2 - Problem Solving
Chapter 2 - Problem Solving
ITEC113 Algorithms and Programming Techniques
Chapter 5 Basic I/O Concepts Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul - Turkey Tel:
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
Chapter 8 Introduction to Arrays Part II Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul.
Chapter 10 Additional Features of Arrays Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul.
Program Design and Development
Chapter 7 Introduction to Arrays Part I Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul.
Chapter 2 Basic Elements of Fortan
Chapter 2: Input, Processing, and Output
Chapter 11 Additional Intrinsic Data Types Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul.
Chapter 4 Loops and Character Manipulation Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul.
C++ for Engineers and Scientists Third Edition
Chapter 1 Program Design
Chapter 9 Introduction to Procedures Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul -
Problem Solving Chapter 2. What is an algorithm? n A solution to a problem that is: –Precise –Effective –Terminating.
Chapter 3 Applications & Logical Constructs. 2 Application 1 Temperature Conversion: Write a program that will convert a Celsius temperature to the corresponding.
Chapter 6 AN INTRODUCTION TO FILES AND FILE PROCESSING Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering.
Chapter 3 Planning Your Solution
Fundamentals of C programming
Programming For Nuclear Engineers Lecture 12 MATLAB (3) 1.
The University of Texas – Pan American
Simple Program Design Third Edition A Step-by-Step Approach
Flow Charting. Goals Create Algorithms using Flow Charting procedures. Distinguish between Flow Charting and Pseudocode. Top-Down Design Bottom-up Design.
HAWKES LEARNING SYSTEMS Students Matter. Success Counts. Copyright © 2013 by Hawkes Learning Systems/Quant Systems, Inc. All rights reserved. Section 2.3.
Programming Fundamentals. Today’s lecture Decisions If else …… Switch Conditional Operators Logical Operators.
1 Chapter 4: Selection Structures. In this chapter, you will learn about: – Selection criteria – The if-else statement – Nested if statements – The switch.
Describe the Program Development Cycle. Program Development Cycle The program development cycle is a series of steps programmers use to build computer.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Selection Control Structures. Simple Program Design, Fourth Edition Chapter 4 2 Objectives In this chapter you will be able to: Elaborate on the uses.
Developing an Algorithm
Fall, 2006Selection1 Choices, Choices, Choices! Selection in FORTRAN Nathan Friedman Fall, 2006.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
Lecture 2 Numerical Methods for Engineering MECN 3500 Department of Mechanical Engineering Inter American University of Puerto Rico Bayamon Campus Dr.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Branches and Program Design
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
PROGRAM DEVELOPMENT CYCLE. Problem Statement: Problem Statement help diagnose the situation so that your focus is on the problem, helpful tools at this.
Chapter 3. Control Structures and Program Design ► Two broad categories of control statement:  Branches  Loops ► These will make the program more complex.
MATLAB 及其工程应用 MATLAB and It’s Engineering Application 主讲教师: 胡章芳
Java Programming Fifth Edition Chapter 5 Making Decisions.
Chapter 3: Developing Class Methods Object-Oriented Program Development Using Java: A Class-Centered Approach.
Introduction to Computer Sciences References: [1] Fortran 95/2003 for Scientists and Engineers (3e) by Stephen J. Chapman. [2] Using Fortran 90 by Chester.
8.1 8 Algorithms Foundations of Computer Science  Cengage Learning.
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.
Chapter 2 - VB 2005 by Schneider- modified by S. Jane '081 Chapter 2 - Problem Solving 2.1 Program Development Cycle 2.2 Programming Tools.
INVITATION TO Computer Science 1 11 Chapter 2 The Algorithmic Foundations of Computer Science.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 4: Introduction to C: Control Flow.
Program Design. Simple Program Design, Fourth Edition Chapter 1 2 Objectives In this chapter you will be able to: Describe the steps in the program development.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
How Computers Solve Problems Computers also use Algorithms to solve problems, and change data into information Computers can only perform one simple step.
| MSC 8102:PROGRAMMING CONCEPTS By Vincent Omwenga, PhD. 1.
C++ for Engineers and Scientists Second Edition Chapter 4 Selection Structures.
Program design Program Design Process has 2 phases:
Chapter 2: Input, Processing, and Output
The Selection Structure
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.
Introduction to Computer Programming
Lesson 9: "if-else-if" and Conditional Logic
Control Statement Examples
Chapter 3: Program Statements
Chapter 3: Selection Structures: Making Decisions
Chapter 3: Selection Structures: Making Decisions
Chapter 2: Input, Processing, and Output
Basic Concepts of Algorithm
WRITING AN ALGORITHM, PSEUDOCODE, AND FLOWCHART LESSON 2.
Presentation transcript:

Chapter 3 Program Design and Branching Structures Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul - Turkey Tel: +90 ( ) Fax: +90 ( )

PROGRAM DESIGN AND BRANCHING STRUCTURES Top-Down Design Techniques Top-down design is the process of starting with a large task and breaking it down into smaller, more easily understandable pieces (subtasks) that perform a portion of the desired task. Each subtask may in turn be subdivided into smaller subtasks if necessary. Once the program is divided into small pieces, each piece can be coded and tested independently. © 2010, Dr. ALİ CAN TAKİNACI Slide No: 2

PROGRAM DESIGN AND BRANCHING STRUCTURES 1.Clearly state the problem that you are trying to solve. For example: We were describing, a proper statement of the problem might have been: Design and write a program to solve a system of simultaneous linear equations having real coefficients and with up to 20 equations in 20 unknowns. 2.Define the inputs required by the program and the outputs to be produced by the program. 3.Design the algorithm that you intend to implement in the program An algorithm is a step-by-step procedure for finding the solution to a problem. It is at this stage in the process that top-down design techniques come into play. 4.Turn the algorithm into Fortran statements 5.Test the resulting Fortran program. Alpha Release: First complete version of the program Beta Relase: The most serious bugs have been removed from the program © 2010, Dr. ALİ CAN TAKİNACI Slide No: 3

PROGRAM DESIGN AND BRANCHING STRUCTURES USE OF PSEUDOCODE AND FLOWCHARTS © 2010, Dr. ALİ CAN TAKİNACI Slide No: 4 The constructs used to build algorithms can be described in two different ways: pseudocode and flowcharts. Pseudocode is a hybrid mixture of Fortran and English. It is structured like Fortran, with a separate line for each distinct idea or segment of code, but the descriptions on each line are in English. Each line of the pseudocode should describe its idea in plain, easily understandable English. For example:

PROGRAM DESIGN AND BRANCHING STRUCTURES Flowcharts are a way to describe algorithms graphically. In a flowchart, different graphical symbols represent the different operations in the algorithm, and our standard constructs are made up of collections of one or more of these symbols. Flowcharts are very useful for describing the algorithm implemented in a program after it is completed. However, since they are graphical, flowcharts tend to be cumbersome to modify © 2010, Dr. ALİ CAN TAKİNACI Slide No: 5

PROGRAM DESIGN AND BRANCHING STRUCTURES Common symbols used in flowcharts. © 2010, Dr. ALİ CAN TAKİNACI Slide No: 6

PROGRAM DESIGN AND BRANCHING STRUCTURES LOGICAL CONSTANTS, VARIABLES, AND OPERATORS © 2010, Dr. ALİ CAN TAKİNACI Slide No: 7 The logical data type contains one of only two possible values: TRUE or FALSE. A logical constant can have one of the following values:.TRUE. or.FALSE. (note that the periods are required on either side of the values to distinguish them from variable names). Thus, the following are valid logical constants:.TRUE.. FALSE. A logical variable is a variable containing a value of the logical data type. A logical variable is declared using the LOGICAL statement: LOGICAL :: var1, var2, var3

PROGRAM DESIGN AND BRANCHING STRUCTURES Like arithmetic calculations, logical calculations are performed with an assignment statement, whose form is logical_variable_name = logical_expression © 2010, Dr. ALİ CAN TAKİNACI Slide No: 8 Some relational operations and their results are given

PROGRAM DESIGN AND BRANCHING STRUCTURES Combinational Logic Operators © 2010, Dr. ALİ CAN TAKİNACI Slide No: 9

PROGRAM DESIGN AND BRANCHING STRUCTURES CONTROL CONSTRUCTS: BRANCHES © 2010, Dr. ALİ CAN TAKİNACI Slide No: 10 Branches are Fortran statements that permit us to select and execute specific sections of code (called blocks) while skipping other sections of code. They are variations of the IF statement, plus the SELECT CASE construct.

PROGRAM DESIGN AND BRANCHING STRUCTURES The Block IF Construct © 2010, Dr. ALİ CAN TAKİNACI Slide No: 11 The commonest form of the IF statement is the block IF construct. This construct specifies that a block of code will be executed if and only if a certain logical expression is true. The block IF construct has the form

PROGRAM DESIGN AND BRANCHING STRUCTURES © 2010, Dr. ALİ CAN TAKİNACI Slide No: 12

PROGRAM DESIGN AND BRANCHING STRUCTURES © 2010, Dr. ALİ CAN TAKİNACI Slide No: 13

PROGRAM DESIGN AND BRANCHING STRUCTURES The ELSE and ELSE lF Clauses © 2010, Dr. ALİ CAN TAKİNACI Slide No: 14 Sometimes we may want to execute one set of statements if some condition is true, and different sets of statements if other conditions are true. If fact, there might be many different options to consider. An ELSE clause and one or more ELSE lF clauses may be added to the block IF construct for this purpose. The block IF construct with an ELSE clause and an ELSE lF clause has the form

PROGRAM DESIGN AND BRANCHING STRUCTURES © 2010, Dr. ALİ CAN TAKİNACI Slide No: 15

PROGRAM DESIGN AND BRANCHING STRUCTURES The SELECT CASE Construts © 2010, Dr. ALİ CAN TAKİNACI Slide No: 16 The SELECT CASE construct is another form of branching construct. It permits a programmer to select a particular code block to execute based on the value of a single integer, character, or logical expression. The general form of a CASE construct is:

PROGRAM DESIGN AND BRANCHING STRUCTURES © 2010, Dr. ALİ CAN TAKİNACI Slide No: 17 The case_expr may be any integer, character, or logical expression. Each case selector must be an integer, character, or logical value or a range of values. No single value can appear in more than one case selector. The CASE DEFAULT block is extremely important for good programming design. If an input value in a SELECT CASE statement does not match any of the cases, none of the cases will be executed.