java programing

profilesalansari95
177018625_cps_example_2.pdf

CPS 150.04 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 prompts the user to enter the number of minutes, and

displays the number of years and days for the given minutes.

For simplicity, assume a year has 365 days.

1. Write the Contract for the above program.

YearsAndDays : number ; number, number

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

program gets the number of minutes from the user (non-neg. number as var. numMins), then

calculates and outputs (1) the whole number of years, and (2) the whole number of days represented

by the input (the vars. numYears and numDays, respectively).

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
shahad
shahad
shahad

CPS 150.04 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 numMins as user input

2. if numMins is negative, ABORT

3. calculate numDays as the quotient of numMins ÷ 1440 (# of minutes in a day)

4. calculate numYears as the quotient of numDays ÷ 365

5. re-calculate numDays as the remainder of numDays ÷ 365

6. output numMins

7. output numYears and numDays

8. end program

Page 2 of 2

shahad
shahad