Starting Out with C++ from Control Structures to Objects (9th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
9th Edition
ISBN: 9780134498379
Author: Tony Gaddis
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 16, Problem 2PC
Program Plan Intro

Time Format

Program plan:

source.cpp:

  • Include the required header files to the program.
  • Define the “main()” function.
    • Call the function “setTime()” and pass the “hours” and “sec” with valid and invald data.
  • Define the “setTime()” function.
    • Create an object for “MilTime” and pass the “hours” and “sec”.
    • Display the military hours using “getHour()” function.
    • Display the military hours using “getStandHr()” function.
    • Display the military hours using “getMin()” function.
    • Display the military hours using “getSec()” function.

Time.h:

  • Define the “Time.h”.
    • In protected, declare the required variable.
    • In private, create the constructor by passing hours, minutes and seconds.
    • Make a call to the function “getHour()”, “getMin()” and “getSec()” to get hours, minutes and seconds.

MilTime.h:

  • Define the “MilTime.h”.
    • In private, declare the required variable.
    • In public, create the constructor by passing two integer arguments.
    • Declare a function “convert()” which convert the hours to military format.
    • Create a mutator function for time.
    • Create an accessor function for military hours and standard format.

MilTime.cpp:

  • Define the “MilTime.h”.
    • Create a constructor “MilTime” which is derived from “Time” class.
    • Check the hours and seconds value.
    • If it is in out of range, then call the “BadHour” and “BadSeconds” exceptions.
    • Else set “hrs” to “milHours” and set “sec” to milSeconds;
    • Call the function “Convert()”.
  • Function definition for function “Convert()”
    • Declare a required variable “val”.
    • Check whether the “milHours” is greater than “1200”.
    • Subtract “milHours” by “1200”.
    • Divide “hours” by 100 and assign to variable “hour”.
    • Subtract “milHours” by “1200”and divide by 100.0.
    • Type cast the variable “val” to “int”.
  • Function definition for function “setTime()”
    • Assign “hrs” to “milHours”.
    • Assign “sec” to “milSeconds”.
    • Call the function “convert()”.

Blurred answer
Students have asked these similar questions
C++ D.S. Malik Exercise 14-4 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 must contain three exception classes: invalidHr, invalidMin, and invalidSec. If the user enters an invalid value for hours, then the program should throw and catch an invalidHr object. Follow similar conventions for the invalid values of minutes and seconds.
Challenge 1: Division.java You have to implement a Division class that divides two numbers given by the user. The program should handle exceptions that could be thrown during operation: If the second number is 0 If any of the numbers is not a valid number, such as a letter.
Instructions: Exception handing Add exception handling to this game (try, catch, throw). You are expected to use the standard exception classes to try functions, throw objects, and catch those objects when problems occur.  At a minimum, you should have your code throw an invalid_argument object when data from the user is wrong.    File GamePurse.h: class GamePurse { // data int purseAmount; public: // public functions GamePurse(int); void Win(int); void Loose(int); int GetAmount(); };   File GamePurse.cpp: #include "GamePurse.h" // constructor initilaizes the purseAmount variable GamePurse::GamePurse(int amount){      purseAmount = amount; } // function definations // add a winning amount to the purseAmount void GamePurse:: Win(int amount){      purseAmount+= amount; } //  deduct an amount from the purseAmount. void  GamePurse:: Loose(int amount){      purseAmount-= amount; }   // return the value of purseAmount. int GamePurse::GetAmount(){      return purseAmount; }   File…

Chapter 16 Solutions

Starting Out with C++ from Control Structures to Objects (9th Edition)

Ch. 16.4 - Prob. 16.11CPCh. 16 - Prob. 1RQECh. 16 - Prob. 2RQECh. 16 - Prob. 3RQECh. 16 - Prob. 4RQECh. 16 - What is unwinding the stack?Ch. 16 - What happens if an exception is thrown by a classs...Ch. 16 - How do you prevent a program from halting when the...Ch. 16 - Why is it more convenient to write a function...Ch. 16 - Why must you be careful when writing a function...Ch. 16 - The line containing a throw statement is known as...Ch. 16 - Prob. 11RQECh. 16 - Prob. 12RQECh. 16 - Prob. 13RQECh. 16 - The beginning of a template is marked by a(n)...Ch. 16 - Prob. 15RQECh. 16 - Prob. 16RQECh. 16 - Write a function that searches a numeric array for...Ch. 16 - Write a function that dynamically allocates a...Ch. 16 - Make the function you wrote in Question 17 a...Ch. 16 - Write a template for a function that displays the...Ch. 16 - Prob. 21RQECh. 16 - Prob. 22RQECh. 16 - Prob. 23RQECh. 16 - Prob. 24RQECh. 16 - T F All type parameters defined in a function...Ch. 16 - Prob. 26RQECh. 16 - T F A class object passed to a function template...Ch. 16 - Prob. 28RQECh. 16 - Prob. 29RQECh. 16 - Prob. 30RQECh. 16 - Prob. 31RQECh. 16 - T F A class template may not be derived from...Ch. 16 - T F A class template may not be used as a base...Ch. 16 - Prob. 34RQECh. 16 - Prob. 35RQECh. 16 - try { quotient = divide(num1, num2); } cout The...Ch. 16 - template class T T square(T number) { return T T;...Ch. 16 - template class T int square(int number) { return...Ch. 16 - Prob. 39RQECh. 16 - Assume the following definition appears in a...Ch. 16 - Assume the following statement appears in a...Ch. 16 - Prob. 1PCCh. 16 - Prob. 2PCCh. 16 - Prob. 3PCCh. 16 - Prob. 4PCCh. 16 - Prob. 5PCCh. 16 - IntArray Class Exception Chapter 14 presented an...Ch. 16 - TestScores Class Write a class named TestScores....Ch. 16 - Prob. 8PCCh. 16 - Prob. 9PCCh. 16 - SortableVector Class Template Write a class...Ch. 16 - Inheritance Modification Assuming you have...Ch. 16 - Prob. 12PCCh. 16 - Prob. 13PC
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
  • Text book image
    Microsoft Visual C#
    Computer Science
    ISBN:9781337102100
    Author:Joyce, Farrell.
    Publisher:Cengage Learning,
    Text book image
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781337671385
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT