Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

) Reference Parameters (returning multiple values): Write a C++ function that co

ID: 673887 • Letter: #

Question

) Reference Parameters (returning multiple values): Write a C++ function that converts standard time to military time. Inputs include hours and minutes in standard time and a character equal to ‘a’ for am or ‘p’ for pm.

         The function call might look like:

                  MilitaryTime(SHour, SMin, AorP, MHour, MMin);

Also write a main program to prompt the user for the inputs (such as 1:30 am), call the function, and display the input and the output in the following form:

12:30 am = 0030

2:30 am = 0230

3:30 pm = 1530

12:00 am = 0000

Run the program for the four

Hint: Using fill(’0’) is an easy way to show leading zeros

Explanation / Answer

#include<iostream>
using namespace std;
void MilitaryTime(int SHour, int SMin,char AorP)
{
   int temp;
if (AorP=='a')
{
   if(SHour==12)
   {
       temp=0;
       cout<<" "<<SHour<<":"<<SMin<<" am = 0"<<temp<<SMin;
   }
  
   else
   {
       if(SHour>9)
       cout<<" "<<SHour<<":"<<SMin<<" am = "<<SHour<<SMin;
       else
       cout<<" "<<SHour<<":"<<SMin<<" am = 0"<<SHour<<SMin;
   }      
}
else
{  
   temp=12+SHour;  
   cout<<" "<<SHour<<":"<<SMin<<" pm = "<<temp<<SMin;
}
}
int main()
{
int hr,min;
char c;
cout<<"enter the hours in standard time: ";
cin>>hr;
cout<<" enter the minutes in standard time: ";
cin>>min;
cout<<" enter a for am and p for pm: ";
cin>>c;
MilitaryTime (hr,min,c);
}