c/c++课的作业合集,都是很简单的文件。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cpp-work/test1/20220317-4.cpp

39 lines
615 B

3 years ago
#include <iostream>
#include <cmath>
using namespace std;
class date {
public:
date(const char *NewD);
date(int NewY, int NewM, int NewD);
date();
void show();
private:
int y, m, d;
};
date::date(int NewY, int NewM, int NewD) : y(NewY), m(NewM), d(NewD) {}
date::date(const char *NewD) {
sscanf(NewD, "%d-%d-%d", &y, &m, &d);
}
void date::show() {
cout << y << '-' << m << '-' << d << endl;
}
date::date() : y(1970), m(1), d(1){}
int main() {
date d1, d2(2011, 3, 8), d3("2011-03-19");
d1.show();
d2.show();
d3.show();
}