1 solutions

  • 0
    @ 2025-11-5 17:24:56

    C++ :

    #include <iostream>
    using namespace std;
    class Date{
     public:
    	Date(int y,int m,int d);
    	Date();
    	void show();
    	void init();
    private:
    	int year;
    	int month;
    	int day; 
    }; 
    Date::Date(int y,int m,int d){
    	year=y;
    	month=m;
    	day=d;
    }
    Date::Date(){
    	int y=1900;
    	int m=1;
    	int d=1;
    	year=y;
    	month=m;
    	day=d;
    }
    void Date::show(){
    	cout<<year<<"-"<<month<<"-"<<day<<endl;
    }
    void Date::init(){
    	cin>>year>>month>>day;
    }
    int main(){
    	Date d1,d;
    	Date d2(2100,12,12);
        d.init();
        d1.show();
        d2.show();
        d.show();
     return 0;
    }
    
    • 1

    C++作业4-1:定义一个带重载构造函数的日期类(分值较大)

    Information

    ID
    18405
    Time
    1000ms
    Memory
    32MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By