Problem Description
编写2个类Date和Student
(1)Date表示出生日期,有3个整型数据成员年、月、日
(2)Student表示学生,有2数据成员,学号(整型)、出生日期(Date类型)
(3)Date、Student中数据成员都是私有的,还有必要的成员函数
完善以下程序。
//你的代码写在这里
int main(void)
{
Student s(1001, 1994, 5, 12);
cout << s.GetSno() << endl;
cout << s.GetDate().GetYear() << endl;
cout << s.GetDate().GetMonth() << endl;
cout << s.GetDate().GetDay() << endl;
return 0;
}
Input Description
无
Output Description
创建1个学生,并且输出学生所有信息。
Sample Output
1001 1994 5 12
实现
#include<iostream>
#include<string.h>
using namespace std;
class Date
{
private:
int Year;
int Month;
int Day;
public:
Date(int a,int b,int c)
{
Year=a;
Month=b;
Day=c;
}
int GetYear()
{
return Year;
}
int GetMonth()
{
return Month;
}
int GetDay()
{
return Day;
}
};
class Student
{
private:
int sno;
Date t;
public:
int s1, s2, s3;
Student(int a, int b, int c, int d) :t(b, c, d)
{
sno=a;
}
int GetSno(){return sno;}
Date GetDate()//返回Date的对象
{
return t;
}
};
这题主要就是题目的形式,需要你返回一个Date的对象才能输出。