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
Explain why different types of equipment are required for proper conditioning of air
blagie [28]

Answer:

 Different types of equipment are required for proper conditioning of air because every air conditional space faces some geometrical and environmental issues or problems. There are some different types of equipment used for conditioning of air that are air system, water system and air-water system. In many cases the air conditioning of the system varies with size of the equipment.  

8 0
3 years ago
As you get older your muscles grow. True or False
xenn [34]

Answer:

True

Explanation:

This is a true fact because From the time you are born to around the time you turn 30, your muscles grow larger and stronger.

8 0
2 years ago
Read 2 more answers
What is an advantage of a nuclear-fission reactor?.
Kobotan [32]

Answer:

Nuclear fission is almost 8,000 times more efficient than traditional fossil fuels at producing energy. That's a lot of energy packed into a small space. Nuclear energy is more efficient, which means it uses less fuel to power the plant and produces less waste.


advantages:
-produces no polluting gases
-does not contribute to global warming
-very low fuel costs
-Low fuel quantity reduces mining and transportation effects on environment
-High technology research required benefits other industries
-Power station has very long lifetime

Disadvantages:
-Waste is radioactive and safe disposal is very difficult and expensive
-Local thermal pollution from wastewater affects marine life
-Large-scale accidents can be catastrophic
-Public perception of nuclear power is negative
-Costs of building and safely decommissioning are very high
-Cannot react quickly to changes in electricity demand

4 0
2 years ago
In what type of automobile is a transaxle most commonly found?
user100 [1]

Answer: vehicles with a front engine and FWD or a rear engine and RWD.

Explanation But the transaxle can also be integrated into the rear axle on cars with a front engine and rear-wheel drive. The transaxle is in the rear where the differential would be rather than beside the engine.

7 0
2 years ago
Select the best answer to the questo
Norma-Jean [14]

Answer:

C

Explanation:

7 0
3 years ago
Read 2 more answers
Other questions:
  • Thermal energy generated by the electrical resistance of a 5-mm-diameter and 4-m-long bare cable is dissipated to the surroundin
    12·1 answer
  • How does fouling affects the performance of a heat exchanger?
    6·1 answer
  • Determine the magnitude of the resultant force and the moment about the origin. Note: the symbol near the 140 N-m moment are not
    15·1 answer
  • A rectangular block having dimensions 20 cm X 30 cm X 40 cm is subjected to a hydrostatic stress of -50 kPa (i.e. under compress
    15·1 answer
  • write an interface downloadable that has a method "geturl" that returns the url of a downloadable object
    5·1 answer
  • B1) 20 pts. The thickness of each of the two sheets to be resistance spot welded is 3.5 mm. It is desired to form a weld nugget
    8·1 answer
  • i need jacket for my daughter who will be going on a girls scouts camping trip it cannot be bulky because she is limited to one
    8·2 answers
  • The value of universal gas constant is same for all gases?<br> a) yes<br> b)No
    15·1 answer
  • 3. A particle is projected to the right from the position S = 0, when an initial velocity of 8 m/s. If the acceleration of the p
    6·1 answer
  • A retail business, owned by share holders and having centralized decision making for their multiple store locations is called:
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!