補完1

1858 ワード

 、     
/*  
*     :console.cpp  
*       :     
*     :2017   5   7    
*      :v1.0  
*              : 
*     :   
*     :    1      
*     :        
*     :      
*     :   
*/    
#include
using namespace std;
class Date; // Date          
class Time
{
public:
	Time(int, int, int);
	void add_a_second(Date &);  //  1 ,1          ,     、     
	void display(Date &);  //    ,  : / /   : :   
private:
	int hour;
	int minute;
	int sec;
};
Time::Time(int a, int b, int c)
{
	hour = a;
	minute = b;
	sec = c;
}

class Date
{
public:
	Date(int, int, int);
	friend class Time; //Time Date      
private:
	int month;
	int day;
	int year;
};
Date::Date(int x, int y, int z)
{
	month = x;
	day = y;
	year = z;
}
int main()
{
	Time t1(23, 59, 32);
	Date d1(12, 31, 2013);   //   ,   Date d1(2,28,2013)     
	for (int i = 0; i <= 100; i++)
	{
		t1.add_a_second(d1);
		t1.display(d1);
	}
	return 0;
}
//             ,             
//     Time          Date             
void Time::add_a_second(Date&d1)
{
	sec++;
	if (sec == 60)
	{
		sec = 0;
		minute++;
		if (minute == 60)
		{
			minute = 0;
			hour++;
			if (hour == 24)
			{
				hour = 0;
				d1.day++;
				if (d1.day == 30)
				{
					d1.month++;
					d1.day = 1;
					if (d1.month == 12)
					{
						d1.month = 1;
						d1.year++;
					}
				}
			}
		}
	}
}
void Time::display(Date&d1)
{
	cout << " :" << d1.month << "  :" << d1.day << "  :" << d1.year << " " << hour << ":" << minute << ":" << sec << endl;
}
 、    :