Control Structures: Selection CE 311 K - Introduction to Computer Methods Daene C. McKinney.

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 4: Control Structures I (Selection)
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
CS 111: Introduction to Programming Midterm Exam NAME _________________ UIN __________________ 10/30/08 1.Who is our hero? 2.Why is this person our hero?
Week 6 - Programming I So far, we’ve looked at simple programming via “scripts” = programs of sequentially evaluated commands Today, extend features to:
Chapter 5 Decisions. Outline and Objectives Relational and Logical Operators If Blocks Select Case Blocks.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
Scalar Variables Start the file with: #! /usr/bin/perl –w No spaces or newlines before the the #! “#!” is sometimes called a “shebang”. It is a signal.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 4: Control Structures I (Selection)
COMP 14 Introduction to Programming Miguel A. Otaduy May 18, 2004.
Comparing Numeric Values If Val(Text1.Text) = MaxPrice Then (Is the current numeric value stored in the Text property of Text1 equal to the value stored.
1 Lecture 7:Control Structures I (Selection) Introduction to Computer Science Spring 2006.
1 CS150 Introduction to Computer Science 1 Relational Operators and the If Statement 9/22/08.
Programming with MATLAB. Relational Operators The arithmetic operators has precedence over relational operators.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 30, 2005.
CODING SYSTEMS CODING SYSTEMS CODING SYSTEMS. CHARACTERS CHARACTERS digits: 0 – 9 (numeric characters) letters: alphabetic characters punctuation marks:
Decisions in Python Comparing Strings – ASCII History.
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
CIS162AD - C# Decision Statements 04_decisions.ppt.
CS0004: Introduction to Programming Relational Operators, Logical Operators, and If Statements.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Computer Science Selection Structures.
Chapter 3 Section 1 Number Representation Modern cryptographic methods, unlike the classical methods we just learned, are computer based. Representation.
CPS120: Introduction to Computer Science Decision Making in Programs.
Lecture Set 5 Control Structures Part A - Decisions Structures.
Chapter 5 Decisions. Outline and Objectives Relational and Logical Operators If Blocks Select Case Blocks.
Chapter 5 - VB 2005 by Schneider1 Chapter 5 – Decisions 5.1 Relational and Logical Operators 5.2 If Blocks.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 6, Lecture 1 (Monday)
Computer Science 1620 boolean. Types so far: Integer char, short, int, long Floating Point float, double, long double String sequence of chars.
Programming 1 DCT 1033 Control Structures I (Selection) if selection statement If..else double selection statement Switch multiple selection statement.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
Chapter 51 Decisions Relational and Logical Operators If Blocks Select Case Blocks.
Chapter 4 Control Structures I. Chapter Objectives Learn about control structures Examine relational and logical operators Explore how to form and evaluate.
ICT Introduction to Programming Chapter 4 – Control Structures I.
Introduction to Programming Lecture Note - 2 Visual Basic Programming Fundamentals.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
Computer Programming TCP1224 Chapter 5 The Selection Structure.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Fundamental Programming Fundamental Programming More Expressions and Data Types.
M204 - Data Representation
Chapter 5 – Decision Making. Structured Programming Sequence Selection Repetition yesno yes no.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
LESSON 3 Expressions, Statements, & Operators. STATEMENTS A statement Controls the sequence of execution Evaluates an expression Does nothing (the null.
 Type Called bool  Bool has only two possible values: True and False.
BINARY CODE.
Visual Basic 6 (VB6) Data Types, And Operators
Sequence, Selection, Iteration The IF Statement
Data Transfer ASCII FILES.
Data Encoding Characters.
Chapter 4 – Decisions 4.1 Relational and Logical Operators
Data Types, Identifiers, and Expressions
Relational Operators Operator Meaning < Less than > Greater than
Chapter 3: Introduction to Problem Solving and Control Statements
Program Flow Control Selection & repetition
VB Decisions, Conditions & If
Presenting information as bit patterns
Visual Basic – Decision Statements
Introduction to Programming Using Python PART 2
Chapter 4: Control Structures I (Selection)
Learning Intention I will learn how computers store text.
The Data Element.
Relational Operators.
Chapter 5 Decisions.
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
The Selection Structure
The Data Element.
Chapter 5: The Selection Structure
Presentation transcript:

Control Structures: Selection CE 311 K - Introduction to Computer Methods Daene C. McKinney

Introduction ASCII (ANSI) Character Set Relational Operators Logical Operators Program Control – Selection – If/Then, If/Else/Then, …

ASCII Characters All info is stored in the computer as strings of 0’s and 1’s Each character is coded to a binary value ASCII (American Standard Code for Information Interchange) Codes 33 to 126, represent letters, digits, punctuation marks, and a few miscellaneous symbols,---.,.'-. \ ( (,'"""""-. `,X `. /` ` `._ (,,_\ |,---.,'o `. | / o \ ) \,. (.____, \| \ \____,' \ '`'\ \ _,____,' \,--,-' \ ( C,' \ `--'.' | | |.O | __| \,-'_ / `L `._ _,' ' `. / `--.._ `',. _\ ` `-. /\ | `. (,\ \ _/ `-._ / \ |--' ( \ ' `-. `' \/\`. `. ) \ -hrr- \ `. | |

ASCII Character Set

Chr(n) = character with ASCII value n (0 < n < 255) Asc(str) = ASCII value of the first character of str TextBox1.Text = Chr(65) displays “A” ListBox1.Items.Add(Asc(“Apple”)) displays 65

Relational Operators =equal to <>not equal to <less than >greater than <=less than equal to >=greater than equal to All relational operators have equal precedence and are evaluated left to right

Example - Relational Operators True or false? 1 < = 1 1 < 1 “car” < “cat” “Dog” < “dog” 5 = 10 (false) 5 > 11 (true) 5 <> 11 (true) ExpressionResult = 3 * 51 (true)

Logical Operators OperatorDescriptionExampleResult AndBoth sides must be true T And T F And T TFTF OrOne side or other must be true T Or T F Or T TTTT NotNegates truthNot (T)F

Logical Operators Anot ABnot BA and BA or B FTFTFF FTTFFT TFFTFT TFTFTT

Examples Suppose: n = 4 and ans = “Y” True or False? 1.( 2 < n ) AND ( n < 6 ) 2.( ans < n ) OR ( n = 6 ) 3.NOT ( n <6 ) 4.( ans = “Y” ) OR ( ans = “y” ) 5.NOT ( ans = “y” ) 6.(( ans < n) AND ( n = 7 )) OR ( ans = “Y”) 7.( n - 2 ) AND (( n = 7 ) OR ( ans = “y”))

Order of Operations 1.Parentheses 2.^ 3.* / \ MOD NOT 6.AND 7.OR 3 * 5 > 8 * 2 OR 6 * 7 < 100 – 5 ^ 2 T or F?

Program Control Sequence Selection Repetition yesno yes no

Is the condition true? Execute Action 1 No Yes Selection: If – Then If condition Then Action 1 End If

Is the condition true? Execute Action 1 No Yes Execute Action 2 Selection: If – Then – Else If condition Then Action 1 Else Action 2 End If

Selection: If – Then (variations) N Y ? N Y ? N Y ? N Y ? If – ThenIf – Then - ElseIf – Then - Elseif

Example Find the larger of two numbers input by a user

Example This if block has a logical operator in its condition

Example If the two numbers are equal, the program reports this

Select Case Statement Select Case testExpression Case a statements-a Case b statements-b Case c statements-c … Case z statements-z Case else statements-else End Select Case a actions Case a Case b Case z Case b actions Case z actions Else actions

Summary ASCII (ANSI) Character Set Relational Operators Logical Operators Program Control – Selection – If/Then, If/Else/Then, …