Top-down Program Design, Relational and Logical Operators

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.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Chapter 8 and 9 Review: Logical Functions and Control Structures Introduction to MATLAB 7 Engineering 161.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
17 March, 2000 CS1001 Lecture 2 Programming and problem solving Software engineering practices.
Additional Data Types: 2-D Arrays, Logical Arrays, Strings Selim Aksoy Bilkent University Department of Computer 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
User-defined Functions Selim Aksoy Bilkent University Department of Computer Engineering
Top-down Program Design Selim Aksoy Bilkent University Department of Computer Engineering
Program Design, Relational and Logical Operators Selim Aksoy Bilkent University Department of Computer Engineering
Modules, Hierarchy Charts, and Documentation
Introduction to MATLAB
MATLAB Strings Selim Aksoy Bilkent University Department of Computer Engineering
Relational and Logical Operators Selim Aksoy Bilkent University Department of Computer Engineering
C++ Operators CS242 COMPUTER PROGRAMMING T.Banan Al-Hadlaq.
Visual Basic Chapter 1 Mr. Wangler.
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.
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
PYTHON. Python is a high-level, interpreted, interactive and object- oriented scripting language. Python was designed to be highly readable which uses.
Computer Science 101 Introduction to 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
October 3, 2005 Lecture 8 - By Paul Lin 1 CPET 190 Lecture 8 Problem Solving with MATLAB
CMPS 1371 Introduction to Computing for Engineers MatLab.
CPS120: Introduction to Computer Science Operations Lecture 9.
Pseudocode Simple Program Design Third Edition A Step-by-Step Approach 2.
Winter Semester 2014/2015 College of Engineering.
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
Neal Stublen What's a class?  A class is comprised of a set of data and the actions taken on that data  Each action is represented.
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.
CMSC 104, Version 8/061L10ArithmeticOps.ppt Arithmetic Operators Topics Arithmetic Operators Operator Precedence Evaluating Arithmetic Expressions In-class.
“Operators” (i.e. “symbols”)
The Department of Engineering Science The University of Auckland Welcome to ENGGEN 131 Engineering Computation and Software Development Lecture 2 Debugging,
CS 115 Lecture 5 Math library; building a project Taken from notes by Dr. Neil Moore.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
The Department of Engineering Science The University of Auckland Welcome to ENGGEN 131 Engineering Computation and Software Development Lecture 2 Debugging,
Fundamentals of Programming I Overview of Programming
Control Structures I Chapter 3
Chapter 3 Program Design
Arithmetic Operators Topics Arithmetic Operators Operator Precedence
Lecture 3: Operators, Expressions and Type Conversion
Computing Fundamentals
Design & Technology Grade 7 Python
The Selection Structure
Variables, Expressions, and IO
Conditional Statements
Introduction to C++ Programming
Use of Mathematics using Technology (Maltlab)
Class 9.1 Chapter 4 Sections: 4.1, 4.2, 4.3
Chapter 3: Selection Structures: Making Decisions
Programming Concepts and Database
Experiment No. (1) - an introduction to MATLAB
Life is Full of Alternatives
Chapter 3: Selection Structures: Making Decisions
Chapter 3: Selection Structures: Making Decisions
Text Copyright (c) 2017 by Dr. E. Horvath
DATA TYPES AND OPERATIONS
WRITING AN ALGORITHM, PSEUDOCODE, AND FLOWCHART LESSON 2.
Presentation transcript:

Top-down Program Design, Relational and Logical Operators Selim Aksoy Bilkent University Department of Computer Engineering saksoy@cs.bilkent.edu.tr

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 Fall 2004 CS 111

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) + 273.15; % Write out the result. fprintf('%6.2f degrees Fahrenheit = %6.2f kelvins.\n', ... temp_f,temp_k); Fall 2004 CS 111

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

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) + 273.15 Write temperature in degree Kelvins Fall 2004 CS 111

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 m3) from the user and output the amount of extra space (in m3) in the tank. Input: radius and height amount of water Output: extra space Fall 2004 CS 111

Top-down Program Design Get radius of the tank base from the user Get the height of the tank from the user Get the amount of water Calculate the amount of extra space 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 Fall 2004 CS 111

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); Fall 2004 CS 111

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 52.831853 m3 extra space in the tank Continue testing: Enter the amount of water:100 There is -37.168147 m3 extra space in the tank Fall 2004 CS 111

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 Fall 2004 CS 111

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

Relational Operators Operation Result 3 < 4 1 3 <= 4 3 == 4 3 ~= 4 3 > 4 4 >= 4 ‘A’ < ‘B’ Fall 2004 CS 111

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) Fall 2004 CS 111

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

Logical Operators input and or xor not a b a & b a | b xor(a,b) ~a 1 1 Fall 2004 CS 111

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) Fall 2004 CS 111