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

PB-Basics of Class

The document provides instructions for a coding problem that involves modifying a Time class with various member functions such as setTime(), printUniversal(), printStandard(), resetTime(), compareTime(), and advanceTime(). The Time class keeps track of hours, minutes, seconds in a private int variable called second. Students are asked to implement the Time class according to the specifications. A main() function is provided to test the class. The output should match the example output given.

Uploaded by

sheng.c.tan
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)
12 views

PB-Basics of Class

The document provides instructions for a coding problem that involves modifying a Time class with various member functions such as setTime(), printUniversal(), printStandard(), resetTime(), compareTime(), and advanceTime(). The Time class keeps track of hours, minutes, seconds in a private int variable called second. Students are asked to implement the Time class according to the specifications. A main() function is provided to test the class. The output should match the example output given.

Uploaded by

sheng.c.tan
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

Midterm online test: Fundamental Computer Programming- C++ Lab(II), Rung-Bin Lin

April 16, 2022, International Bachelor Program in Informatics, Yuan Ze University

Problem B: Time Class

(25%, related to Lab 2)

Problem Description

You are asked to modify the Time class definition given in the file help.rtf, into the
one shown below:

class Time
{
public:
Time(); // constructor
void setTime( int h, int m, int s ); // set time by giving hour, minute and second
// 0 <= h <24, 0<= m <60, 0 <= s <60
void printUniversal() const; // print time in universal-time format
void printStandard() const; // print time in standard-time format
void resetTime(); // Reset time with second = 0
void compareTime(Time); // Compare two Time's objects
void advanceTime(int, int, int) ; // Advance time by a number of hours, minutes,
seconds
static int printedTimes; // Number of times Time objects are printed
private:
int second; // number of seconds, 0 <= second <= 86399
}; // end class Time

where the members are largely self-explained. If any parameter in the parameter list
of setTime(int, int, int) is out of range, second should be set to zero. The function
compareTime(Time &) determines whether the time of the object that calls this
member function is later than the time of the object given in the parameter list. If its
time is later, print out “Later”. If its time is early, print out “Earlier”. Otherwise, print
“Same”.
The main() function is also provided. The output should be the same as Example
Output. The main() function is given in the file called help.rtf and should not be
changed.

Input Format

None

Output Format

As given in the example.

Example Output
Midterm online test: Fundamental Computer Programming- C++ Lab(II), Rung-Bin Lin
April 16, 2022, International Bachelor Program in Informatics, Yuan Ze University

You might also like