Computer Science Homework Help

Santa Monica College Write a C++ Program Computer Programming Task

 

in the space below write a c++ program that converts 12-hour time (including AM/PM) to 24 hour time. You must define an exception class called InvalidTime wherein if the user enters an out of range time or gibberish characters, your program will throw and catch InvalidTime.

For example, make your class support the following code:

TwelveHourTime sevenAM ( “7:00 AM” );

cout<< sevenAmM.twentyFourTime () <<endl;; //prints “ 07:00 “

TwelveHourTime eightPM ( “ 8:30 PM “ );

cout<< eightPM.twentyFourTime () << endl; // prints “20:30”

try

{

TwelveHourTime bad ( “ asef32422 ” );

//the previous line should throw an InvalidTime exception

} catch ( InvalidTime )

{

cout<< “ caught error as expected “ <<endl;

}