0% found this document useful (0 votes)
45 views

Object Oriented Programming LAB (08) Special OOP Section (NC) Instructions

The document provides instructions for a lab assignment on object-oriented programming. It describes a task to write a Time class that stores time in hours, minutes, and seconds. The Time class is to have private data members for each, with mutator and accessor methods. Constructors are also required, including one that takes hours and minutes as arguments. Overloaded operators like stream insertion and extraction must be implemented. The class must handle boundary conditions like incrementing past 59 seconds or 59 minutes. Main is to test the Time class functionality.

Uploaded by

Asad Latif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Object Oriented Programming LAB (08) Special OOP Section (NC) Instructions

The document provides instructions for a lab assignment on object-oriented programming. It describes a task to write a Time class that stores time in hours, minutes, and seconds. The Time class is to have private data members for each, with mutator and accessor methods. Constructors are also required, including one that takes hours and minutes as arguments. Overloaded operators like stream insertion and extraction must be implemented. The class must handle boundary conditions like incrementing past 59 seconds or 59 minutes. Main is to test the Time class functionality.

Uploaded by

Asad Latif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Object Oriented Programming

LAB(08)

Special OOP Section(NC)

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.

1 OOP Special Section


[email protected]
iii. A default constructor that initializes all the data members of the class with default values.

5. Provide the implementation of following overloaded operators


i. stream insertion(<<)to display the time in the form16:50:45(hour:minutes:seconds)
ii. stream extraction (>>)should prompt the user for a time to be stored in a Time object. The
operator should ask the user to enter the time in the following format; hour:minutes:seconds

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)

2 OOP Special Section


[email protected]

You might also like