Object Oriented Programming LAB (08) Special OOP Section (NC) Instructions
Object Oriented Programming LAB (08) Special OOP Section (NC) Instructions
LAB(08)
Instructions:
• Work on your own in the lab task. No collaboration is allowed; otherwise it would result
in 'F'. You can use your books, notes, handouts etc.
• To get full credit of your efforts, follow the coding conventions as well as the comments
section that describes your logic to the teacher assistant.
• Email the lab to the email [email protected] with a proper subject of following
format: [RollNum]-LAB(06+07).
• Deadline: 19 August 17, 2020 till 5.00pm sharp.
Task # 1:
Write a class named Time that stores the time in 24 hours format; having following
functionalities
1. The class should have following three private data members.
i. An integer named second that holds the value of the seconds.
ii. An integer named minute that holds the amount of the minutes.
iii. An integer named hour that holds the value of the hours.
Value should only be assigned to second, if it is in between 0 (default value) and 59 both inclusive.
Value should only be assigned to minute, if it is in between 0 (default value) and 59 both inclusive.
Value should only be assigned to hour, if it is in between0 (default value) and 23 both inclusive.
2. Provide the implementation of mutators for all the data members (sec, minute and hour) of the class.
3. Provide the implementation of accessors for all the data members (sec, minute and hour) of the class.
4. Provide the implementation of following constructors and a destructor
i. The constructor should accept the Time’s second, minute and hour as arguments. These values
should be assigned to the object’s appropriate member variables.
ii. The constructor should accept the Time’s minute and hour as arguments. These values should be
assigned to the object’s appropriate member variables. The second data member should be
assigned to the default value.
iii. pre-increment (++) should increment the second data member of the object iv. post-increment
(++) should increment the second data member of the object
v. pre-decrement (--) should decrement the second data member of the object
vi. post-decrement (--) should decrement the second data member of the object
vii. subtraction (-) binary should subtract the one time from another and return the number of
seconds between two times. For example, if 16:50:45 is subtracted from 16:51:00, the result
will be 15.
viii. addition (+) unary should return true, if the time is a working hour i.e. 09:00:00 to 17:00:00,
false otherwise.
6. The class should detect the following conditions and handle them accordingly:
1. When a time is set to the last sec of the minute and incremented, it should become the first sec
of the following minute.
2. When a time is set to59:59 (min:sec)and incremented, it should become00:00 (min:sec) of the
following hour.
3. When a sec is set to the first sec of the minute and decremented, it should become the last sec
of the previous minute.
4. When a time is set to 00:00 (min:sec) and decremented, it should become 59:59 (min:sec) of
the previous hour.
7. Once you have written the class, write main function and test its functionality by creating some objects
of Time (30 Marks)