CS150 Introduction to Computer Science 1

Slides:



Advertisements
Similar presentations
The "if structure" is used to execute statement(s) only if the given condition is satisfied.
Advertisements

CS107 Introduction to Computer Science Lecture 3, 4 An Introduction to Algorithms: Loops.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
1 9/15/06CS150 Introduction to Computer Science 1 Combined Assignments, Relational Operators, and the If Statement.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
1 9/24/07CS150 Introduction to Computer Science 1 Relational Operators and the If Statement.
1 Lecture 8:Control Structures I (Selection) (cont.) Introduction to Computer Science Spring 2006.
1 9/26/08CS150 Introduction to Computer Science 1 Logical Operators and if/else statement.
1 9/28/07CS150 Introduction to Computer Science 1 Loops section 5.2, 5.4, 5.7.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
1 10/11/06CS150 Introduction to Computer Science 1 do/while and Nested Loops.
Announcements Quiz 1 Posted on blackboard Handed Back (and Gone Over)Next Monday “Only a Quiz” Counts 5% of Final Grade Exam 1 Counts 10%
CS150 Introduction to Computer Science 1
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
1 10/9/06CS150 Introduction to Computer Science 1 for Loops.
1 9/25/06CS150 Introduction to Computer Science 1 Nested Ifs, Logical Operators, exit() Page 194.
1 CS150 Introduction to Computer Science 1 Relational Operators and the If Statement 9/22/08.
The If/Else Statement, Boolean Flags, and Menus Page 180
Chapter 4 MATLAB Programming Logical Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
1 9/28/07CS150 Introduction to Computer Science 1 Logical Operators and if/else statement.
19/5/2015CS150 Introduction to Computer Science 1 Announcements  1st Assignment due next Monday, Sep 15, 2003  1st Exam next Friday, Sep 19, 2003  1st.
Decision II. CSCE 1062 Outline  Boolean expressions  switch statement (section 4.8)
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
MULTIPLE ALTERNATIVES IF… THEN… ELSEIF SELECT CASE.
1 09/15/04CS150 Introduction to Computer Science 1 Life is Full of Alternatives Part 2.
111/18/2015CS150 Introduction to Computer Science 1 Announcements  I have not graded your exam yet.
CSC 107 – Programming For Science. Today’s Goal  Discuss writing functions that return values  return statement’s meaning and how it works  When and.
11/10/2016CS150 Introduction to Computer Science 1 Last Time  We covered “for” loops.
COMP Loop Statements Yi Hong May 21, 2015.
1 9/26/05CS150 Introduction to Computer Science 1 Life is Full of Alternatives.
Introduction to Programming
What Actions Do We Have Part 1
CS 1430: Programming in C++ No time to cover HiC.
for Repetition Structures
Chapter 4 MATLAB Programming
CSC113: Computer Programming (Theory = 03, Lab = 01)
Numbering System TODAY AND TOMORROW 11th Edition
CS150 Introduction to Computer Science 1
Unary Operators ++ and --
Repetition Control Structure
Summary Two basic concepts: variables and assignments Basic types:
CS150 Introduction to Computer Science 1
CS150 Introduction to Computer Science 1
CS150 Introduction to Computer Science 1
CS150 Introduction to Computer Science 1
Let’s all Repeat Together
switch Selection Structure
CS150 Introduction to Computer Science 1
Decision I (if Statement)
Introduction to Programming
CS150 Introduction to Computer Science 1
Life is Full of Alternatives
Programming Concepts and Database
CS150 Introduction to Computer Science 1
Understanding Conditions
CS2011 Introduction to Programming I Selections (I)
Selection Structures: Single-alternative
do/while Selection Structure
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
CS150 Introduction to Computer Science 1
Life is Full of Alternatives
CS150 Introduction to Computer Science 1
Life is Full of Alternatives
Chapter 4: Selection Structures: if and switch Statements
CS150 Introduction to Computer Science 1
Agenda Warmup Review Finish 1.2 Assignments Lesson 1.3 (If Statements)
Functions Divide and Conquer
Life is Full of Alternatives Part 3
Agenda Warmup Review Finish 1.2 Assignments Lesson 1.3 (If Statements)
Presentation transcript:

CS150 Introduction to Computer Science 1 Announcements 1st Assignment due Today! 1st Exam next Friday, Sep 19, 2003 1st Quiz next week 4/16/2019 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 If statements Single alternative: if (condition) or if (condition) statement; { next statement; statements; } next statement; If condition is true, statement(s) following if execute if condition is false, statement(s) following if are skipped 4/16/2019 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 Examples if (x >= 0) cout << “x is positive” << endl; if (x < 0) x = -x; if ((x == 0) && (y == 0)) { x = 1; y = 1; } 4/16/2019 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 Two Alternative if (condition) if (condition) statementT; { else statementsT; statementF; } else { statementsF; } 4/16/2019 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 Examples if (x >= 0) cout << “x is positive” << endl; else cout << “x is negative” << endl; 4/16/2019 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 More Examples x = 25.0; if (y != (x - 10.0)) x = x - 10.0; else x = x/2.0; if ((y < 15.0) && (y >= 0.0)) x = 5*y; x = 2*y; 4/16/2019 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 Program Write a program that inputs 2 numbers and outputs the larger Write a program that inputs 3 numbers and outputs the largest Write a program that inputs a number and outputs if its even or odd 4/16/2019 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 Program Write a program that computes the area of a triangle or a rectangle based on the user typing in ‘t’ or ‘r’ first. 4/16/2019 CS150 Introduction to Computer Science 1

Multiple Alternative Ifs if (condition1) statement1; else if (condition2) statement2; … else defaultstatement; 4/16/2019 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 Program Write a program that displays a letter grade corresponding to an exam score 90 - 100 A 80 - 89 B 70 - 79 C 60 - 69 D 0-59 F 4/16/2019 CS150 Introduction to Computer Science 1