Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In c++ Background For some reason, the U.S. military has been getting their time as the number of hours (double) or as the number of
In c++
Background For some reason, the U.S. military has been getting their time as the number of hours (double) or as the number of minutes (unsigned int) as the time elapsed from 00:00. Your task as their software engineer is to convert these measurements to a more readable format. More specifically, your task is to implement an overloaded function to convert either of these types of inputs to military time. Put simply, military time displays the hour count (0-23 inclusive) followed by the minute count ( 059 inclusive). If either the hour count or minute count is less than 10 (i.e., a single digit), you will need to prepend a 0 to it in your final answer. Assignment Prompt You are writing a program to convert a time measurement (can be minutes provided as integers or hours provided as doubles) to the time in the day (24 hours). Return the time in the format "hour":"minute". Note that if your minute and/or hour count is less than 10, you will need to prepend a 0 (i.e., 14:9 should be 14:09) as if you were reading the time on a digital clock displaying military time. For example, ToMilitaryTime (8.4) = "08:24" OR ToMilitaryTime(389) = "06:29". When a double (representing the number of hours passed), round the time to the nearest minute using round () (\#include ). Note that the round ( ) function returns a double. How can you convert this to a string? Furthermore, if you are given input that falls out of the range of military time (i.e., an hour or minute count is less than 0 OR hour count is >24.0 OR minute count > 1440), you will need to throw an exception. Functions to Implement \( \begin{array}{cc}1 & \text { std::string ToMilitaryTime(unsigned int num_mins); } \\ 2 & \text { // Example: ToMilitaryTime }(389) \Rightarrow " 06: 29 " \\ 3 & / / \text { Example: ToMilitaryTime }(844) \Rightarrow " 14: 04 " \\ 4 & / / \text { Example: ToMilitaryTime }(1440) \Rightarrow " 00: 00 " \\ 5 & \\ 6 & \text { std: :string ToMilitaryTime(double num_hours) } \\ 7 & / / \text { Example: ToMilitaryTime }(8.4) \Rightarrow " 08: 24 " \\ 8 & / / \text { Example: ToMilitaryTime }(14.4432) \Rightarrow " 14: 27 " \\ 9 & \text { // Example: ToMilitaryTime }(24.0) \Rightarrow " 00: 00 "\end{array} \) function-overloading-military-time function-overloading-military-time function-overloading-military-time driver.cc military_time.hpp military_time.cc CS128A+EditorStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started