Assignment #4 - Functions

Due: Tues, Oct 25 (due date revised because setting on submission site was wrong. Please submit now!)

Objective

This assignment will consist of writing a couple of small programs that involve practice writing and calling functions.

Task

Write the following programs, each in a separate file. Filenames should be: (Note that the filenames are all lowercase)

Exercise 1

Filename: seconds.cpp
  1. Write a function called Seconds that takes in three integer parameters (representing hours, minutes, and seconds) and returns the number of seconds since the last time the clock "struck 12" (i.e. was at 12:00:00 -- AM or PM doesn't matter since you're not tracking this).
     
  2. To test this function, write a main() routine (in the same file) that prompts the user to enter hours, minutes, and seconds for two different clock times; then uses the Seconds function to calculate the shortest amount of time in seconds between the two times (both of which are within one 12-hour cycle of the clock); the print out the number of seconds since "striking 12" for both clocks, as well as the number of seconds between the two clock times

Sample Run 1:

(user input underlined)
  Input first clock time...
  Hours: 6
  Minutes: 45
  Seconds: 30

  Input second clock time...
  Hours: 4
  Minutes: 50
  Seconds: 12

  It's been 24330 seconds since the first clock struck 12:00
  It's been 17412 seconds since the second clock struck 12:00
  The two times are 6918 seconds apart.

Sample Run 2:

(user input underlined)
  Input first clock time...
  Hours: 12
  Minutes: 43
  Seconds: 16

  Input second clock time...
  Hours: 7
  Minutes: 11
  Seconds: 59

  It's been 2596 seconds since the first clock struck 12:00
  It's been 25919 seconds since the second clock struck 12:00
  The two times are 23323 seconds apart.

Exercise 2

Filename: dice.cpp
  1. Write a function called RollDice that returns the result from rolling two standard six-sided dice)
  2. To test this function, write a main() routine that does the following:
  3. Note: When you seed the random number generator, go ahead and use the time function, as illustrated in the class notes

Sample Run 1

(user input underlined)
How many times would you like to roll the two dice? 10000

Snake eyes (double 1s) appeared
   268 times
   2.68 % of the time

A roll of 7 appeared
   1675 times
   16.75 % of the time

Sample Run 2

(user input underlined)
How many times would you like to roll the two dice? 500000

Snake eyes (double 1s) appeared
   13706 times
   2.74 % of the time

A roll of 7 appeared
   83300 times
   16.66 % of the time

Sample Run 3

(user input underlined)
How many times would you like to roll the two dice? 500000

Snake eyes (double 1s) appeared
   13921 times
   2.78 % of the time

A roll of 7 appeared
   83789 times
   16.76 % of the time

Requirements for all programs


Submitting:

Program submissions should be done through the submission web page, linked from the main course web site. Submit the files:
 seconds.cpp
 dice.cpp