EE 222 Course 4 part 1 - PowerPoint PPT Presentation

1 / 31
About This Presentation
Title:

EE 222 Course 4 part 1

Description:

You will work on a 1-week project. get/print all course ... Marilyn Monroe. 3. EE 222 Course 4 - part 1. Today's Menu: Making decision = flow control ... – PowerPoint PPT presentation

Number of Views:99
Avg rating:3.0/5.0
Slides: 32
Provided by: cat946
Category:
Tags: course | marilyn | monroe | part

less

Transcript and Presenter's Notes

Title: EE 222 Course 4 part 1


1
EE 222 Course 4 - part 1
  • Announcements
  • Homeworks 1 and 2 were due Tuesday MIDNIGHT
  • Next week classes (T and TH) Pr. P Mlesna
  • You will work on a 1-week project
  • get/print all course material from Vista
  • IF it does not work I will send an email to every
    one and let you know where to get the material
    from
  • homework word (.doc) or pdf file
  • Thanks!

2
EE 222 Course 4 - part 1
  • Ever notice that 'what the hell' is always the
    right decision?
  • Marilyn Monroe

3
EE 222 Course 4 - part 1
  • Todays Menu
  • Making decision flow control
  • Conditional statements
  • if, if-else statements
  • switch
  • Loops
  • while, do-while, for loops
  • Controlling loops with continue and break

4
EE 222 Course 4
  • Objectives
  • Write proper flow charts
  • is it a while or a do-while?
  • Handle properly, master the use of
  • repetition structures
  • Selection structures

5
EE 222 Course 4
  • NOTE!!!!!!
  • In the following
  • boolean expression test condition whose result
    is
  • true or false 0 or 1 (_____ 1 and
    _____ 0)
  • Statement
  • a single instruction ENDED by or
  • a set of instructions all ENDED by

6
Conditional statement if
  • Syntax
  • if (boolean expression)
  • statement
  • What it does
  • Executes a statement/ block of code if and only
    if some boolean expression is true.
  • Note indent the statement in the
  • Flow chart look

7
Conditional statement if -flow chart
8
Conditional statement if -example
include using namespace std int
main() // Let's define the number that we
want the // player to guess as a constant
const int magicNumber 8 // Ask the player
for his guess cout between 1 and 10 " about..."
playerGuess // Give some feedback if the
guess is right if( playerGuess magicNumber
) cout right!" too smart for me!" done! return 0
9
Conditional statement if-else
  • Syntax
  • if (boolean expression)
  • statement
  • else
  • statement
  • What it does
  • Executes a statement/ block of code if and only
    if some boolean expression is true AND .
  • Gives a 2nd alternative
  • It is more user-friendly you know whats going
    on
  • Flow chart look

10
Conditional statement if-else flow chart
11
Conditional statement if-else -example
if( playerGuess magicNumber ) cout
cout 12
Conditional statements combination
  • Chained if-else statements
  • Nested conditional statements

if(boolean condition) statement else
if(boolean condition) statement else
if(boolean condition) statement
13
Conditional statements (contd)Nested
conditional statements
  • if( boolean condition )
  • statement
  • if(boolean condition)
  • statement
  • else if(boolean condition)
  • statement
  • else
  • statement

14
Conditional statement switch statement
  • Syntax
  • switch (expression)
  • case expression_value1 statement
  • case expression_value2 statement
  • .
  • case expression_valuen statement
  • default statement
  • NOTE expression can _____ be bool, int, char
  • What it does
  • Executes a statement/ block of code if and only
    if one expression value is true
  • Its equivalent to several _____ statements but
    its more neat

15
Conditional statement switch statement
16
Conditional statement switch statement example
  • include
  • using namespace std
  • int main()
  • // Let's read the grade
  • cout
  • char theGrade
  • cin theGrade
  • // Give an appropriate assessment
  • switch( theGrade )
  • case 'A'
  • cout
  • case 'B'
  • case 'C'
  • case 'D'

17
Conditional statement switch statement example
(contd)
  • Caution
  • If you forget a _____ in a switch statement, the
    computer may execute the _____ case statement.

18
Loop the while loop
  • Syntax
  • while(boolean expression/ test condition)
  • statement
  • What it does
  • Executes a statement/ block of code as long as
    the test condition holds true.
  • Flow chart look

19
Loop the while loop -flow chart
20
Loop the while loop example
  • include
  • using namespace std
  • int main()
  • // Let's define the number that we want the
  • // player to guess as a constant
  • const int magicNumber 8
  • // Let's initialize the player's guess with a
  • // bogus value that is not the right choice
  • int playerGuess -1
  • // Then, ask the player to guess until he
  • // gets it right
  • cout

21
Loop the while loop contd
  • Notes
  • If the test condition
  • Is _____ right from the start the block will not
    be executed even _____.
  • Is always true then its an _____ loop the
    computer has no way to stop repeating the block

22
Loop the do-while loop
  • Syntax
  • do
  • statement
  • while(boolean expression/ test condition)
  • What it does
  • Executes a statement/ block of code at least
    _____as long as the test condition holds true.
  • Flow chart look

23
Loop the do-while loop - flow chart
24
Loop the do-while loop - example
  • do
  • cin playerGuess
  • if( magicNumber playerGuess )
  • cout
  • else
  • cout
  • while( magicNumber ! playerGuess )

25
Loop the for loop
  • Syntax
  • for (initialisation of control variable
    test condition control variable update
    )
  • statement
  • What it does
  • Combines __________, _____ and _____
  • Executes a statement/ block of code as long as
    the test condition holds true.
  • Flow chart look

26
Loop the for loop - flow chart
27
Loop the for loop -example
//single initialization for(index1
index playerGuess
if( magicNumber playerGuess ) cout "You're right! Congratulations!\n" else
cout initialization for(index1,ca indexindex,c) cin playerGuess if(
magicNumber playerGuess ) cout "You're right! Congratulations!\n" else
cout
  • You can rewrite a _____ loop as a _____ loop

  • 28
    Combination loop, conditional statement
    do // Ask the player for his guess
    cin playerGuess // Give feedback
    if( magicNumber playerGuess ) cout "You're right! Congratulations!\n" else
    cout magicNumber ! playerGuess )
    29
    Questions
    • It helps me when
    • It would help me if
    • The question I have is

    30
    Course Lab part 2
    • Understand the problem
    • organize /summarize the results of a problem
      analysis IPO chart
    • Output ?
    • Input ?
    • Algorithm input processing?
    • Flow chart
    • And THEN .Programming

    31
    Your Turn
    • It helps me when
    • It would help me if
    • The question I have is
    Write a Comment
    User Comments (0)
    About PowerShow.com