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
valina [46]
3 years ago
6

Write a program that prompts the user to enter time in 12-hour notation. The program then outputs the time in 24-hour notation.

Your program should contain three exception classes: InvalidHr, InvalidMin, and InvalidSec. If user enters invalid value for hour, then the program should throw and catch an InvalidHr object. Same applies to the invalid value for minutes and seconds.
Engineering
1 answer:
Juliette [100K]3 years ago
4 0

Answer:

THE CODE FOR THE PROGRAM IS GIVEN BELOW:

#include <iostream>

#include "ConvertTimeHeader.h"

using namespace std;

int main()

{

convertTime convert;

int hr, mn, sc = 0;

 

cout << "Please input hours in 12 hr notation: ";

cin >> hr;

cout << "Please input minutes: ";

cin >> mn;

cout << "Please input seconds: ";

cin >> sc;

 

convert.invalidHr(hr);

convert.invalidMin(mn);

convert.invalidSec(sc);

convert.printMilTime();

 

system("Pause");

 

return 0;  

 

}

#include <iostream>

#include "ConvertTimeHeader.h"

using namespace std;

int convertTime::invalidHr (int hour)

{

try{

 if (hour < 13 && hour > 0)

  {hour = hour + 12;

  return hour;}

 else{

 

  cin.clear();

  cin.ignore();

  cout << "Invalid input! Please input hour again in correct 12 hour format: ";

  cin >> hour;

  invalidHr(hour);

  throw 10;

 }

   

}

catch (int c) { cout << "Invalid hour input!";}

}

int convertTime::invalidMin (int min)

{

try{

 if (min < 60 && min > 0)

  {return min;}

 else{

 

  cin.clear();

  cin.ignore();

  cout << "Invalid input! Please input minutes again in correct 12 hour format: ";

  cin >> min;

  invalidMin(min);

  throw 20;

  return 0;

 }

   

}

catch (int e) { cout << "Invalid minute input!" << endl;}

}

int convertTime::invalidSec(int sec)

{

try{

 if (sec < 60 && sec > 0)

  {return sec;}

 else{

 

  cin.clear();

  cin.ignore();

  cout << "Invalid input! Please input seconds again in correct 12 hour format: ";

  cin >> sec;

  invalidSec(sec);

  throw 30;

  return 0;

 }

   

}

catch (int t) { cout << "Invalid second input!" << endl;}

}

void convertTime::printMilTime()

{

cout << "Your time converted: " << hour << ":" << min << ":" << sec;

}

Explanation:

You might be interested in
Which of the following is described as a way engineers can test and investigate how things should be under certain circumstances
goblinko [34]

Answer:

The option that is best described as a way engineers can test and investigate how things should be under certain circumstances is;

  • Modeling

Explanation:

Modeling is a tool an engineer can use for the physical representation of a system that will facilitate the definition, testing and analysis, communication, data generation, data verification and data validation of given concepts

Models also aid in setting specifications, supporting designs, and verification of a given system

Therefore, with modeling engineers can investigate the behavior of systems under given environmental conditions.

3 0
3 years ago
A large building will need several different types of workmen to install and repair pipes for water, heating,
siniylev [52]

Answer:

Plumber and pipefitters

Explanation:

3 0
3 years ago
What was a campaign belief in the 1980 presidential election? Carter called for a stronger national defense. Carter promised to
andreyandreev [35.5K]

Answer:

C

Explanation:

On edge 2021

6 0
3 years ago
Read 2 more answers
List one advantage and one disadvantage of the use of the commutator?
Mariulka [41]

Answer and  Explanation:

Commutator are used in DC machine commutator is mainly used for the reversing the direction of the current .It is connected to the armature of the DC generator or motor

ADVANTAGE OF COMMUTATOR The main advantage of the commutator in DC motor is to keep keep the direction of the toque always in the same direction by changing the current direction

DISADVANTAGE OF COMMUTATOR : The main disadvantage is due to the friction between the commutator and brushes there is a friction loss.

3 0
3 years ago
Air enters a tank through an area of 0.2 ft2 with a velocity of 15 ft/s and a density of 0.03 slug/ft3. Air leaves with a veloci
Mademuasel [1]

Answer:

please find attached.

Explanation:

4 0
3 years ago
Other questions:
  • Which one of the following statements about the Wright brothers is not true?
    6·1 answer
  • Compute the estimated actual endurance limit for SAE 4130 WQT 1300 steel bar with a rectangular cross section of 20.0 mm by 60 m
    11·1 answer
  • What is your employer required to have on fixed ladders that extend more than 24 feet in the workplace?
    15·2 answers
  • What type of fuel does a 2 cycle engine use
    5·1 answer
  • Suggest how the following requirements might be rewritten in a
    8·1 answer
  • PLEASE HELP ASAP!!! Thanks
    11·1 answer
  • Design drawings use line styles of up to eight different varieties to communicate important information about the item. true or
    7·1 answer
  • Which fields of engineering use fluid power? Explain how these fields make use of fluid power systems: water supply, agricultura
    10·1 answer
  • A tool used to put a concave edge on a plane iron is
    6·1 answer
  • Ferroconcrete is reinforced concrete that combines concrete and ________. A. Lead c. Copper b. Iron d. Aluminum.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!