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
The town of Mustang, TX is concerned that waste heat discharged from a new up- stream power plant will decimate the minnow popul
vitfil [10]

Answer:

Yes the water will be safe at the point of cooling water discharge

Explanation:

Power losses in plant= 350- 350×0.35=227.5MW

Rate of heat rejection to stream= 0.75× 227.5= 170.625MW

Rate of heat rejection= rate of flow of water× c × ΔT

170625000= 150000000× 4.186 × (Final temperature- 20)

Final temperature= 20.3 ◦C

The final temperature of stream will be 20.3 ◦C. Thechange is very small so the minnows will be able to handle this temperature.

7 0
3 years ago
Describe the engineering design process in your own words.
MrMuchimi

Answer:

Explanation:

8 0
3 years ago
Read 2 more answers
13. Write a function which is passed two strings. The function creates a new string from the two original strings by copying one
attashe74 [19]

Answer:

I am writing the code in C++. Let me know if you want the program in some other programming language.

#include <iostream>  // includes header file for input output functions

using namespace std;     //to identify objects like cin cout

string CopyStrings(string string1, string string2)  

{   string newString = "";    

   for (int loop = 0; loop < string1.length() ||  

                   loop < string2.length(); loop++)      {      

       if (loop < string1.length())  

           newString += string1[loop];          

       if (loop < string2.length())  

           newString += string2[loop];      }  

   return newString;   }  

int main()  

{   string stringA = "ace";  

   string stringB = "bdf";  

   cout << CopyStrings(stringA, stringB);   }

Output:

abcdef

Explanation:

The function CopyStrings() function takes two strings i.e. string1 and string2 as parameters to copy characters from both the string one character from each.

The newString variable stores the new string after copying characters from both strings string1 and string2.

Then the for loop starts which has a variable loop which is an index variable that traverses through both the strings stored in string1 and string2. The loop continues to execute until it moves through entire length of string1 and string2 which means it copies all the characters from both string1 and string2. length() is used here which returns length of the string1 and string2.

If statement in the for loop checks the character that loop (index) variable is pointing to is less than the string1 length which means it checks each character stored in string1. For example if string1 contains "ace" and loop variable is moving through the string and is currently at "a" then this condition is true. If the condition evaluates to true then the body of if statement is executed. The next statement stores that character a into the newString variable.

Next If statement checks character that loop variable is pointing to is less than the string2 length which means it checks each character stored in string2. For example if string2 contains "bdf" and loop variable is moving through the string and is currently at "b" then this condition is true. If the condition evaluates to true then the body of if statement is executed. The next statement stores that character b into the newString variable.

Then the second iteration starts which again first stores the next character i.e. c from string1 into newString and then stores next character i.e d from string2 into newString.

Then the third iteration starts which again first stores the next character i.e. e from string1 into newString and then stores next character i.e f from string2 into newString.

Then the loop breaks as the loop variable reaches end of both the string1 and string2.

return newString will return the copied string into the output screen which is abcdef.

The screenshot of code along with output is attached.

3 0
3 years ago
A torque T 5 3 kN ? m is applied to the solid bronze cylinder shown. Determine (a) the maximum shearing stress, (b) the shethe 1
Lelechka [254]

£¢π£¥¥¥£€€√¢•€€÷×¶£¥€✓©¥%¶×^€[{%¶∆{£]=¥✓=€

4 0
2 years ago
The change in specific internal energy depends on the path of a process. a)-True b)-False
Basile [38]

Answer:

(b) False

Explanation:

The specific internal energy of the system does not depend on the path of the process, it is a state function means its depend on only on the initial and the final position it does not depend on the path which it follow in the process.Internal energy is associated with the random motion of the molecules.

So it is false statement as internal energy is not a path function

7 0
2 years ago
Other questions:
  • The flatbed truck carries a large section of circular pipe secured only by the two fixed blocks A and B of height h. The truck i
    14·2 answers
  • Determine F12 and F21 for the following configurations: (a) A long semicircular duct with diameter of 0.1 meters: (b) A hemisphe
    10·1 answer
  • A spherical seed of 1 cm diameter is buried at a depth of 1 cm inside soil (thermal conductivity of 1 Wm-1K-1) in a sufficiently
    14·1 answer
  • (a) Consider a germanium semiconductor at T 300 K. Calculate the thermal equilibrium electron and hole concentrations for (i) Nd
    7·1 answer
  • Refrigerant-134a enters an adiabatic compressor at -30oC as a saturated vapor at a rate of 0.45 m3 /min and leaves at 900 kPa an
    13·1 answer
  • Technician A states that air tools generally produce more noise than electric tools, so wear ear protection when using air tools
    8·1 answer
  • The volume of the pyramid is 36 cubic cm, find the volume of the prism.
    5·1 answer
  • A golfer and her caddy see lightning nearby. the golfer is about to take his shot with a metal club, while her caddy is holding
    12·1 answer
  • A ruptured desiccant bag in a reciever-driver is usually caused by what?​
    13·1 answer
  • On a day in which the local atmospheric pressure is 99.5 kPa, answer each of the following: (a) Calculate the column height of m
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!