/*
改錯題:
設計一個日期類和時間類,並編寫全局函數display用於顯示日期和時間。要求:display函數做爲類外的普通函數,而不是成員函數
在主函數中調用display函數,display函數分別引用Time和Date兩個類的對象的私有數據,輸出年、月、日和時、分、秒。
下面的程序中,在begin到end部分存在語法錯誤。請改正錯誤,使程序按下面輸入輸出的規定運行。
注意:只提交修改過的begin到end部分的代碼。
*/
#include <iostream>
using namespace std;
//將程序須要的其餘成份寫在下面,只提交修改後的begin到end部分的代碼
//******************** begin ********************
class Time; //類的提早聲明
class Date //日期類
{
public:
Date(int y,int m,int d)
{
year=y;
month=m;
day=d;
}
private:
int year;
int month;
int day;
};
class Time //時間類
{
public:
Time(int h,int m,int s)
{
hour=h;
min=m;
sec=s;
}
private:
int hour;
int min;
int sec;
};
void display(const Date & d, const Time & t)
{
cout<<d.year<<"/"<<d.month<<"/"<<d.day<<endl;
cout<<t.hour<<":"<<t.min<<":"<<t.sec<<endl;
}
//********************* end ********************
int main()
{
void display(const Date &,const Time &);
int year,month,day;
cin>>year>>month>>day;
Date d1(year,month,day);
int hour,minute,second;
cin>>hour>>minute>>second;
Time t1(hour,minute,second);
display(d1,t1);
return 0;
}