类对象成员

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的对象才能输出。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值