Files
BasicsOfComputerSoftwareEng…/OOP/04/Exercise01.cpp
2023-03-14 19:17:55 +08:00

42 lines
727 B
C++

#include <iostream>
class Date {
private:
int d, m, y;
public:
Date(int dd = 0, int mm = 0, int yy = 0);
void addDay();
friend Date operator ++(Date& D);
friend Date operator ++(Date& D, int);
void Print();
};
Date::Date(int dd, int mm, int yy): d(dd), m(mm), y(yy){};
Date operator ++(Date& D) {
D.addDay();
return D;
}
Date operator ++(Date& D, int) {
Date tmp = Date(D);
D.addDay();
return tmp;
}
void Date::addDay() {
this->d++;
}
void Date::Print() {
std::cout << this->d << "," << this->m << "," << this->y << std::endl;
}
int main() {
Date aDay = Date(12,3,2023);
aDay++.Print();
aDay.Print();
(++aDay).Print();
aDay.Print();
return 0;
}