Program Design, Relational and Logical Operators Selim Aksoy Bilkent University Department of Computer Engineering

Slides:



Advertisements
Similar presentations
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.
Advertisements

User-defined Functions Selim Aksoy Bilkent University Department of Computer Engineering
Chapter 3 Program Design And Branching Structures.
CMSC 104, Version 9/011 Arithmetic Operators Topics Arithmetic Operators Operator Precedence Evaluating Arithmetic Expressions In-class Project Incremental.
INTRODUCTION TO PROGRAMMING
Chapter 8 and 9 Review: Logical Functions and Control Structures Introduction to MATLAB 7 Engineering 161.
17 March, 2000 CS1001 Lecture 2 Programming and problem solving Software engineering practices.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
Chapter 3 Program Design and Branching Structures Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering.
Branches and Loops Selim Aksoy Bilkent University Department of Computer Engineering
MATLAB Review Selim Aksoy Bilkent University Department of Computer Engineering
Class 9.1 Chapter 4 Sections: 4.1, 4.2, 4.3
Lecture Notes 1/21/04 Program Design & Intro to Algorithms.
Top-down Program Design, Relational and Logical Operators
User-defined Functions Selim Aksoy Bilkent University Department of Computer Engineering
Top-down Program Design Selim Aksoy Bilkent University Department of Computer Engineering
Chapter 1 Program Design
Lecture Notes 8/30/05 Program Design & Intro to Algorithms.
Introduction to MATLAB
Relational and Logical Operators Selim Aksoy Bilkent University Department of Computer Engineering
Pseudocode.
Design & Analysis of Algorithms Introduction. Introduction Algorithms are the ideas behind computer programs. An algorithm is the thing which stays the.
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING.
Visual Basic Chapter 1 Mr. Wangler.
Introduction to Matlab Creating Matlab Scripts Birth Year Program Get the user’s age as input Display the user’s birth year Use input() to get the age.
1 Lab Session-III CSIT-120 Fall 2000 Revising Previous session Data input and output While loop Exercise Limits and Bounds Session III-B (starts on slide.
1 Chapter 1 MATLAB Primer This introductory chapter is relatively short and has as its main objective the introduction of MATLAB ® to the reader. This.
Programming.
School of Computer Science & Information Technology G6DICP - Lecture 9 Software Development Techniques.
Computer Science 101 Introduction to Programming.
Arithmetic Operators Topics Arithmetic Operators Operator Precedence
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
October 3, 2005 Lecture 8 - By Paul Lin 1 CPET 190 Lecture 8 Problem Solving with MATLAB
I Power Higher Computing Software Development The Software Development Process.
Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.
Introduction to Programming with RAPTOR
CPS120: Introduction to Computer Science Operations Lecture 9.
Pseudocode. Simple Program Design, Fourth Edition Chapter 2 2 Objectives In this chapter you will be able to: Introduce common words, keywords, and meaningful.
Pseudocode Simple Program Design Third Edition A Step-by-Step Approach 2.
Cs413_design04.ppt Design and Software Development Design : to create a functional interface that has high usability Development : an organized approach.
Branches and Program Design
CS221 Algorithm Basics. What is an algorithm? An algorithm is a list of instructions that transform input information into a desired output. Each instruction.
Chapter 4 Controlling Execution CSE Objectives Evaluate logical expressions –Boolean –Relational Change the flow of execution –Diagrams (e.g.,
MATLAB 及其工程应用 MATLAB and It’s Engineering Application 主讲教师: 胡章芳
Software Engineering CS103 February 13, How Do You Solve Big Problems? Thousands of programmers Thousands of programmers Months or years of coding.
Program Development C# Programming January 30, 2007 Professor J. Sciame.
Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming.
CMSC 104, Version 8/061L10ArithmeticOps.ppt Arithmetic Operators Topics Arithmetic Operators Operator Precedence Evaluating Arithmetic Expressions In-class.
Intro to Loops 1.General Knowledge 2.Two Types of Loops 3.The WHILE loop 1.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 4: Introduction to C: Control Flow.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Visual Basic.NET Windows Programming
Fundamentals of Programming I Overview of Programming
Control Structures I Chapter 3
Arithmetic Operators Topics Arithmetic Operators Operator Precedence
The Selection Structure
ALGORITHM Basic CONCEPTS of Basic Concepts of Algorithm
Conditional Statements
Use of Mathematics using Technology (Maltlab)
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING
Class 9.1 Chapter 4 Sections: 4.1, 4.2, 4.3
Click to add Text Computers & Instructions. Computers are given instructions in the form of computer programs that are created through the development.
Chapter 3: Selection Structures: Making Decisions
Life is Full of Alternatives
Programming Concepts and Database
Life is Full of Alternatives
Chapter 3: Selection Structures: Making Decisions
Chapter 3: Selection Structures: Making Decisions
WRITING AN ALGORITHM, PSEUDOCODE, AND FLOWCHART LESSON 2.
Electrical and Computer Engineering Department SUNY – New Paltz
Presentation transcript:

Program Design, Relational and Logical Operators Selim Aksoy Bilkent University Department of Computer Engineering

Spring 2004CS 1112 Creating MATLAB Scripts Choose File>New>M-file from the menu Use the editor to write your program Document your program using comments that include Short note about what your program does Short note about how it works Author information Date information Version information

Spring 2004CS 1113 Creating MATLAB Scripts % Script file: temp_conversion.m % % Purpose: % To convert an input temperature from degrees Fahrenheit to % an output temperature in kelvins. % % Record of revisions: % Date Programmer Description of change % ==== ========== ===================== % 12/01/97 S. J. Chapman Original code % % Define variables: % temp_f -- Temperature in degrees Fahrenheit % temp_k -- Temperature in kelvins % Prompt the user for the input temperature. temp_f = input('Enter the temperature in degrees Fahrenheit: '); % Convert to kelvins. temp_k = (5/9) * (temp_f - 32) ; % Write out the result. fprintf('%6.2f degrees Fahrenheit = %6.2f kelvins.\n',... temp_f,temp_k);

Spring 2004CS 1114 Top-down Program Design Start State the problem Define inputs and outputs Design the algorithm Convert algorithm into MATLAB statements Test the resulting program End Decomposition Stepwise refinement

Spring 2004CS 1115 Algorithm Systematic procedure that produces -in a finite number of steps- the answer to a question or the solution of a problem. The name derives from the Latin translation, Algoritmi de numero Indorum, of the 9th- century Muslim mathematician al-Khwarizmi's arithmetic treatise “Al-Khwarizmi Concerning the Hindu Art of Reckoning.” (Britannica) An algorithm is a sequence of finite number of steps arranged in a specific logical order which, when executed, will produce a correct solution for a specific problem.

Spring 2004CS 1116 Pseudocode A hybrid mixture of MATLAB and English for defining algorithms Independent of any programming language so it can be easily converted to any programming language Example pseudocode: Prompt user to enter temperature in degrees Fahrenheit Read temperature in degrees Fahrenheit (temp_f) temp_k (in Kelvins)  (5/9) * (temp_f – 32) Write temperature in degree Kelvins

Spring 2004CS 1117 Testing Test individual subtasks: unit testing Add tested components one by one and test them together: build Alpha release Beta release Test for all legal input data sets: standard data sets, ground truth

Spring 2004CS 1118 Top-down Program Design Problem: write a program that takes the radius and height (in meters) of a cylinder tank and the amount of water (in m 3 ) from the user and output the amount of extra space (in m 3 ) in the tank. Input: radius and height amount of water Output: extra space

Spring 2004CS 1119 Top-down Program Design Design: 1. Get radius of the tank base from the user 2. Get the height of the tank from the user 3. Get the amount of water 4. Calculate the amount of extra space 5. Write the result Step 4 is not clear enough, refine it: Calculate the capacity of the tank (pi * radius^2 * h) extra space  capacity - water

Spring 2004CS Top-down Program Design Code: r = input('Enter the radius of the tank base:'); h = input('Enter the height of the tank:'); water = input('Enter the amount of water:'); capacity = pi * r^2 * h; space = capacity - water; fprintf('There is %f m3 extra space in the tank', space);

Spring 2004CS Top-down Program Design Testing: Enter the radius of the tank base:2 Enter the height of the tank:5 Enter the amount of water:10 There is m3 extra space in the tank Continue testing: Enter the radius of the tank base:2 Enter the height of the tank:5 Enter the amount of water:100 There is m3 extra space in the tank

Spring 2004CS Top-down Program Design Design: refine step 4 again Calculate the capacity of the tank (pi * radius^2 * h) extra space  ((capacity – water) + abs(capacity – water))/2

Spring 2004CS Relational Operators Relational operators are used to represent conditions (such as “space  0” in the previous example) Result of the condition is either true or false In MATLAB: false is represented by 0 true is represented by 1 (non-zero)

Spring 2004CS Relational Operators OperationResult 3 < 41 3 <= 41 3 == 40 3 ~= 41 3 > 40 4 >= 41 ‘A’ < ‘B’1

Spring 2004CS Relational Operators Don’t confuse equivalance (==) with assignment (=) Be careful about roundoff errors during numeric comparisons (you can represent “x == y” as “abs(x-y) < eps”) Relational operations have lower priority than arithmetic operations (use parentheses to be safe, though)

Spring 2004CS Logical Operators More complex conditions can be represented by combining relational operations using logic operators Logical operators: &AND |OR xorExclusive OR ~NOT

Spring 2004CS Logical Operators inputandorxornot aba & ba | bxor(a,b)~a

Spring 2004CS Operator Hierarchy Processing order of operations: parenthesis (starting from the innermost) exponentials (left to right) multiplications and divisions (left to right) additions and subtractions (left to right) relational operators (left to right) ~ operators & operators (left to right) | operators (left to right)