3. 24-hour time (also known in the U.S. as military time) is widely used around the world. Time is expressed as hours since midnight. The day starts at 0000, and ends at 2359. • Write a program that converts am/pm time to 24-hour time. • Hints: o Think of how each hour should be handled. 12:00 am -12:59 am becomes what? 8:00 am becomes what? 12:00 pm? 1:00 pm? Group the hours into cases that should be handled similarly (e.g., 1:00 am to 11:00 am are handled the same). o Declare variables for hoursAmPm, minAmPm, and hours24. Note that minutes for 24-hour time remain the same as for am/pm, so no extra variable is needed. o Use an if-else statement to detect each case, and set the hours24 appropriately. o When outputting hour24, check if the hour is 0-9 (just check for < 10). If so, output a "0". So 7 will be output as 07. Do the same when outputting the minutes. 4. Make sure to follow the Grading Rubric and Academic Integrity guidelines outlined in the syllabus. Expected Program Output: Test Run #1 2:30 pm 1430 Test Run #2 12:01 am 0001

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
icon
Concept explainers
Question

C++ please - 24-hour time (also known in the U.S. as military time) is widely used around the world. Time is expressed as hours since midnight. The day starts at 0000, and ends at 2359. Write a program that converts am/pm time to 24-hour time. If the input is 2:30 pm, the output should be 1430. If the input is 12:01 am, the output should be 0001.

Hints:

  • Think of how each hour should be handled. 12:00 am -12:59 am becomes what? 8:00 am becomes what? 12:00 pm? 1:00 pm? Group the hours into cases that should be handled similarly (e.g., 1:00 am to 11:00 am are handled the same).

  • Declare variables for hoursAmPm, minAmPm, and hours24. Note that minutes for 24-hour time remain the same as for am/pm, so no extra variable is needed.

  • Use an if-else statement to detect each case, and set the hours24 appropriately.

  • When outputting hour24, check if the hour is 0-9 (just check for < 10). If so, output a "0". So 7 will be output as 07. Do the same when outputting the minutes.

#include <iostream>

int main() 
{
   std::string time;
   
   std::cout << "Enter the time as (hh:mm xm) ";
   std::getline(std::cin, time);
   
   /* Type your code here. */

   return 0;
}

3. 24-hour time (also known in the U.S. as military time) is widely used around the world.
Time is expressed as hours since midnight. The day starts at 0000, and ends at 2359.
• Write a program that converts am/pm time to 24-hour time.
• Hints:
o Think of how each hour should be handled. 12:00 am -12:59 am becomes what?
8:00 am becomes what? 12:00 pm? 1:00 pm? Group the hours into cases that
should be handled similarly (e.g., 1:00 am to 11:00 am are handled the same).
o Declare variables for hoursAmPm, minAmPm, and hours24. Note that minutes for
24-hour time remain the same as for am/pm, so no extra variable is needed.
o Use an if-else statement to detect each case, and set the hours24 appropriately.
o When outputting hour24, check if the hour is 0-9 (just check for < 10). If so, output
a "0". So 7 will be outp as 07. Do the same when outputting the minutes.
4. Make sure to follow the Grading Rubric and Academic Integrity guidelines outlined in
the syllabus.
Expected Program Output:
Test Run #1
2:30 pm
1430
Test Run #2
12:01 am
0001
Transcribed Image Text:3. 24-hour time (also known in the U.S. as military time) is widely used around the world. Time is expressed as hours since midnight. The day starts at 0000, and ends at 2359. • Write a program that converts am/pm time to 24-hour time. • Hints: o Think of how each hour should be handled. 12:00 am -12:59 am becomes what? 8:00 am becomes what? 12:00 pm? 1:00 pm? Group the hours into cases that should be handled similarly (e.g., 1:00 am to 11:00 am are handled the same). o Declare variables for hoursAmPm, minAmPm, and hours24. Note that minutes for 24-hour time remain the same as for am/pm, so no extra variable is needed. o Use an if-else statement to detect each case, and set the hours24 appropriately. o When outputting hour24, check if the hour is 0-9 (just check for < 10). If so, output a "0". So 7 will be outp as 07. Do the same when outputting the minutes. 4. Make sure to follow the Grading Rubric and Academic Integrity guidelines outlined in the syllabus. Expected Program Output: Test Run #1 2:30 pm 1430 Test Run #2 12:01 am 0001
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 7 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

This doesn't solve the problem nor does it implement the below. 

 

int main() 
{
   std::string time;
   
   std::cout << "Enter the time as (hh:mm xm) ";
   std::getline(std::cin, time);
   
   /* Type your code here. */

   return 0;
}

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Operators
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education