Create a function called MilitaryToRegularTime that converts time in the military time format into the regular format. For example, convert 2249 to 10:49 pm. The function should receive a single int parameter that represents the military time. It should return a std::string that contains the regular time counterpart of the given military time. Please see the sample output below to guide the design of your program

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter5: Repetition Statements
Section5.6: Nested Loops
Problem 2E
icon
Related questions
Question

Military to Regular Time

Create a function called MilitaryToRegularTime that converts time in the military time format into the regular format. For example, convert 2249 to 10:49 pm.

The function should receive a single int parameter that represents the military time. It should return a std::string that contains the regular time counterpart of the given military time.

Please see the sample output below to guide the design of your program.

Note: Consider possible edge cases in user input to ensure your program works correctly.

Sample output:

Please enter the time in military time: 1433 The equivalent regular time is: 2:33 pm

Make sure that you examine the MilitaryToRegularTime function prototype in time_converter.h, implement it in time_converter.cc, and call it from inside of main.cc. You'll find that skeleton code has already been provided and you simply need to call the function, which can be called from inside main.cc because we include the header file via: #include "time_converter.h"

main.cc file

#include <iostream>
  #include <string>
   
  #include "time_converter.h"
   
  int main() {
  int military_time = 0;
  std::cout << "Please enter the time in military time: ";
  std::cin >> military_time;
   
  // TODO: Call your function to convert from military time to regular time
  // and assign its result to regular_time.
  std::string regular_time;
   
  std::cout << "The equivalent regular time is: " << regular_time << "\n";
  return0;
  }

 

time_converter.cc file 

#include <iostream>
  #include <string>
   
  std::string MilitaryToRegularTime(int military_time) {
  // TODO: convert military_time to regular time in string format.
  // Hint: std::to_string() converts a given integer to a string.
  return"";
  }

 

time_converter.h file 

#include <iostream>
  #include <string>
   
  // Converts the time in military format to regular format.
  std::string MilitaryToRegularTime(int military_time);
Sample output:
Please enter the time in military time: 1433
The equivalent regular time is: 2:33 pm
Transcribed Image Text:Sample output: Please enter the time in military time: 1433 The equivalent regular time is: 2:33 pm
Military to Regular Time
Create a function called MilitaryToRegularTime that converts time in the military time format into the regular format. For example,
convert 2249 to 10:49 pm.
The function should receive a single int parameter that represents the military time. It should return a std::string that contains the
regular time counterpart of the given military time.
Please see the sample output below to guide the design of your program.
Note: Consider possible edge cases in user input to ensure your program works correctly.
Sample output:
Please enter the time in military time: 1433
The equivalent regular time is: 2:33 pm
Make sure that you examine the MilitaryToRegularTime function prototype in time_converter.h, implement it in time_converter.cc,
and call it from inside of main.cc. You'll find that skeleton code has already been provided and you simply need to call the function, which
can be called from inside main.cc because we include the header file via: #include "time_converter.h"
Transcribed Image Text:Military to Regular Time Create a function called MilitaryToRegularTime that converts time in the military time format into the regular format. For example, convert 2249 to 10:49 pm. The function should receive a single int parameter that represents the military time. It should return a std::string that contains the regular time counterpart of the given military time. Please see the sample output below to guide the design of your program. Note: Consider possible edge cases in user input to ensure your program works correctly. Sample output: Please enter the time in military time: 1433 The equivalent regular time is: 2:33 pm Make sure that you examine the MilitaryToRegularTime function prototype in time_converter.h, implement it in time_converter.cc, and call it from inside of main.cc. You'll find that skeleton code has already been provided and you simply need to call the function, which can be called from inside main.cc because we include the header file via: #include "time_converter.h"
Expert Solution
Step 1

main.cc file
#include <iostream>
   #include <string>
    
   #include "time_converter.h"
    
   int main() {
   int military_time = 0;
   std::cout << "Please enter the time in military time: ";
   std::cin >> military_time;
    
   // TODO: Call your function to convert from military time to regular time
   // and assign its result to regular_time.
   std::string regular_time;
 regular_time = MilitaryToRegularTime(military_time);
    
   std::cout << "The equivalent regular time is: " << regular_time << "\n";
   return0;
   }

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Function Arguments
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:
9780357392676
Author:
FREUND, Steven
Publisher:
CENGAGE L
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT