#include<iostream>
using namespace std;
class CDate
{
public:
int Date_Year;
int Date_Month;
int Date_Day;
};
int main()
{
CDate date1;//定义CDate类对象date1、date2
CDate date2;
int age = 0;//定义年龄,初始值为0
date1.Date_Year = 2019;//给date1的公有数据成员赋值
date1.Date_Month = 3;
date1.Date_Day = 9;
date2.Date_Year = 1999;//給date2的公有数据成员赋值
date2.Date_Month = 3;
date2.Date_Day = 9;
age = date1.Date_Year - date2.Date_Year;//计算年龄
cout << "He is " << age << "years old." << endl;//输出生日
cout << "His birthday is "
<< date2.Date_Year
<< '-'
<< date2.Date_Month
<< '-'
<< date2.Date_Day
<< endl;
cout << "date1 occupies " << sizeof(date1) << " bytes.";
cout << endl;
return 0;
}
版权声明:本文为starmultiple原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。