Question: Relation between 2 4 - hour notation and 1 2 - hour notation is shown in the following table. Let mm be minutes. From the

Relation between 24-hour notation and 12-hour notation is shown in the following table. Let mm be minutes.
From the above table, we notice the processing of 24-hour format can be categorized by four categories,
depending on the value of hour. Each category is represented by different color.
In Task A, input time in 24-hour notation and print out the corresponding 12-hour notation. There are several
steps.
Name your source code convert_24_to_12.cpp
Input time in 24-hour notation to a string variable.
Extract values of hour and minute from input.
(a) Use find method of string class to find out the index of colon (, 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, stoi ("12") returns
12.
If hour is not in 0,23(that is, hour is smaller than 0 or hour is larger than 23) or minute is not in [0,59],
then print "invalid input" and return -1. The word "invalid" cannot be missed.
Depending on the values of hour, print out the corresponding 12-hour notation.
Here are some sample input/output.
(a) When hour or minute is not valid.
in c++ with explanation
Relation between 2 4 - hour notation and 1 2 -

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!