Practical Programming COMP153-06S Lecture 3: Making Decisions.

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

Chapter 4 Decision Making Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E. Reingold.
CS0004: Introduction to Programming Select Case Statements and Selection Input.
ECS 15 if and random. Topic  Testing user input using if statements  Truth and falsehood in Python  Getting random numbers.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program.
Practical Programming COMP153-08S Lecture: Repetition Continued.
Practical Programming COMP153-08S Lecture 6: Making Decisions Part II.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
IS437: Fall 2004 Instructor: Dr. Boris Jukic Program Flow Control: Decisions and Conditions (Branching) Controlled Repetition (Looping)
Basic Elements of Programming A VB program is built from statements, statements from expressions, expressions from operators and operands, and operands.
General Computer Science for Engineers CISC 106 Lecture 10 Roger Craig Computer and Information Sciences 3/06/2009.
Information Technology Center Hany Abdelwahab Computer Specialist.
Visual Basic: An Object Oriented Approach 3 – Making Objects Work.
1 CS150 Introduction to Computer Science 1 Relational Operators and the If Statement 9/22/08.
Chapter 4: Control Structures: Selection
Microsoft Visual Basic 2008: Reloaded Fourth Edition
CS0004: Introduction to Programming Relational Operators, Logical Operators, and If Statements.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Lab 01 Forms in excel Tahani ALdweesh Insert form into your project. 2. Change form’s properties. 3. Put controls on the form. 4. Change controls’
Lecture Set 5 Control Structures Part A - Decisions Structures.
1. We’ve learned that our programs are read by the compiler in order, from top to bottom, just as they are written The order of statement execution is.
Variables, operators, canvas, and multimedia Dr. José M. Reyes Álamo.
CMPS 1371 Introduction to Computing for Engineers CONDITIONAL STATEMENTS.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand how decisions are made in a computer ❏ To understand the logical.
Lab 4 Range Review, Control Logic and Loops ► Range Review ► Control Logic and Loops ► Exercise.
MULTIPLE ALTERNATIVES IF… THEN… ELSEIF SELECT CASE.
Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression.
Computer Science: A Structured Programming Approach Using C1 5-2 Two-Way Selection The decision is described to the computer as a conditional statement.
Computer Science: A Structured Programming Approach Using C1 5-2 Two-Way Selection The decision is described to the computer as a conditional statement.
CSC115 Introduction to Computer Programming Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA 19383
1 Flow Control Ifs, loops. 2 Data Type At the lowest level, all data in a computer is written in 1’s and 0’s (binary) How the data gets interpreted, what.
CS 101 Test 2 Study Guide Acronyms RAD - Rapid Application Development IDE - Integrated Development Environment GUI - Graphical User Interface VB - Visual.
Java Decision Making and booleans (Java: An Eventful Approach, Ch 4), Slides Credit: Bruce, Danyluk and Murtagh CS 120 Lecture October 2012.
4-1 Chapter 4 The Selection Process in VB.NET. 4-2 Learning Objectives Understand the importance of the selection process in programming. Describe the.
Other Variable Types Dim lab as String makes a box that can store a label tag Dim ColHead As String ColHead = “function” ColHead function Dim lab as Boolean.
Chapter 3 Control Structures. The If…Then Statement The If…Then statement is a Decision statement = that executes a set of statements when a condition.
Computer Programming TCP1224 Chapter 5 The Selection Structure.
Visual Basic CDA College Limassol Campus COM123 Visual Basic Programming Semester C Lecture:Pelekanou Olga Week 4: Understand and implement Decisions.
31/01/ Selection If selection construct.
EGR 115 Introduction to Computing for Engineers Branching & Program Design – Part 3 Friday 03 Oct 2014 EGR 115 Introduction to Computing for Engineers.
110 F-1 Decisions and Conditions Chapter 4: We can design a form We can calculate To make our programs more powerful, we need to be able to make choices.
Practical Programming COMP153-08S Lecture: Repetition.
Calculator Program Explained by Arafa Hamed. First Designing The Interface Ask yourself how many places are there that will be used to input numbers?
1 CS161 Introduction to Computer Science Topic #6.
مقدمة في البرمجة Lecture 7. Write VB.net project using the for loop to calculate : 1- the sum of numbers from 1 to (A) numbers. 2- the sum of Odd numbers.
COMP Loop Statements Yi Hong May 21, 2015.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 11 So Many Paths … So Little Time.
Knowledge Base. Defining a Variable Dim statement Dim intXX As Integer Public in a Module Public dblNN As Double.
CS 139 – Programming Fundamentals Lecture 08A. Relational/comparison Operators Relational Operator Meaning > is greater than < is less than >= is greater.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 5 Decision Making.
More Visual Basic Code: if-then-else, for loops Controls: Multiple forms, List Boxes, Radio buttons, frames,
1 4.2 Selection Logical Operators. 2 Learning Objectives Explain how the logical operator AND Boolean statements works. Directly testing if text boxes.
Visual Basic Declaring Variables Dim x as Integer = 0 In the statement above, x is being declared as an Integer (whole number) and is initialised.
CS 31 Discussion, Week 2 Faisal Alquaddoomi, Office Hours: BH 2432, MW 4:30-6:30pm, F 12:30-1:30pm (today)
Visual Basic/ Visual Studio Brandon Large. Connecting to prior knowledge In your notes write down what the two main parts of the computer are. The “software”
Computer Science Up Down Controls, Decisions and Random Numbers.
IF STATEMENTS AND BOOLEAN EXPRESSIONS. BOOLEAN EXPRESSIONS Evaluate to a value of true or false Use relational or equivalence operators Boolean operators.
Practical Programming COMP153-08A Lecture 4:Strings & Formatting.
CSIT 108 Review Visual Basic.NET Programming: From Problem Analysis to Program Design.
CMSC201 Computer Science I for Majors Lecture 03 – Operators
Selection—Making Decisions
An Introduction to Programming with C++ Fifth Edition
البرمجة بلغة فيجول بيسيك
مراحل كتابة البرنامج بلغة فيجول بيسك ستديو
Chapter 8: More on the Repetition Structure
Selection Statements.
Conditional Logic Presentation Name Course Name
Programming Concepts and Database
Understanding Conditions
Selection—Making Decisions
Presentation transcript:

