[Cpp]
/*
* Copyright (c) 2013, computer College, Yantai University
* All rights reserved.
* File name: test. cpp
* Author: Fan Lulu
* Completion date: January 1, April 15, 2013
* Version: v1.0
*
* Input Description: None
* Problem description:
* Program output:
* Problem analysis:
* Algorithm Design: omitted
*/
# Include <iostream>
Using namespace std;
Class Date; // advance reference Declaration for the Date class
Class Time
{
Public:
Time (int, int, int); // defines the constructor
Void add_a_second (Date &); // increase by 1 second. After 1 second, it may arrive at the next day, which is until the next month, January, and next year.
Void display (Date &); // display time. Format: Month/day/year hour: minute: Second
Private:
Int hour;
Int minute;
Int sec;
};
Class Date
{
Public:
Date (int, int, int );
Friend class Time; // Time is defined as a friend class of Date.
Private:
Int month;
Int day;
Int year;
};
Int main ()
{
Time t1 (23, 59, 32 );
Date d1 (2012 );
For (int I = 0; I <= 80; I ++)
{
T1.add _ a_second (d1 );
T1.display (d1 );
}
Return 0;
}
// The member functions in the two classes are defined below, and the member functions must not be added.
// Note that you can call the private data member of the Date class in the Time member function.
Time: Time (int h, int m, int s)
{
Hour = h;
Minute = m;
Sec = s;
}
Date: Date (int m, int d, int y)
{
Month = m;
Day = d;
Year = y;
}
// Defines the time class member function, where Date is a friend class, you can directly call the private member in Date
Void Time: add_a_second (Date & d)
{
If (++ sec> = 60) ++ minute, sec-= 60;
If (minute> = 60) ++ hour, minute-= 60;
If (hour> = 24) ++ d. day, hour-= 24;
If (d. day> 30) + + d. month, d. day-= 30; // Q.
If (d. month> 12) + + d. year, d. month-= 12; // Q.
}
Void Time: display (Date & d)
{
Cout <d. month <"/" <d. day <"/" <d. year <"";
Cout }
/*
* Copyright (c) 2013, computer College, Yantai University
* All rights reserved.
* File name: test. cpp
* Author: Fan Lulu
* Completion date: January 1, April 15, 2013
* Version: v1.0
*
* Input Description: None
* Problem description:
* Program output:
* Problem analysis:
* Algorithm Design: omitted
*/
# Include <iostream>
Using namespace std;
Class Date; // advance reference Declaration for the Date class
Class Time
{
Public:
Time (int, int, int); // defines the constructor
Void add_a_second (Date &); // increase by 1 second. After 1 second, it may arrive at the next day, which is until the next month, January, and next year.
Void display (Date &); // display time. Format: Month/day/year hour: minute: Second
Private:
Int hour;
Int minute;
Int sec;
};
Class Date
{
Public:
Date (int, int, int );
Friend class Time; // Time is defined as a friend class of Date.
Private:
Int month;
Int day;
Int year;
};
Int main ()
{
Time t1 (23, 59, 32 );
Date d1 (2012 );
For (int I = 0; I <= 80; I ++)
{
T1.add _ a_second (d1 );
T1.display (d1 );
}
Return 0;
}
// The member functions in the two classes are defined below, and the member functions must not be added.
// Note that you can call the private data member of the Date class in the Time member function.
Time: Time (int h, int m, int s)
{
Hour = h;
Minute = m;
Sec = s;
}
Date: Date (int m, int d, int y)
{
Month = m;
Day = d;
Year = y;
}
// Defines the time class member function, where Date is a friend class, you can directly call the private member in Date
Void Time: add_a_second (Date & d)
{
If (++ sec> = 60) ++ minute, sec-= 60;
If (minute> = 60) ++ hour, minute-= 60;
If (hour> = 24) ++ d. day, hour-= 24;
If (d. day> 30) + + d. month, d. day-= 30; // Q.
If (d. month> 12) + + d. year, d. month-= 12; // Q.
}
Void Time: display (Date & d)
{
Cout <d. month <"/" <d. day <"/" <d. year <"";
Cout }