consolidate all repos to one for archive
This commit is contained in:
60
semester_2/programiranje_2/primeri/Example12/Date.cpp
Normal file
60
semester_2/programiranje_2/primeri/Example12/Date.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include "Date.h"
|
||||
|
||||
Date::Date() : day(1), month(1), year(1971) {}
|
||||
|
||||
//Date::Date(const Date& dat) : day(dat.day), month(dat.month), year(dat.year) {}
|
||||
|
||||
Date::Date(int d, int m, int y) : day(d), month(m), year(y) {
|
||||
}
|
||||
|
||||
Date::~Date() {}
|
||||
|
||||
int Date::getDay() const {
|
||||
return day;
|
||||
}
|
||||
|
||||
void Date::setDay(int day) {
|
||||
if (day < 1 || day > 31) {
|
||||
std::cout << "Wrong day: " << day << std::endl;
|
||||
this->day = 1;
|
||||
}
|
||||
this->day = day;
|
||||
}
|
||||
|
||||
int Date::getMonth() const {
|
||||
return month;
|
||||
}
|
||||
|
||||
void Date::setMonth(int month) {
|
||||
if (month < 1 || month > 12) {
|
||||
std::cout << "Wrong month: " << month << std::endl;
|
||||
this->month = 1;
|
||||
}
|
||||
this->month = month;
|
||||
}
|
||||
|
||||
int Date::getYear() const {
|
||||
return year;
|
||||
}
|
||||
|
||||
void Date::setYear(int year) {
|
||||
this->year = year;
|
||||
}
|
||||
|
||||
const std::string Date::toString() const {
|
||||
// A stringstream associates a string object with a stream allowing you to read
|
||||
// from the string as if it were a stream (like cin).
|
||||
std::stringstream ss;
|
||||
ss << day << "." << month << "." << year;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
bool Date::isEqual(const Date& second) const {
|
||||
if (day==second.day && month == second.month && year == second.year)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user