online exsam

profilefadoo
cs1150_module8-espressoexample_kzw.pdf

3/9/2015

1

The Espresso Program

 The program computes ? The price of an espresso drink

 based on:

– The price of drink

– The size of drink

– The number of shots

– Plus tax

The following slides with a black background are adapted from Pearson Addison Wesley with permission of book

rep.

15 Wright State University, Department of Computer Science Dr. Kera Z. Watkins, Computer Science & Engineering

CS1160 Intro to Programming

CS1150

Introduction to Computer Science

The Espresso Program

 The following lines are executed with the purchase of a double tall latte:

 Line 3 is executed: The test drink == "espresso" fails, because the variable drink has the value "latte“ The ‘then’ statement is skipped

• double • 2 shots

• tall • 12 oz

16 Wright State University, Department of Computer Science Dr. Kera Z. Watkins, Computer Science & Engineering

CS1160 Intro to Programming

CS1150

Introduction to Computer Science

The Espresso Program

 The purchase of a double tall latte:

2. Line 4 is executed: The test drink == "latte" || drink == "cappuccino“ has a true outcome

3/9/2015

2

17 Wright State University, Department of Computer Science Dr. Kera Z. Watkins, Computer Science & Engineering

CS1160 Intro to Programming

CS1150

Introduction to Computer Science

The Espresso Program

 The purchase of a double tall latte:

3. Line 4a is executed: The ounce == 8 test is false, so the then statement is skipped

4. Line 4b is true: The ounce == 12 test has price = 2.35

18 Wright State University, Department of Computer Science Dr. Kera Z. Watkins, Computer Science & Engineering

CS1160 Intro to Programming

CS1150

Introduction to Computer Science

The Espresso Program

 The purchase of a double tall latte:

5. Line 4c is executed: The ounce == 16 test fails, so its then statement is skipped

6. Line 5 is executed: The drink == "Americano" test fails, so its then statement is skipped

19 Wright State University, Department of Computer Science Dr. Kera Z. Watkins, Computer Science & Engineering

CS1160 Intro to Programming

CS1150

Introduction to Computer Science

The Espresso Program

 The purchase of a double tall latte:

7. Line 6 is executed: This causes the value of shots minus 1 to be multiplied by .50, resulting in the value .50, which is added to price, yielding price ⇐⇒ 2.85

3/9/2015

3

20 Wright State University, Department of Computer Science Dr. Kera Z. Watkins, Computer Science & Engineering

CS1160 Intro to Programming

CS1150

Introduction to Computer Science

The Espresso Program

 The purchase of a double tall latte:

8. Line 7 is executed: Current value of price is multiplied by taxRate, resulting in 0.25, which is added to price to compute the final value of 3.10, which is assigned to price