COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.

Slides:



Advertisements
Similar presentations
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 5 Selection Statements Animated Version.
Advertisements

©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 5 Selection Statements.
The "if structure" is used to execute statement(s) only if the given condition is satisfied.
Selection (decision) control structure Learning objective
COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.
COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.
1 9/24/07CS150 Introduction to Computer Science 1 Relational Operators and the If Statement.
COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.
COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.
COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.
School of Computing Science CMT1000 Ed Currie © Middlesex University 1 CMT1000: Introduction to Programming Ed Currie Lecture 5B: Branch Statements - Making.
1 Lecture 14 Chapter 6 Looping Dale/Weems/Headington.
COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.
Flow control 1: if-statements (Liang 72-80) if(radius < 0) { System.out.println(“cannot get area: radius below zero”); } else { double area = radius *
1 CS150 Introduction to Computer Science 1 Relational Operators and the If Statement 9/22/08.
1 Midterm Review COMP 102. Tips l Eat a light meal before the exam l NO electronic devices (including calculators, dictionaries, phones, pagers, etc.)
The If/Else Statement, Boolean Flags, and Menus Page 180
COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.
If Statements & Relational Operators, Part 2 Programming.
Programming Fundamentals. Today’s lecture Decisions If else …… Switch Conditional Operators Logical Operators.
CS31: Introduction to Computer Science I Discussion 1A 4/9/2010 Sungwon Yang
Chapter 02 (Part III) Introduction to C++ Programming.
Multi Way Selection You can choose statement(s) to run from many sets of choices. There are two cases for this: (a)Multi way selection by nested IF structure.
PROBLEM SOLVING & ALGORITHMS CHAPTER 5: CONTROL STRUCTURES - SELECTION.
CHAPTER 8 CONTROL STRUCTURES Prepared by: Lec. Ghader R. Kurdi.
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 21, 2005 Lecture Number: 10.
If Statements If statements: allow the computer to make a decision Syntax: if (some condition) { then do this; } else { then do that; } no semicolons on.
PROGRAM FLOW CHAPTER3 PART1. Objectives By the end of this section you should be able to: Differentiate between sequence, selection, and repetition structure.
Lecture 2 Control Structure. Relational Operators -- From the previous lecture Relational Operator Meaning == is equal to < is less than > is greater.
1 09/15/04CS150 Introduction to Computer Science 1 Life is Full of Alternatives Part 2.
Control structures Algorithm Development Conditional Expressions Selection Statements 1.
COMP Flow of Control: Branching 1 Yi Hong May 19, 2015.
COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.
If Statements Programming. COMP104 Lecture 7 / Slide 2 Review: Rules for Division l C++ treats integers different than doubles. 100 is an int. l 100.0,
1 CS 101 Fall 2001 Lecture 3. 2 Boolean expressions The expressions that are allowed to be in the parentheses following an if can be of the form x>y,
Iteration & Loop Statements 1 Iteration or Loop Statements Dept. of Computer Engineering Faculty of Engineering, Kasetsart University Bangkok, Thailand.
LESSON 4 Decision Control Structure. Decision Control Structures 1. if statement 2. if-else statement 3. If-else-if statement 4. nested if statement 5.
Programming Fundamentals by Dr. Nadia Y. Yousif1 Control Structures (Selections) Topics to cover here: Selection statements in the algorithmic language:
COMP Loop Statements Yi Hong May 21, 2015.
1 9/26/05CS150 Introduction to Computer Science 1 Life is Full of Alternatives.
C++ Programming Lecture 5 Control Structure I (Selection) – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook.
Programming Language C++ Lecture 3. Control Structures  C++ provides control structures that serve to specify what has to be done to perform our program.
Algorithms JPC and JWD © 2002 McGraw-Hill, Inc. 2 Algorithms 2 An Algorithm is a finite set of precise instructions for performing a computation or for.
Chapter 5 – Decision Making. Structured Programming Sequence Selection Repetition yesno yes no.
Chapter 3. Control Structure C++ Programing. Conditional structure C++ programming language provides following types of decision making statements. Click.
 By the end of this section you should be able to: ◦ Differentiate between sequence, selection, and repetition structure. ◦ Differentiae between single,
Looping I (while statement). CSCE 1062 Outline  Looping/repetition construct  while statement (section 5.1)
Branching statements.
Selection Control Structure
LESSON 4 Decision Control Structure
Compound Assignment Operators in C++
Control Structures: Selection Statement
Chapter#3 Structured Program Development in C++
Repetition Control Structure
Visual Basic – Decision Statements
Summary Two basic concepts: variables and assignments Basic types:
Looping III (do … while statement)
Decision I (if Statement)
CS2011 Introduction to Programming I Selections (I)
CS150 Introduction to Computer Science 1
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
There many situations comes in real life when we need to make some decisions and based on these decisions, we decide what should we do next. Similar situations.
Control Structures: Selection Statement
The Selection Structure
Branching statements Kingdom of Saudi Arabia
Selection Control Structure
Life is Full of Alternatives Part 3
Presentation transcript:

COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo

Lecture Review  if statement Provides the means of choosing  Between two or more execution paths in a program E.g. In ATM,  if user key in correct password? correct: allow user to cash-out money not correct: force user to quit

Lecture Review  Syntax 1. if (condition) {action;} 2. if (condition) {action_1;} else {action_2;} 3. if (condition_1) {action_1;} else if (condition_2) {action_2;} else if (condition_3) {action_3;} else {action_4;}

Lecture Review  Example 1. if ( exam mark is larger than 49 ) { exam passed ;} 2. if ( exam mark is larger than 49 ) { exam passed ;} else { retake exam ;}

Lecture Review  Example 3. if ( exam mark is larger than 89 ) { A grade ;} else if ( exam mark is larger than 69 ) { B grade ;} else if ( exam mark is larger than 59 ) { C grade ;} else if ( exam mark is larger than 49 ) { D grade ;} else { F grade ;}

Lecture Review  Relational Operators == is equal to < is smaller than <= is smaller than or equal to > is larger than >= is larger than or equal to != not equal to  E.g. (10 > 8) True (8 == 6) False (8 <= 8) True

Lecture Review  Example 3. if (exam_mark > 89) {cout<<“A grade”;} else if (exam_mark >= 70) {cout<<“B grade”;} else if (59 < exam_mark) {cout<<“C grade”;} else if (50 <= exam_mark) {cout<<“D grade”;} else {cout<<“F grade”;}

Lecture Review  Boolean Operators && and || or ! Not  E.g. if (is_102TA && is_girl) {cout <<“Hello Jackie!”<<endl;} if (is_102TA || is_helpYou) {cout <<“You are so nice, Thank you!”<<endl;

Leeture Review  Nested if Statement if statement is inside another if if (condition_1) { if (condition_2) { if (condition_3) { action_1; } action_2a; } else { action_2b; } action_3; }

Summary  By the end of this lab, you should be able to: Implement if statement Set condition with  Relational operators  Boolean operators Use shortcut assignment

Lab3  Use if-statement cout<<“…”; cin>>greater_than_18; if (greater_than_18 == ‘y’ || greater_than_18 == ‘Y’) { cout<<“…”; cin>>name; //… input height and weight BMI = /*…*/; cout<<“Dear ”<<name<<“,”<<endl; //… output the 1 st paragraph of advice letter //use if-statement to give different advice according to BMI /* … */ //… output the rest of the advice letter } else cout<<“…”<<endl;