Review the following: if-else One branch if Conditional operators Logical operators Switch statement Conditional expression operator Nested ifs if –else.

Slides:



Advertisements
Similar presentations
Control Statements. Define the way of flow in which the program statements should take place. Control Statements Implement decisions and repetitions.
Advertisements

259 Lecture 10 Spring 2013 Advanced Excel Topics – More User Defined Functions; Conditional Statements.
If Statements & Relational Operators Programming.
July 13 th.  If/ Else if / Else  Variable Scope  Nested if/else's  Switch statements  Conditional Operator.
1 Engineering Problem Solving With C++ An Object Based Approach Chapter 3 Control Structures.
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
If Statements. COMP104 If / Slide 2 Three Program Structures * Sequence - executable statements which the computer processes in the given order * Choice.
CS 117 Spring 2002 Review for Exam 2 March 6, 2002 open book, 1 page of notes.
Selection. Computer Programming 2 Objectives Examine if statement in more detail Study use of switch statement to implement multialternative selections.
Quiz 1 Exam 1 Next Week. Nested if Statements if (myGrade >= 80) if (myGrade >= 90) cout
3.5 Quadratic Equations OBJ:To solve a quadratic equation by factoring.
4.8: Quadratic Formula HW: worksheet
More on Input Output Input Stream : A sequence of characters from an input device (like the keyboard) to the computer (the program running). Output Stream.
CPS120: Introduction to Computer Science Decision Making in Programs.
OBJ: To solve a quadratic equation by factoring
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
CONTROLLING PROGRAM FLOW
Solving Quadratic Equations. Solving by Factoring.
Pre-Calculus Section 1.5 Equations Objectives: To solve quadratics by factoring, completing the square, and using the quadratic formula. To use the discriminant.
QuadraticEquation class. Background A quadratic equation is a second-order polynomial equation in a single variable x, ax 2 + bx + c = 0 (with a≠0.)
Perform Calculations and Control Flow Telerik Software Academy Learning & Development Team.
1 Example: Solution of Quadratic Equations We want to solve for real values of x, for given values of a, b, and c. The value of x can be determined from.
1 2. Program Construction in Java. 2.4 Selection (decisions)
Refer to Ivor Horton’s Beginning ANSI C++ The Complete Language, 3rd Ed. APress Media, LLC. Choices and Decisions if statement if-else statement Relational.
Copyright 2003 Scott/Jones Publishing Making Decisions.
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
Review the following : Flowcharting Variable declarations Output Input Arithmetic Calculations Conditional Statements Loops.
Chapter 4 Selection: the if-else and switch-case instructions.
PEG200/Saidatul Rahah 1.  Selection Criteria › if..else statement › relational operators › logical operators  The if-then-else Statement  Nested if.
Chapter Making Decisions 4. Relational Operators 4.1.
C++ Programming Lecture 7 Control Structure I (Selection) – Part II The Hashemite University Computer Engineering Department.
Selection Control Structures (L08) * Selection Criteria * if Statements * The if-else Statement Selection Control Structure Dr. Ming Zhang.
 for loop  while loop  do-while loop for (begin point; end point ; incrementation ) { //statements to be repeated }
Solving Quadratic Formula using the discriminant.
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,
Solving Quadratic Equations. Factor: x² - 4x - 21 x² -21 a*c = -21 b = -4 x + = -21 = x 3x3x x 3 (GCF) x-7 (x – 7)(x + 3)
CPS120: Introduction to Computer Science Decision Making in Programs.
Copyright © 2012 Pearson Education, Inc. Publishing as Addison Wesley R.5 The Basics of Equation Solving  Solve linear equations.  Solve quadratic equations.
CPS120: Introduction to Computer Science Decision Making in Programs.
Lecture 7 Computer Programming -1-. Conditional Statements 1- if Statement. 2- if ….. else Statement. 3- switch.
Selection Control Structures 2 (L09) * Nested if Statements * The if-else Chain * Exercise: if, if-else, nested if, and if-else chain Selection Control.
Chapter 3. Control Structure C++ Programing. Conditional structure C++ programming language provides following types of decision making statements. Click.
CSE202: Lecture 5The Ohio State University1 Selection Structures.
Mathematical Manipulation Data types Operator precedence Standard mathematical functions Worked examples.
 By the end of this section you should be able to: ◦ Differentiate between sequence, selection, and repetition structure. ◦ Differentiae between single,
SOLVE QUADRATIC EQUATIONS BY USING THE QUADRATIC FORMULA. USE THE DISCRIMINANT TO DETERMINE THE NUMBER AND TYPE OF ROOTS OF A QUADRATIC EQUATION. 5.6 The.
Selection (if-then-else) Programming Has 3 Types of Control: Sequential (normal): Control of Execution Proceeds One after the Other Selection (if-then-else):
 2006 Pearson Education, Inc. All rights reserved if…else Double-Selection Statement if – Performs action if condition true if…else – Performs.
1 Chapter 4 - Control Statements: Part 1 Outline 4.1 Introduction 4.4 Control Structures 4.5 if Selection Structure 4.6 if/else Selection Structure 4.7.
Branching statements.
The Quadratic Formula..
生查子 ~ 歐陽修 去年元夜時,花市燈如晝, 月上柳梢頭,人約黃昏後; 今年元夜時,月與燈依舊, 不見去年人,淚濕春衫袖。
Chapter 4: Making Decisions.
Solving quadratics methods
Solving Quadratic Equations
Sum and Product of Roots
CSC113: Computer Programming (Theory = 03, Lab = 01)
Chapter 4: Making Decisions.
Expressions and Control Flow in JavaScript
Worksheet Key 9 11/14/2018 8:58 PM Quadratic Formula.
Flow Control Statements
Review: Simplify.
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.
Decisions, decisions, decisions
Chapter 3 Quadratic Equations
C++ Programming Lecture 7 Control Structure I (Selection) – Part II
quadratic formula. If ax2 + bx + c = 0 then
Presentation transcript:

Review the following: if-else One branch if Conditional operators Logical operators Switch statement Conditional expression operator Nested ifs if –else if Program using conditional statements

if ( condition ) { //code for true branch } else { //code for false branch } condition True branch False branch TF

if ( x >= y ) { cout << “x is greater than or equal to y”; } else { cout << “x is less than y”; }

> greater than <less than >=greater than or equal <=less than or equal ==equal !=not equal

if (condition) { //true branch } condition True branch TF

if ( x > 7 ) { x = x +3; cout << x; }

&& logical and || logical or ! logical not

if ( a > b && c < d ) { cout << “both conditions true”; } if (x 18 ) {cout << “either condition is true”; if (! Prime) { cout << “ number is not prime”; } (1) (2) (3)

switch (variable) { case a: statements case b: statements default: statements }

switch (x ) { case 6 : cout << “x is 6”; break; case 3 : cout << “x is 3”; break; default: cout << “x is not 6 or 3 “; } x==6 x is 6 x==3 x is 3 x is not 6 or 3 t t f f

(condition) ? true branch : false branch;

Big = (a>b) ? a : b ; a > b Big = aBig = b TF

c > d X=2X=3 t t a>b X=1 f f if (a > b) { if ( c > d) { X = 3; } else { X = 2; } else { X = 1; }

if ( g > 89) cout << “Grade = A”; else if (g > 79 ) cout << “Grade = B”; else if (g > 69) cout << “Grade = C;” else cout << “Grade = “Bad”; g> 89 g > 79 g> 69 Grade = Bad Grade = A Grade = B Grade = C

Find the roots of the quadratic equation ax² + bx + c = 0 The 2 roots are found using the formula: _______ -b ± √ (b²-4ac) a

Start End Prompt for & read in a,b,c D =disciminant D>0 && a != 0 Calculate 2 roots r1,r2 r1,r2 Roots imaginary or a == 0 T F

#include #include using std::cin; using std::cout; using std::endl; int main() { double a, b, c; cout > a >> b >> c; double d = b * b * a * c; if ((d >= 0.0) && (a != 0.0)) { double x1 = (-b + sqrt(d)) / (2.0 * a); double x2 = (-b - sqrt(d)) / (2.0 * a); cout << "x1 = " << x1 << " x2 = " << x2 << endl; } else cout << "the roots are imaginary or a equals 0" << endl; return 0; }

double a, b, c; cout > a >> b >> c;

double d = b * b * a * c;

if ( (d >= 0.0) && (a != 0.0) )

{ double x1 = (-b + sqrt(d)) / (2.0 * a); double x2 = (-b - sqrt(d)) / (2.0 * a); cout << "x1 = " << x1 << " x2 = " << x2 << endl; }

else cout << "the roots are imaginary or a equals 0" << endl;

Review the following: if-else One branch if Conditional operators Logical operators Switch statement Conditional expression operator Nested ifs if –else if Program using conditional statements