consolidate all repos to one for archive
This commit is contained in:
45
semester_2/programiranje_2/naloga0902/Date.cpp
Normal file
45
semester_2/programiranje_2/naloga0902/Date.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
|
||||
#include "Date.h"
|
||||
|
||||
std::ostream& operator<<(std::ostream &out, const Date &date) {
|
||||
return out << date.toString();
|
||||
}
|
||||
|
||||
Date::Date(unsigned int day, unsigned int month, unsigned int year) : day(day), month(month), year(year) {}
|
||||
|
||||
std::string Date::toString() const {
|
||||
return std::to_string(day) + ", " + std::to_string(month) + ", " + std::to_string(year);
|
||||
}
|
||||
|
||||
bool Date::operator==(const Date &other) const {
|
||||
return this->year == other.year && this->month == other.month && this->day == other.day;
|
||||
}
|
||||
|
||||
//prefix ++a
|
||||
Date& Date::operator++() {
|
||||
day++;
|
||||
if(months[month-1] < day){
|
||||
month++;
|
||||
day = 1;
|
||||
}
|
||||
if(month == 13){
|
||||
year++;
|
||||
month = 1;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
//postfix a++
|
||||
Date Date::operator++(int dummy) {
|
||||
Date tmp(day,month,year);
|
||||
day++;
|
||||
if(months[month-1] < day){
|
||||
month++;
|
||||
day = 1;
|
||||
}
|
||||
if(month == 13){
|
||||
year++;
|
||||
month = 1;
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
Reference in New Issue
Block a user