Practical Programming COMP153-06S Lecture 3: Making Decisions

Administration We are doing Lab 2 –MSDN available from CS office –Labs and Lectures are available in the lab and on the web –Try to finish by Friday (20 th ) You should have had Lab 1 verified by today, or at least by the end of this week

Programming So Far First: Controls, Properties, Events Second: Types and Arithmetic The test tutorial had a simple calculator which would have been more useful if we could have supplied an operation as well as 2 numbers. That is today’s topic.

Today – Making Decisions Computer can compare and branch In VB.NET –The If statement –The Select Case statement New type – Boolean (true or false) –Eg: enabled, visible properties The checkbox control allows people to make decisions – message box for popping up a window

The If statement If condition Then statements ElseIf condition Then statements Else statements End If Condition: either a Boolean property or a comparision (with and / or / not) Statements: any VB.NET statements

Eg: Setting background If condition Then statements Else statements End If If (YellowCheckBox.Checked) Then ActiveForm.BackColor = Color.Yellow Else ActiveForm.BackColor = SystemColors.Control End If

Calculator If (TextBox3.Text = "+") Then Label4.Text = Str(Val(TextBox1.Text) + Val(TextBox2.Text)) ElseIf (TextBox3.Text = "-") Then Label4.Text = Str(Val(TextBox1.Text) - Val(TextBox2.Text)) ElseIf (etc.) End If

Tax rates

Tax rates (2) incometaxrates.htmlhttp:// incometaxrates.html Up to $38, cents/dollar 38,001 – 60, cents/dollar Over 60, cents/dollar If (IncomeTextBox.Text <= 38000) Then TaxLabel.Text = IncomeTextBox.Text * 19.5 / 100 ElseIf (IncomeTextBox.Text <= 60000) Then TaxLabel.Text = (IncomeTextBox.Text – 38000) * 33 / 100 Else TaxLabel.Text = (IncomeTextBox.Text ) * 39 / 100 End If Comparison with strings is sort order

The Select Case statement Select Case expression Case value statements Case value statements Case Else statements End Select

Fruit prices

Fruit prices (2) Select Case ItemTextBox.Text Case 1 PriceLabel.Text = WeightTextBox.Text * 3.99 Case 2 PriceLabel.Text = WeightTextBox.Text * 5.5 Case 3 PriceLabel.Text = WeightTextBox.Text * 6.0 Case Else MessageBox.Show(“Please Enter 1, 2 or 3”) End Select

Calculator (2) Select Case (TextBox3.Text) Case "+" Label4.Text = Str(Val(TextBox1.Text) + Val(TextBox2.Text)) Case "-" Label4.Text = Str(Val(TextBox1.Text) - Val(TextBox2.Text)) Case “*” Label4.Text = Str(Val(TextBox1.Text) * Val(TextBox2.Text)) Case “/” Label4.Text = Str(Val(TextBox1.Text) / Val(TextBox2.Text)) Case “^” Label4.Text = Str(Val(TextBox1.Text) ^ Val(TextBox2.Text)) Case Else Label4.Text = “You must use on of (*,+,-,/,^)” End Select

Case is clever (first variable) Case 1, 3, 5 Case 1 To 10 Case 1 To 4, 7 To 9, 11, 13 Dim Number As Integer = 8 Select Number ' Evaluate Number. Case 1 To 5 ' Number between 1 and 5, inclusive. MessageBox.Show("Between 1 and 5") Case 6, 7, 8 ' Number between 6 and 8. MessageBox.Show("Between 6 and 8") Case 9 To 10 ' Number is 9 or 10. MessageBox.Show("Greater than 8") Case Else ' Other values. MessageBox.Show("Not between 1 and 10") End Select

THE END of the lecture