第四周。
This commit is contained in:
42
OOP/04/Exercise01.cpp
Normal file
42
OOP/04/Exercise01.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user