1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
olga nikolaevna [1]
3 years ago
11

Reference Parameters (returning multiple values): Write a C++ function that converts standard time to military time. Inputs incl

ude 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 cases above plus at least three other cases.

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

Engineering
1 answer:
valkas [14]3 years ago
5 0

Answer:

Code is given as below:

Explanation:

#include <iostream>

using namespace std;

//function prototype declaration

void MilitaryTime(int, int, char, int &, int &);

int main()

{

    //declare required variables

    int SHour, SMin, MHour, MMin;

    char AorP;

    //promt and read the hours from the user

    cout<<"Enter hours in standard time : ";

    cin>>SHour;

    //check the hours are valid are not

    while(SHour<0 || SHour>12)

    {

         cout<<"Invalid hours for standard time. "

             <<"Try again..."<<endl;

         cout<<"Enter hours in standard time : ";

         cin>>SHour;

    }

    //promt and read the minutes from the user

    cout<<"Enter minutes in standard time : ";

    cin>>SMin;

    //check the minutes are valid are not

    while(SMin<0 || SMin>59)

    {

         cout<<"Invalid minutes for standard time. "

             <<"Try again..."<<endl;

         cout<<"Enter minutes in standard time : ";

         cin>>SMin;

    }

    //promt and read the am or pm from the user

    cout<<"Enter standard time meridiem (a for AM p for PM): ";

    cin>>AorP;

    //check the meridiem is valid are not

    while(!(AorP=='a' || AorP=='p' || AorP=='A' || AorP=='P'))

    {

         cout<<"Invalid meridiem for standard time. "

             <<"Try again..."<<endl;

         cout<<"Enter standard time meridiem (a for AM p for PM): ";

         cin>>AorP;

    }

    //call function to calculate the military time

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

    //fill zeros and display standard time

    cout.width(2);

    cout.fill('0');

    cout<<SHour<<":";

    cout.width(2);

    cout.fill('0');

    cout<<SMin;

    if(AorP=='a' || AorP=='A')

         cout<<" am = ";

    else

         cout<<" pm = ";

    //fill zeros and display military time

    cout.width(2);

    cout.fill('0');

    cout<<MHour;

    cout.width(2);

    cout.fill('0');

    cout<<MMin<<endl;

    system("PAUSE");

    return 0;

}

//function to calculate the military time with reference parameters

void MilitaryTime(int SHour, int SMin, char AorP, int &MHour, int &MMin)

{

    //check the meredium is am or pm

    //and calculate hours

    if(AorP=='a' || AorP=='A')

    {

         if(SHour==12)

             MHour = 0;

         else

             MHour = SHour;

    }

    else

         MHour = SHour+12;

    MMin = SMin;

You might be interested in
Split the timing circuit below into 3 blocks by drawing 2 vertical lines across it, label each of the blocks stating whether it
garik1379 [7]

Answer:

i can Help you but iam using my phone so typing is really hectic. reach me via app on +254743503332

3 0
2 years ago
Que es stream media?
____ [38]

Answer:

ummmmmmmmmmmmmmmmmmmm no se

4 0
3 years ago
You can divide a surface by drawing a line through it
SpyIntel [72]

Answer:

T

Explanation:

6 0
3 years ago
Read 2 more answers
Air,in a piston cylinder assembly, is initially at 300 K and 200 kPa.It is then heated at constant pressure to 600 K. Determine
Mandarinka [93]

Answer:

Explanation: Please see the attached picture for answer.

5 0
3 years ago
Read 2 more answers
A piston cylinder containing 0.2 kg of air undergoes a process where pressure and volume are related by the expression P=CV wher
Black_prince [1.1K]

Answer:

Work = 51,33 kJ

Explanation:

According to the ideal gas equation, the initial volume is calculated as follows:

V_{i} =RT_{i}m/P_{i}=(0,2870)kJ/kg K*(25+273,15)K*(0,2)kg/(100)kN/m^{2}=0,1711m^{3}

Then the work for an isobaric process can be calculated using the following expression:

W=P(V_{f}-V_{i} )

And considering that,

V_{f}=4V_{i}

The work can be calculated as follows:

W=P(4V_{i}-V_{i})=3PV_{i} =(3)*(100)kn/m^{2}*(0,1711)m^{3}=51,33kJ

3 0
3 years ago
Read 2 more answers
Other questions:
  • An ideal Diesel cycle has a maximum cycle temperature of 2000°C. The state of the air at the beginning of the compression is P1
    10·1 answer
  • A Carnot machine operates with 25% efficiency, whose heat rejection reservoir temperature is 300K. Determine the temperature at
    13·1 answer
  • Define ""acidity"" of an aqueous solution. How do you compare the strength of acidity of solutions ?
    6·1 answer
  • 1) Find the time in seconds to reach full charge in an RL circuit with L = 5 H and R = 100 ohms
    10·1 answer
  • A hot plate with a temperature of 60 C, 50 triangular profile needle wings of length (54 mm), diameter 10 mm (k = 204W / mK) wil
    6·1 answer
  • Will give brainliest to whoever answers correctly!!!!
    5·2 answers
  • 11. Amphetamines that keep drivers awake also help with coordination and reaction time.
    5·2 answers
  • Which of these people is an engineer?
    13·1 answer
  • Using the method of joints, determine the force in each member of the truss shown in the image.
    14·1 answer
  • When are we going to abandon internal combustion engines?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!