Hours and minutes: The time is 03:00 Hours and minutes: The time is 03:15 fail Test 2 Input: 3 65 Actual Expected
Hours and minutes: The time is 03:00 Hours and minutes: The time is 03:15 fail Test 2 Input: 3 65 Actual Expected
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
Can anyone help me with this?

Transcribed Image Text:**Test 1**
- **Input:**
- 3 15
| Actual | Expected |
|---------------------------------------------|--------------------------------------------|
| Hours and minutes: The time is 03:00 (fail) | Hours and minutes: The time is 03:15 |
- **Explanation:** The test was expected to output the time as 03:15 based on the input (3 hours and 15 minutes). However, the actual output incorrectly displays the time as 03:00, resulting in a fail.
---
**Test 2**
- **Input:**
- 3 65
| Actual | Expected |
|---------------------------------------------|---------------------------------------------------------|
| Hours and minutes: The time is 03:00 (fail) | Hours and minutes: minutes (65) out of range |
- **Explanation:** The expected behavior was to identify 65 minutes as out of range since there are only 60 minutes in an hour. The actual output shown as 03:00 fails to handle this condition correctly.

Transcribed Image Text:**Title: Creating Valid Time Objects Using a Factory Function**
You've seen how creating an invalid `Time` object (e.g., `Time treatmentTime = {0, -2};`) can lead to disaster. One solution to this problem is to use a **factory function** to create objects. Complete the `makeTime` factory function which throws an `invalid_argument` if one of the elements would make the object invalid.
---
### Code Overview (File: udts.cpp)
```cpp
#include <string>
#include <stdexcept>
#include "time.h"
using namespace std;
/**
* Construct a valid time object.
* @param h the hours in the range 0..23
* @param m the minutes in the range 0..59
* @exception throws invalid_argument if out of range.
* @return the constructed Time object.
*/
Time makeTime(int h, int m)
{
}
```
#### Explanation:
- **Header Files:**
- `#include <string>`: Allows usage of string functions.
- `#include <stdexcept>`: Provides standard exceptions including `invalid_argument`.
- `#include "time.h"`: Includes custom time definitions.
- **Namespace:**
- `using namespace std;`: Allows standard library usage without `std::` prefix.
- **Function Documentation:**
- **makeTime(int h, int m):**
- **Parameters:**
- `h`: Hour (valid range: 0 to 23)
- `m`: Minute (valid range: 0 to 59)
- **Exception:** Throws `invalid_argument` if the input values are out of the specified valid ranges.
- **Return:** Constructs and returns a valid `Time` object.
This setup ensures that the time object is always created with a valid state, preventing potential errors in the program. Complete the function by implementing the appropriate checks and return logic within the curly braces (`{ }`).
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images

Recommended textbooks for you

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education

Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY