Write the following overloaded operators, which have prototypes already written in Time.h and empty definitions (that you must complete) in [login to view URL]:

• Input/output operators: << >>

• Comparison operators: == != < >

• Arithmetic operators: + - += -=

• Increment operators: ++ as both pre- and post-increment

Operator specifications

Input/output

Both the input and output operators should handle times entered in the form h:mm _M or hh:mm _M, where

• h or hh = # of hours, using 1 or 2 digits

• mm = # of minutes, always using 2 digits

• _M = AM or PM

Examples of valid times: 7:30 PM, 12:22 AM, 9:09 PM.

Comparison

Each comparison operator tests the relationship between two Time objects, returning a boolean value indicating if the specified condition is true or false. As noted above, the conditions being tested are equality (==), inequality (!=), less than (<), and greater than (>).

Arithmetic

The arithmetic operators perform addition or subtraction between two Time objects as follows:

• When adding two times, take the first time and advance it by the number of hours and minutes specified in the second time.

• When subtracting one time from another, take the first time and move it back by the number of hours and minutes specified in the second time.

Keep in mind that a time after noon (12:00 PM) is 12 hours later than the same time before noon. The following examples demonstrate the desired arithmetic:

• 3:35 PM + 12:17 AM = 3:52 PM (add 0 hours, 17 minutes)

• 8:00 AM + 7:06 PM = 3:06 PM (add 19 hours (since 7 PM = 12 + 7 = 19 hours), 6 minutes)

• 4:15 AM - 3:20 AM = 12:55 AM (subtract 3 hours, 20 minutes)

• 1:15 PM - 3:20 PM = 9:55 PM (subtract 15 hours, 20 minutes)

The difference between the two addition operators is the += operator stores the sum in the calling object, while the + operator creates a new object to store the sum and returns a copy of that new object, without modifying the calling object. In other words, the following two statements calculate the same sum (T2 + T3), but the first one stores that sum in T1, while the second one stores the sum in T2:

T1 = T2 + T3;

T2 += T3; // shorthand for T2 = T2 + T3;

The difference between the - and -= operators is similar.

Increment

The pre- and post-increment operators are similar to the add operations, but, as unary operators, each of them adds a single minute to the time stored in the calling object. Recall that the difference between pre- and post-increment operators is essentially that the pre-increment operator changes the calling object and then returns a reference to it, while the post-increment operator copies the calling object and returns its original value after changing the original object.

Hints

Suggested order

I'd suggest writing these operators in the following order:

• Output operator (<<): Testing every other operator is easier when you can print the result, and it's easy to declare and initialize Time objects

• Input operator (>>): This operator is only used in the first two test cases--we don't combine input tests with any other operator tests--but moving on to this one is a logical extension of the output operator.

• Comparison operators (==, !=, <, >): All of these operators are similar, and checking how two Times compare to one another is relatively straightforward.

• Arithmetic operators (+, -, +=, -=): Understanding how to correctly add and subtract Time objects is the hardest part of this assignment, in my opinion. (Remember, I couldn't get the advance() function right the first time!) There are a couple of special cases to account for, as described below. I recommend handling the simple + and - operators before the augmented assignments += and -=.

• Increment operators (++): The increment operators are definitely simpler than the add and subtract operators, but you have to understand addition to write these correctly

Навыки: Программирование на C++

О работодателе:
( 0 отзыв(-а, -ов) ) Lowell, United States

ID проекта: #27876296

## Поручен:

mubashirmalick

Hi! I am an expert in C, C++ and data structures. I would be easily able to help you regarding any task related to them. Kindly message me to discuss more details. Thank you!

\$50 USD за 1 день
(9 отзывов(-а))
2.7

## 5 фрилансеров(-а) готовы выполнить эту работу в среднем за \$52

usamamw141

Hi there, I am expert in C++ and I can do this task today. Feel free to inbox me any time. Thank you.

\$50 USD за 1 день
(72 отзывов(-а))
5.4
tanukumari1262

Hi I have read the description and can do this work.I have 8 years of experience in C,C++ and [login to view URL] me so we can further [login to view URL] forward to work with you. Thanks

\$30 USD за 1 день
(10 отзывов(-а))
3.4
braincenter

Hello, Hope this message finds you well, I checked your details and I believe that my experience is what you are looking 4. I have been working on similar projects for the past eight years, and I have the essential sk Больше

\$100 USD за 3 дней(-я)
(4 отзывов(-а))
2.4
hnizami6649

Hello! I'm a professional programmer in computer science. I look forward to the best possible time and on a low budget to solve your informatics tasks, projects, and tasks. Are you stuck in the middle of an IT task, Больше

\$30 USD за 2 дней(-я)
(0 отзывов(-а))
0.0