Problem Solving with C++ (10th Edition)
Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134521176
Author: SAVITCH
Publisher: PEARSON
Question
Book Icon
Chapter 16, Problem 2PP
Program Plan Intro

  • Include required library files.
  • Define a “checkDay()” function to check invalid date.
    • Check day and month using “if” statement.
  • Define a “convertToString()” function to convert string.
    • Create an array of months and declare the empty string for date.
    • Check the numerical month and print the corresponding month in alphabetic format.
  • Define a “convertDate()” function to convert date for the given format.
    • Check the given format and convert the valid string.
  • Define a “main()” function.
    • Call the “convertDate()” function with parameter inside the “try” block.
    • Any problem converting date, the exception is thrown to the “catch” block.
    • The “catch” will print the error message if the given date is invalid.

Blurred answer
Students have asked these similar questions
Write a class TimeOfDay that uses the exception classes defined in the previous exercise. Give it a method setTimeTo(timeString) that changes the time if timeString corresponds to a valid time of day. If not, it should throw an exception of the appropriate type. [Java]
Write a method that will take in a time in 24 hour format (1430) and return the time in 12 hour format (2:30pm). This method should have appropriate exception handling. If an incorrect time is sent as an argument (something out of bounds or 23(#4k in other words garbage), then your method should throw a TimeFormatException which you define. In no case should your method throw an unhandled exception! Show how to test the method to be sure.
What is the difference between using @Test(expected = TypeOfException) and using try/catch when testing if a method or constructor properly returns an exception? A. They do the same thing.   B. @Test(expected = ...) is the proper way to unit test in java, and try/catch should only be used when unit testing in Python.   C. @Test(expected = ...) will give a passing test as soon as one exception of the proper type is thrown and then stop the test, but using try/catch will allow you to test many examples in the same test and will only stop after running all examples or reaching a fail() or an assert statement that fails.   D. We should never use try/catch when unit testing, otherwise we will catch the exception and then won't know if it is actually thrown.
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,