baidu_34564873 2016-04-06 13:58 采纳率: 33.3%
浏览 1414
已采纳

C++类的组合编程问题求帮忙

设计出生日期类birthday:
year,month,day
设计学生类student:
No(学号) ,Name(姓名),Birth(生日),Score(成绩)
下面是主函数部分
int main()
{
Birthday d(2002,1,1);
Student s1;
Student
s2("102","AAA",98,2001,1,1);
s1.disp();
s2.disp();
Student
s3("103","BBB",90,d);
s3.disp();
return 0;
}

帮忙添加两个类,再用类的组合实现并完善一下这个程序~初学者求解,谢谢

  • 写回答

2条回答

  • you都是我的 2016-04-06 15:09
    关注
     class CBirthday 
    {
    public:
        CBirthday()
        {
            m_nYear = 1990;
            m_nMonth = 9;
            m_nDay = 25;
        }
        CBirthday(int nYear, int nMonth, int nDay)
        {
            m_nYear = nYear;
            m_nMonth = nMonth;
            m_nDay = nDay;
        }
    public:
    int     m_nYear;
    int     m_nMonth;
    int     m_nDay;
    
    };
    
    class CStudent
    {
    public:
        CStudent()
        {
            m_strName = "李二狗";
            m_strNo = "110110";
            m_nScore = 0;
        }
    
        CStudent(const string &strNo, const string &strName, int nScore, int nYear, int nMonth, int nDay)
        {
            m_strNo = strNo;
            m_strName = strName;
            m_nScore = nScore;
            m_Birthday.m_nYear = nYear;
            m_Birthday.m_nMonth = nMonth;
            m_Birthday.m_nDay = nDay;
        }
    
        CStudent(const string &strNo, const string &strName, int nScore, CBirthday birthday)
        {
            m_strNo = strNo;
            m_strName = strName;
            m_nScore = nScore;
            m_Birthday = birthday;
        }
    
        void Disp()
        {
            cout<<"姓名:"<<m_strName.c_str() <<endl;
            cout<<"学号:"<<m_strNo.c_str() <<endl;
            cout<<"生日:"<<m_Birthday.m_nYear<<"-"<<m_Birthday.m_nMonth<<"-"<<m_Birthday.m_nDay <<endl;
            cout<<"成绩:"<<m_nScore <<endl;
        }
    
    private:
        string      m_strNo;
        string      m_strName;
        CBirthday   m_Birthday;
        int         m_nScore;
    };
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        CBirthday d(2002,1,1);
        CStudent s1;
        CStudent s2("102","AAA",98,2001,1,1);
        s1.Disp();
        s2.Disp();
        CStudent s3("103","BBB",90,d);
        s3.Disp();
    
        return 0;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog