Question: Input time in 1 2 - hour notation and print out the corresponding 2 4 - hour notation. There are several steps. Name your source

Input time in 12-hour notation and print out the corresponding 24-hour notation. There are several steps.
Name your source code convert_12_to_24.cpp
Input time in 12-hour notation to a string variable.
(a) The format of 12-hour notation is hh:mm AM or hh:mm PM , where hh is in 1,12 and mm is in 0,59,
the input may contain space.
We cannot use cin variablellame; to read the input, since stops at the first space or return
key, whichever is encounted first.
To read input with spaces, use getline(cin, variablellame); read a line, and put the input line to
veriablellame.
Operator read an int, a double number, a string, cdots, to the corresponding variable.
Function getline read a line and save that line to a string variable.
Extract the last two characters from input, it should be either AM or PM.
Extract values of hour and minute from input.
(a) Use find method of string class to find out the index of colon (i), a character separating hour and
minute.
(b) Use substr method of string class to get the substring representing hour and minute.
(c) Use stoi function to convert a string to the corresponding integers. For example, sto1("12") returns
If hour is not in 1,12(that is, hour is smaller than 0 or hour is larger than 12) or minute is not in 0,59,
then print "invalid input" and return-1. The word "invalid" cannot be missed.
(a) Optional (will not test in gradescope script): test whether input is ended with either "AM" or "PM".
Depending on the values of suffix "AM" or "PM" and hour, print out the corresponding 24-hour notation.
Input time in 1 2 - hour notation and print out

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!