Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C++ Programming Assignment Help needed ASAP For this C++ program can you please complete Time.cpp file using overloaded operators. Below are the screenshots that can
C++ Programming Assignment Help needed ASAP
For this C++ program can you please complete Time.cpp file using overloaded operators. Below are the screenshots that can you be helpful. So can you please complete the Time.cpp file with the C++ code and return to me ASAP. Thanks
7.23 Program 3: The Time class and operator overloading This assignment gives you experience writing overloaded operators for handling input/output, comparisons, and arithmetic operations. Earlier in the semester, we discussed how to model time as a data type, briefly defining a Time structure. I've converted this structure to a class and written the four member functions we discussed (set (), display (), advance(), and lessThan ( )) and the class constructors. I've also written a main program to test the code you generate. Your job will be to write the following overloaded operators, which have prototypes already written in Time . h and empty definitions (that you must complete) in Time . cpp . 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 . horhh = # 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 (). 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 theComparison 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 (). 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 = 12 + 13; T2 += 13; // shorthand for 12 = 12 + 13; 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 ( >): 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. 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. Code reuse This program offers a great chance to practice one of the key tenets of programming: reusing existing code when writing new functions. You can use some of the operators to help you write others; you may also be able to use some of the four member functions I wrote to help you write your operators. Math on Time objects From personal experience (again, the advance( ) function looked a lot different originally), I can tell you it is much easier to do math on the miltime data members of Time objects and update the other three data members (hours, minutes, and AMorPM) afterwards than it is to do math on hours and minutes and fix everything else after that. See the new advance ( ) function for an example. The trickiest part of these operators is accounting for: 1. Cases in which you add or subtract enough minutes to affect the number of hours. For example, 1:50 AM + 1:15 AM = 3:05 AM (since "2:65 AM" isn't a valid time). 2. Cases in which you add or subtract enough hours to change from AM to PM or vice versa. For example, 11:09 PM + 1:23 AM = 12:32 AM.Code reuse This program offers a great chance to practice one of the key tenets of programming: reusing existing code when writing new functions. You can use some of the operators to help you write others: you may also be able to use some of the four member functions I wrote to help you write your operators. Math on Time objects From personal experience (again, the advance(} function looked a lot differentoriginally]. I can tell you it is much easier to do math on the miltime data members of Time objects and update the other three data members (hours, minutes, and AltorPM] afterwards than it is to do math on hours and minutes and x everything else after that. See the new aduance(} function for an example. The trickiest part ofthese operators is accounting for: 1. Cases in which you add or subtract enough minutes to affect the number of hours. For example. 1:50 AM + 1:15 PM = 3:05 AM [since '2:65 Alvl' isn't a valid time]. 2. Cases in which you add or subtract enough hours to change from AM to PM or vice versa. For example, 11:09 PM + 1:23 AM = 12:32 AM. 33\"...\" ' 123.1: Program 3: The Time class and operator overloading D! 100 U Down oade ble fles Time.h , Time.cpp .and RTC.Cpp Download Current file: time_test_p3.cpp Load default template... /* * EECE. 3220: Data Structures * Instructor: M. Geiger * time_test_p3. cpp: Main program to test Time class for Program 3 she #include "Time.h" #includeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started