java programing

profilesalansari95
177018625_cps_examplee2_3.pdf

CPS 150.03 First Quiz Algorithms & Programming I

Dr. N. Bashias

Spring 2017 Name: _________________________________________________

Carefully read and answer the following question on this quiz.

We have been asked to write a program that reads the subtotal and the gratuity (tip) rate, then computes

the tip and total (of subtotal and tip).

1. Write the Contract for the above program.

CalcTippedTotal : +number, +number ; number, number

2. Based on your Contract, write a Purpose Statement for this program.

program is given, as user input, (1) a subtotal (pos. number as var. subTotal) and (2) a tip rate (pos.

number as var. tipRate); program calculates and outputs (1) the tip amount (number as var. tipAmt)

and (2) the total (number as var. total)

3. Based on your Contract and Purpose Statement, write some examples for this program. Make sure you

include counter-examples (i.e., erroneous examples that would result in aborting the program)

Page 1 of 2

shahad
shahad
shahad

CPS 150.03 First Quiz Algorithms & Programming I

Dr. N. Bashias

Spring 2017 Name: _________________________________________________

4. Based on your Contract, Purpose Statement and examples, write an algorithm for this program.

1. get subTotal as user input

2. if subTotal is zero or negative, ABORT

3. get tipRate as user input

4. if tipRate is zero or negative, ABORT

5. calculate tipAmt as subTotal × (tipRate ÷ 100)

6. calculate total as subTotal + tipAmt

7. output subTotal, tipRate

8. output tipAmt, total

9. end program

Page 2 of 2

shahad
shahad