用c++遍一下程序 开头一定要是#include<iostream> using namespace std;

2024-12-02 05:05:25
推荐回答(2个)
回答1:

#include
using namespace std;

class Date
{ public:
Date(int y,int m,int d):month(m),day(d),year(y){}
friend class DateTime;
private: int month, day,year;
};

class Time
{ public:
Time(int h,int m,int s):hour(h),minute(m),sec(s){}
friend class DateTime;
private: int hour,minute,sec;
};

class DateTime
{ public:
DateTime(class Date &dd, class Time &tt){
y =dd.year; m=dd.month; d=dd.day;
hour=tt.hour; minute=tt.minute; sec=tt.sec;
};
display(){
cout << m<<"-"<< d<<"-"<< y<< " ";
cout <};
private: int y,m,d,hour,minute,sec;
};

int main()
{
class Date d1(2012,6,20);
class Time t1(18,20,15);
class DateTime dt(d1,t1);
dt.display();
return 0;
}
===
输出:
6-20-2012 18:20:15

回答2:

已发。