CISC1600: Computer Science I Lab 3

Purpose: In this lab assignment of CIS1600, we will continue to get familiar with the programming environment on storm, and practice using if/else and if statement to implement a program that checks the validity of time format.

Instruction: We will write a program that reads in a time in the 24-hour military time format, check for its validity, and if it's valid, output the time in the corresponding 12-hour am-pm block time. Please name your source code as timecheck.cpp.

Your program works as follows:

  1. Prompt the user to enter a time in military format
  2. Read in the time (read the hour, min and second separately)
  3. Check if the user input time is valid or not, if not, display an error message and exit the program.
    	A time is valid if the hour is between 0 and 24, and the minute is between 0 and 59, and
    	the second is between 0 and 59.
    	
  4. Convert the time to 12-hour am-pm clock time format and output the result
    Please review Military Time Chart to see how to convert 
    military time to 12-hour am-pm clock time. 
    

An example run of your program is as follows, where the user inputs are underlined, and the program output are shown in regular format:

$ ./a.out
Please enter a time in military format (HH:MM:SS):11:32:30
It's a valid time!
In 12-hour am-pm clock, this is 11:32:30 am.
Bye!
An example when the time entered is in the PM:
$ ./a.out
Please enter a time in military format (HH:MM:SS):14:30:30
It's a valid time!
In 12-hour am-pm clock, this is 2:30:30 pm.
Bye!
An example when the time entered is in midnight:
$ ./a.out
Please enter a time in military format (HH:MM:SS):24:42:40
It's a valid time!
In 12-hour am-pm clock, this is 12:42:40 midnight.
Bye!
The following example shows a run when the input is wrong:
$ ./a.out
Please enter a time in military format (HH:MM:SS):25:32:30
It's invalid! The hours must be between 0 and 24.
Bye!
The following example shows a run when the min is wrong:
$ ./a.out
Please enter a time in military format (HH:MM:SS):25:-9:30
It's invalid! The minutes must be between 0 and 59.
Bye!
Yet another example when the input is wrong:
$ ./a.out
Please enter a time in military format (HH:MM:SS):24:32:67
It's invalid! The second must be between 0 and 59.
Bye!
Coding Style Requirement:
  1. Please indent your code in as required.
  2. Use descriptive names for variables
  3. Use blank lines to separate the code into appropriate blocks
  4. Be sure to include comments to help others understand your program, and help yourself think!

How to submit

Please submit your program (which has to be named timecheck.cpp) to the following webpage: Lab3 submission link.

Please refer to Lab Instruction 4 here for how to 1) transfer your code from storm to your laptop, and then 2) submit your code to autograder.