2、设计一个Student类(1)基本信息:学号、姓名、性别、出生日期、院系、专业; 数据成员中:“日期”要声明为一个内嵌子对象(2)Student类要包含:构造函数、内联成员函数、带默认参数的构

#include<iostream>
#include<string>
using namespace std;
class Date{              //日期类 
    public:
        Dates(int ayear,int amonth,int aday);//构造函数 
        int getYear(){   //成员函数方法实现 
            return year;
        }
        int getMonth(){   //成员函数方法的实现 
            return month;
        }
        int getDay(){    //成员函数的方法实现 
            return day;
        }
void Setin(){     //成员函数的方法实现 
    cout<<"出生年份:"; 
    cin>>year;
    cout<<"出生月份:"; 
    cin>>month;
    cout<<"出生日期:";
    cin>>day; 
}
        Dates(const Date &d);   //构造函数 
        void showDate();  //成员函数   显示信息 
        ~Date(){}  //析构函数 
        private:
            int year,month,day;
};
int Date::Dates(int ayear,int amonth,int aday){  //成员函数的方法实现 
    year=ayear;
    month=amonth;
    day=aday;
    
}
Date::Dates(const Date &d){  //复制构造函数的方法实现 
    year=d.day;
    month=d.month;
    day=d.day;
}
void Date::showDate(){   //成员函数的方法实现 
    cout<<year<<'-'<<month<<'-'<<day<<endl;
}
class Student{//Student类    同时内嵌日期类 
    public:    
    Student(){}    
        Student(string anum,string aname,string asex,Date abirthdate,string adepartment,string amajor);//带默认参数的构造函数  同时日期类为内嵌子对象 
        ~Student(){}
    void SetIn(){//成员函数及其方法的实现 
        cout<<"学号:";
        cin>>num;
        cout<<"姓名:";
        cin>>name;
        cout<<"性别:";
        cin>>sex;
        birthdate.showDate();
        cout<<"院系:";
        cin>>department;
        cout<<"专业:";
        cin>>major;
    }
    void Show();//内联成员函数 
    void SetInfo(){//修改学生信息的函数 
        char a;
        cout<<"是否修改(是=y,否=n)"<<endl;
        cin>>a;
        if(a=='y') {
        SetIn();
        SetInfo();    
        }
        else {
        void Show();    
        }
    }
    private:
        string num;
        string name,sex,department,major;
        Date birthdate;
        
};
Student::Student(string anum,string aname,string asex,Date abirthdate,string adepartment,string amajor){
    num=anum;
    name=aname;
    sex=asex;
    department=adepartment;
    major=amajor;
    birthdate=abirthdate;
}
inline void Student::Show(){//内联函数的方法实现 
    cout<<"学号:"<<num<<endl;
    cout<<"姓名"<<endl;
    cout<<"姓名:"<<name<<endl;
    cout<<"性别"<<sex<<endl;
    birthdate.showDate();
    cout<<"院系:"<<department<<endl;
    cout<<"专业:"<<major<<endl; 
    }


int main(){
    Date d1;
    cout<<"请输入出生日期:"<<endl; 
    d1.Setin();
    cout<<"请输入学生的基本信息:"<<endl;
          Student s1;
    d1.showDate();
    s1.SetIn();//调用函数 
    s1.SetInfo();
    s1.Show();
    return 0;    
}


 

  • 9
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值