diff options
Autocommit at 05.05.2022 @ 16:18
9 files changed, 118 insertions, 149 deletions
| -rw-r--r-- | src/Date/Date.cpp | 74 | ||||
| -rw-r--r-- | src/Date/Date.h | 33 | ||||
| -rw-r--r-- | src/DateTime/DateTime.cpp | 97 | ||||
| -rw-r--r-- | src/DateTime/DateTime.h | 41 | ||||
| -rw-r--r-- | src/EventSystem/Event.cpp | 4 | ||||
| -rw-r--r-- | src/EventSystem/Event.h | 4 | ||||
| -rw-r--r-- | src/EventSystem/EventSystem.cpp | 4 | ||||
| -rw-r--r-- | src/EventSystem/EventSystem.h | 6 | ||||
| -rw-r--r-- | src/VenueConsoleUI.cpp | 4 |
diff --git a/src/Date/Date.cpp b/src/Date/Date.cpp new file mode 100644 index 0000000..4732b0c --- /dev/null +++ b/src/Date/Date.cpp @@ -0,0 +1,74 @@ +#include "Date.h" + +/* Private */ + +bool Date::isLeapYear() { + // Implements https://en.wikipedia.org/wiki/Leap_year#Gregorian_calendar + return year % 400 == 0 || year % 100 != 0 || year % 4 == 0; +} + +unsigned short Date::daysInMonth() { + if (month == 2) + return 28 + isLeapYear(); + if (month <= 7) + return 30 + month % 2; + return 31 - month % 2; +} + +/* Public */ + +Date::Date() : Date(01, 05, 2022) {} + +Date::Date(unsigned short day, unsigned short month, unsigned short year) { + this->day = day; + this->month = month; + this->year = year; +} + +int Date::compare(const Date& other) const { + if (year < other.year || month < other.month || day < other.day) + return -1; + return year > other.year || month > other.month || day > other.day; +} + +unsigned short Date::get_day() const { + return day; +} +bool Date::set_day(unsigned short newDay) { + if (newDay == 0 || newDay > daysInMonth()) + return false; + day = newDay; + return true; +} + +unsigned short Date::get_month() const { + return month; +} +bool Date::set_month(unsigned short newMonth) { + if (newMonth == 0 || newMonth > 12) + return false; + month = newMonth; + return true; +} + +unsigned short Date::get_year() const { + return year; +} +bool Date::set_year(unsigned short newYear) { + year = newYear; + return true; +} + +/* Outside of class */ + +std::istream& operator>>(std::istream& istr, Date& dt) { + unsigned short d, M, y; + istr >> d >> M >> y; + dt = Date(d, M, y); + return istr; +} + +std::ostream& operator<<(std::ostream& ostr, const Date& dt) { + ostr << dt.get_day() << "." << dt.get_month() << "." << dt.get_year(); + return ostr; +} diff --git a/src/Date/Date.h b/src/Date/Date.h new file mode 100644 index 0000000..5d1ff62 --- /dev/null +++ b/src/Date/Date.h @@ -0,0 +1,33 @@ +#ifndef HEADER_DATETIME +#define HEADER_DATETIME + +#include <istream> +#include <ostream> + +class Date { + unsigned short day; + unsigned short month; + unsigned short year; + + bool isLeapYear(); + unsigned short daysInMonth(); + +public: + Date(); + Date(unsigned short day, unsigned short month, unsigned short year); + int compare(const Date& other) const; + + unsigned short get_day() const; + bool set_day(unsigned short newDay); + + unsigned short get_month() const; + bool set_month(unsigned short newMonth); + + unsigned short get_year() const; + bool set_year(unsigned short newYear); +}; + +std::istream& operator>>(std::istream& istr, Date& dt); +std::ostream& operator<<(std::ostream& ostr, const Date& dt); + +#endif diff --git a/src/DateTime/DateTime.cpp b/src/DateTime/DateTime.cpp deleted file mode 100644 index 8359f0b..0000000 --- a/src/DateTime/DateTime.cpp +++ /dev/null @@ -1,97 +0,0 @@ -#include "DateTime.h" - -/* Private */ - -bool DateTime::isLeapYear() { - // Implements https://en.wikipedia.org/wiki/Leap_year#Gregorian_calendar - return year % 400 == 0 || year % 100 != 0 || year % 4 == 0; -} - -unsigned short DateTime::daysInMonth() { - if (month == 2) - return 28 + isLeapYear(); - if (month <= 7) - return 30 + month % 2; - return 31 - month % 2; -} - -/* Public */ - -DateTime::DateTime() : DateTime(12, 00, 01, 05, 2022) {} - -DateTime::DateTime(unsigned short hour, unsigned short minute, unsigned short day, unsigned short month, unsigned short year) { - this->hour = hour; - this->minute = minute; - this->day = day; - this->month = month; - this->year = year; -} - -int DateTime::compare(const DateTime& other) const { - if (year < other.year || month < other.month || day < other.day || hour < other.hour || minute < other.minute) - return -1; - return year > other.year || month > other.month || day > other.day || hour > other.hour || minute > other.minute; -} - -unsigned short DateTime::get_hour() const { - return hour; -} -bool DateTime::set_hour(unsigned short newHour) { - if (newHour > 23) - return false; - hour = newHour; - return true; -} - -unsigned short DateTime::get_minute() const { - return minute; -} -bool DateTime::set_minute(unsigned short newMinute) { - if (newMinute > 59) - return false; - minute = newMinute; - return true; -} - -unsigned short DateTime::get_day() const { - return day; -} -bool DateTime::set_day(unsigned short newDay) { - if (newDay == 0 || newDay > daysInMonth()) - return false; - day = newDay; - return true; -} - -unsigned short DateTime::get_month() const { - return month; -} -bool DateTime::set_month(unsigned short newMonth) { - if (newMonth == 0 || newMonth > 12) - return false; - month = newMonth; - return true; -} - -unsigned short DateTime::get_year() const { - return year; -} -bool DateTime::set_year(unsigned short newYear) { - year = newYear; - return true; -} - -/* Outside of class */ - -std::istream& operator>>(std::istream& istr, DateTime& dt) { - unsigned short h, m, d, M, y; - istr >> h >> m >> d >> M >> y; - dt = DateTime(h, m, d, M, y); - return istr; -} - -std::ostream& operator<<(std::ostream& ostr, const DateTime& dt) { - bool padh = dt.get_hour() < 10, padm = dt.get_minute() < 10; - ostr << ((padh) ? "0" : "") << dt.get_hour() << ":" << ((padm) ? "0" : "") << dt.get_minute() << " " << dt.get_day() << "." << dt.get_month() << "." << dt.get_year(); - return ostr; -} diff --git a/src/DateTime/DateTime.h b/src/DateTime/DateTime.h deleted file mode 100644 index e9f353c..0000000 --- a/src/DateTime/DateTime.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef HEADER_DATETIME -#define HEADER_DATETIME - -#include <istream> -#include <ostream> - -class DateTime { - unsigned short hour; - unsigned short minute; - unsigned short day; - unsigned short month; - unsigned short year; - - bool isLeapYear(); - unsigned short daysInMonth(); - -public: - DateTime(); - DateTime(unsigned short hour, unsigned short minute, unsigned short day, unsigned short month, unsigned short year); - int compare(const DateTime& other) const; - - unsigned short get_hour() const; - bool set_hour(unsigned short newHour); - - unsigned short get_minute() const; - bool set_minute(unsigned short newMinute); - - unsigned short get_day() const; - bool set_day(unsigned short newDay); - - unsigned short get_month() const; - bool set_month(unsigned short newMonth); - - unsigned short get_year() const; - bool set_year(unsigned short newYear); -}; - -std::istream& operator>>(std::istream& istr, DateTime& dt); -std::ostream& operator<<(std::ostream& ostr, const DateTime& dt); - -#endif diff --git a/src/EventSystem/Event.cpp b/src/EventSystem/Event.cpp index 7bd0428..4d1637e 100644 --- a/src/EventSystem/Event.cpp +++ b/src/EventSystem/Event.cpp @@ -2,9 +2,9 @@ #include "Reservation.h" #include "StatusCodes.h" -Event::Event() : Event(nullptr, "", DateTime()) {} +Event::Event() : Event(nullptr, "", Date()) {} -Event::Event(const Hall* hall, String name, DateTime time) : tickets(), reservations() { +Event::Event(const Hall* hall, String name, Date time) : tickets(), reservations() { this->hall = hall; this->name = name; this->time = time; diff --git a/src/EventSystem/Event.h b/src/EventSystem/Event.h index 48cc137..5f733f0 100644 --- a/src/EventSystem/Event.h +++ b/src/EventSystem/Event.h @@ -12,13 +12,13 @@ class Event { OrderedList<Ticket> tickets; OrderedList<Reservation> reservations; - DateTime time; + Date time; String name; const Hall* hall; public: Event(); - Event(const Hall* hall, String name, DateTime time); + Event(const Hall* hall, String name, Date time); StatusCode reserveTicket(const Ticket& ticket, const char* password, const char* note); diff --git a/src/EventSystem/EventSystem.cpp b/src/EventSystem/EventSystem.cpp index 463ca15..54c81ad 100644 --- a/src/EventSystem/EventSystem.cpp +++ b/src/EventSystem/EventSystem.cpp @@ -19,12 +19,12 @@ EventSystem::EventSystem(const Event* events, unsigned eventCount) { updateSoonestUpcoming(); } -StatusCode EventSystem::createEvent(const Hall* hall, String name, DateTime time) { +StatusCode EventSystem::createEvent(const Hall* hall, String name, Date time) { events.insert(Event(hall, name, time)); return Success; } -unsigned EventSystem::queryFreeSeats(const char* name, const DateTime& dt) { +unsigned EventSystem::queryFreeSeats(const char* name, const Date& dt) { unsigned index = events.get_count(); for (unsigned i = 0; i < events.get_count(); i++) { if (events[i].) diff --git a/src/EventSystem/EventSystem.h b/src/EventSystem/EventSystem.h index eadcc42..9139746 100644 --- a/src/EventSystem/EventSystem.h +++ b/src/EventSystem/EventSystem.h @@ -17,7 +17,7 @@ public: EventSystem(); EventSystem(const Event* events, unsigned eventCount); - StatusCode createEvent(const Hall* hall, String name, DateTime time); + StatusCode createEvent(const Hall* hall, String name, Date time); StatusCode cancelEvent(); StatusCode reserveTicket(unsigned eventIndex, char* note, unsigned seatRow, unsigned seatColumn); @@ -25,9 +25,9 @@ public: StatusCode buyTicket(); void queryUpcoming(unsigned hallIndex); - unsigned queryFreeSeats(const char* name, const DateTime& dt); + unsigned queryFreeSeats(const char* name, const Date& dt); void queryReservations(unsigned eventIndex); - void queryBoughtTickets(DateTime start, DateTime end, unsigned hall); + void queryBoughtTickets(Date start, Date end, unsigned hall); void queryMostVisited(); void queryInsufficientlyVisited(); void reportReservations(unsigned eventIndex); diff --git a/src/VenueConsoleUI.cpp b/src/VenueConsoleUI.cpp index 6ab494b..5a41b64 100644 --- a/src/VenueConsoleUI.cpp +++ b/src/VenueConsoleUI.cpp @@ -28,7 +28,7 @@ void command_newEvent() { char name[MAX_LINE_WIDTH]; inputLineBox("Enter event name: ", name, MAX_LINE_WIDTH); - DateTime dt; + Date dt; inputBox("Enter event date and time: ", &dt); handleStatusCode(v->get_es().createEvent(&v->get_halls()[hallIndex], name, dt)); @@ -39,7 +39,7 @@ void command_newEvent() { void command_freeSeats() { char name[MAX_LINE_WIDTH]; inputLineBox("Enter event name: ", name, MAX_LINE_WIDTH); - DateTime dt; + Date dt; inputBox("Enter event date and time: ", &dt); print("Number of free seats: "); printLine(v->get_es().queryFreeSeats(name, dt)); |
