Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <iostream>
- using namespace std;
- #ifndef _DATE_HPP_
- #define _DATE_HPP_
- class Date
- {
- private:
- size_t day;
- size_t month;
- size_t year;
- public:
- Date() : day(1), month(1), year(1970) {};
- Date(size_t day, size_t month, size_t year) :
- day(day),
- month(month),
- year(year)
- {};
- Date(const Date &obj) :
- day(obj.day),
- month(obj.month),
- year(obj.year)
- {};
- // Destructor
- virtual ~Date();
- // Get Methods
- inline auto getDay() -> size_t {
- return this->day;
- };
- inline auto getMonth() -> size_t {
- return this->month;
- };
- inline auto getYear() -> size_t {
- return this->year;
- };
- // Set Methods
- inline auto setDay(size_t value) -> void {
- this->day = value;
- }
- inline auto setMonth(size_t value) -> void {
- this->month = value;
- }
- inline auto setYear(size_t value) -> void {
- this->year = value;
- }
- inline auto operator < (Date &obj) -> bool {
- //return ((this->year < obj.year) ? true : this->month < obj.month ? true : this->day < obj.day ? true : false );
- return (this->year < obj.year || this->month < obj.month || this->day < this->day);
- }
- inline auto operator== (const Date &obj) -> bool {
- return (this->year == obj.year && this->month == obj.month && this->day == obj.day);
- }
- auto operator+(size_t count) -> Date {
- do {
- if(this->day + count > 31) {
- if(this->month % 2 == 0 && this->month != 12)
- this->day = ((this->day + count) - 30);
- else
- this->day = ((this->day + count) - 31);
- if(this->month > 11) {
- this->month = 1;
- this->year++;
- }
- }
- } while(this->day > 31);
- return *this;
- }
- auto operator-(size_t count) -> Date {
- this->day -= 20;
- return *this;
- }
- auto operator+=(size_t count) -> Date {
- if(this->day + count > 31) {
- if(this->month % 2 == 0 && this->month != 12)
- this->day = ((this->day + count) - 30);
- else
- this->day = ((this->day + count) - 31);
- if(this->month > 11) {
- this->month = 1;
- this->year++;
- }
- }
- return *this;
- }
- friend auto operator <<(ostream &output, const Date &obj) -> ostream& {
- output << obj.day << "/" << obj.month << "/" << obj.year;
- return output;
- }
- };
- #endif
- --------------
- #pragma once
- #include "Date.hpp"
- #include <string>
- #ifndef _LIBRARY_HPP_
- #define _LIBRARY_HPP_
- class Library
- {
- private:
- string id;
- string reader;
- Date date;
- public:
- Library() : id(""), reader(""), date(Date()) {};
- Library(string id, string reader, Date &date) :
- id(id),
- reader(reader),
- date(date) {};
- Library(const Library &obj) :
- id(obj.id),
- reader(obj.reader),
- date(obj.date) {};
- // Destructor
- virtual ~Library(void);
- // Get Methods
- inline auto getId() -> string {
- return this->id;
- }
- inline auto getReader() -> string {
- return this->reader;
- }
- inline auto getDate() -> Date& {
- return this->date;
- }
- // Operators
- auto operator<(Library &obj) -> bool {
- return (this->date < obj.date);
- }
- auto operator==(const Library &obj) -> bool {
- return (this->id == obj.id && this->reader == obj.reader && this->date == obj.date);
- }
- friend auto operator<<(ostream &output, const Library &obj) -> ostream& {
- output << "Book ID: " << obj.id << endl;
- output << "Reader Name: " << obj.reader << endl;
- output << "Date: " << obj.date << endl;
- return output;
- }
- };
- #endif
- ----------------
- #include "Library.hpp"
- #include <vector>
- #include <algorithm>
- int main() {
- vector<Library> array_libraries;
- vector<Date> array_date;
- Date now(11, 12, 2018);
- array_date.push_back(Date(25, 10, 2018));
- array_date.push_back(Date(5, 12, 2019));
- array_libraries.push_back(Library("1", "Georgi", array_date[1]));
- array_libraries.push_back(Library("2", "Petur", array_date[0]));
- for(auto &element : array_libraries) {
- cout << element;
- }
- sort(array_libraries.begin(), array_libraries.end(), [](Library &left, Library &right) {
- return left.getDate() < right.getDate();
- });
- cout << "\n\nSorted: \n\n";
- for(auto &element : array_libraries) {
- cout << element;
- }
- cout << "\n\nLate: \n\n";
- for(auto &element :array_libraries) {
- if(element.getDate() < (now -20)) {
- cout << element;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement