CSC141 Computer Science I Zhen Jiang Dept. of Computer Science

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

Control Statements. Define the way of flow in which the program statements should take place. Control Statements Implement decisions and repetitions.
The switch statement Week 5. The switch statement Java Method Coding CONCEPTS COVERED THIS WEEK.
Introduction to Computers and Programming Lecture 6 Professor: Evan Korth New York University.
Decisions (Conditional Programming) Chapter 5 (Sec. 5.1 & 5.2)
Boolean Types & Compound Conditionals CSC 1401: Introduction to Programming with Java Lecture 4 – Part 3 Wanda M. Kunkle.
Boolean Expressions Conditional Statements & Expressions CSC 1401: Introduction to Programming with Java Lecture 4 – Part 2 Wanda M. Kunkle.
The If/Else Statement, Boolean Flags, and Menus Page 180
C++ for Engineers and Scientists Third Edition
CHAPTER#3 STRUCTURED PROGRAM DEVELOPMENT IN C++ 1 st semester King Saud University College of Applied studies and Community Service Csc 1101.
Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA CSC141 Computer Science I.
1 Chapter 4: Selection Structures. In this chapter, you will learn about: – Selection criteria – The if-else statement – Nested if statements – The switch.
CPS120: Introduction to Computer Science Decision Making in Programs.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design First Edition by Tony Gaddis.
Flow of Control Part 1: Selection
Summer Training on Computer Science, WCU Summer Training on Computer Science 2008 Zhen Jiang Department of Computer Science West Chester University West.
Decision Making - CIS 1068 Program Design and Abstraction Zhen Jiang CIS Dept. Temple University SERC 347, Main Campus 10/27/20151.
Lecture 3 Decisions (Conditionals). One of the essential features of computer programs is their ability to make decisions. Like a train that changes tracks.
CHAPTER 4: Selection Control Structure. Objectives  Use the relational comparison operators  Learn about AND logic  Learn about OR logic  Make selections.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Chapter 4 Making Decision Csc 125 C++ programming language Fall 2005.
Conditional Statement Chapter 8. Conditional Statements Are statements that check an expression then may or may not execute a statement or group of statement.
CHAPTER#3 STRUCTURED PROGRAM DEVELOPMENT IN C++ 1 st semester King Saud University College of Applied studies and Community Service Csc 1101.
Decisions  Relational operators  Operate on two numbers or two Strings  ==, !=, >, >=,
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
More Selection Executing Statements Selectively Chap. 7 (Read § & Part of Picture: Boolean Logic and Digital Design) 1.
CSC115 Introduction to Computer Programming Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA 19383
Control Structures - Selections - Repetitions/iterations (part 2) 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
Chapter 5 Selection Statements Mr. Dave Clausen La Cañada High School.
CSC115: Matlab Special Session Dr. Zhen Jiang Computer Science Department West Chester University.
More Selection Executing Statements Selectively Chap. 7 (Read § & Part of Picture: Boolean Logic and Digital Design) 1.
Chapter 5 – Decision Making. Structured Programming Sequence Selection Repetition yesno yes no.
Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA CSC141 Computer Science I.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
C++ for Engineers and Scientists Second Edition Chapter 4 Selection Structures.
Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA CSC530 Data Structures - LOOP 7/9/20161.
5.04 Apply Decision Making Structures
More on the Selection Structure
Selection (also known as Branching) Jumail Bin Taliba by
Introduction to C++ Programming Language
Decisions Chapter 4.
Chapter 4: Making Decisions.
Lecture 3- Decision Structures
Chapter 4: Decision Structures and Boolean Logic
Chapter 4: Making Decisions.
CSC115 Introduction to Computer Programming
CSC141 Computer Science I Zhen Jiang Dept. of Computer Science
Control Structures.
CSC115 Introduction to Computer Programming
MIS 3200 – Unit 4 Complex Conditional Statements else if switch.
CSC141 Computer Science I Zhen Jiang Dept. of Computer Science
Loop Development Zhen Jiang Dept. of Computer Science
IF if (condition) { Process… }
CSC115 Introduction to Computer Programming
Selection CSCE 121 J. Michael Moore.
CSC530 Data Structure - Decision
Control Structures: Selection Statement
Chapter 4: Decision Structures and Boolean Logic
CSC115 Introduction to Computer Programming
Conditionals.
Chapter 3: Selection Structures: Making Decisions
Boolean Expressions to Make Comparisons
Zhen Jiang West Chester University
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
Chapter 3: Selection Structures: Making Decisions
Computer Programming Basics
Control Structures: Selection Statement
Selection Control Structure
Chapter 4: Decision Structures and Boolean Logic
Presentation transcript:

CSC141 Computer Science I Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA 19383 zjiang@wcupa.edu

Selection (Decision) Introduction T/F selection MC selection

Selection (Decision) Rolling a dice. Sample execution (click on this link to try http://www.cis.temple.edu/~jiang/dice.exe Each button in the above sample has

No Yes Win/Lost? Double the money Bankrupt Restart

If else statement if (test) action 1 (statements 1) else action 2 (statements 2) //end if action 3 (statement 3)

No Yes Test by boolean expression Action 1 Action 2 Action 3

Boolean expression in test Simple expression Format <Value> <relational operators> <Value> Number value relational operators, Table 3-1, page 113 ==, !=, <, >, <=, >= !!! Number one error: “(a=2)” instead of “(a==2)” char value (not string!) relational operators ==, != (page 121)

Complex expression &&, ||, ! (Table 3-4, page 137) Truth table Precedence order, table 3-10, page 144 Number range, page 144-145

Ex 6: http://www.cs.wcupa.edu/~zjiang/141_ex6.pdf 11/27/2018

Development of a correct decision program Grade.java

Development Process Identify two exclusive options Implement each handling in different action parts Identify the situation (values) for option selection Make an expression so that all the situation value for option part 1 will lead to the test result (boolean value) true. Verify all the situation value for option part 2 will lead to the test false, otherwise, revise the above expression!

60, 61, 62, …, 100 ? 1, 2, …, 58, 59

Ex 7: http://www.cs.wcupa.edu/~zjiang/141_ex7.pdf 11/27/2018

If statement, Code 3-1, page 115 Relational operator ?, page 152 Multiple selection Nested if, Code 3-4, page 129 If else if, Code 3-5, page 133 Example: letter grade

Comments: Nested if for multiple selection problem If case 1 Else if … //end of case 2 if //End of case 1 if

Development of a correct multiple-decision program Letter grade

Ex 9 http://www.cs.wcupa.edu/~zjiang/141_ex9.pdf

Switch Switch([variable]) Case [constant value]: Break (or no break), Code 3-13, 3-14, page 157-159

Project 2 11 case If-else BMI expression simplification Discount Last else no if Nested if and multiple if Avg < 90 && test1 < 90 to attend the final Discount %, ()?