|
FMI Ticket System
| Kamen Mladenov | FMI Computer Science Year 1 Group 6 | Project 1 | Project Topic 4 |
|
Stores a day, month and year. More...
#include <Date.h>
Public Member Functions | |
| Date () | |
| Sets date as 01 May 2022. | |
| Date (const char *str) | |
| Parses string. More... | |
| Date (unsigned short day, unsigned short month, unsigned short year) | |
| Sets day, month and year. More... | |
| unsigned short | get_day () const |
| Returns the day. | |
| bool | set_day (unsigned short day) |
| Sets the day. More... | |
| unsigned short | get_month () const |
| Returns the month. | |
| bool | set_month (unsigned short month) |
| Sets the month. More... | |
| unsigned short | get_year () const |
| Returns the year. | |
| bool | set_year (unsigned short year) |
| Sets the year. More... | |
| String | createString () const |
| Returns the date as a String object. More... | |
| void | read (std::istream &istr) |
| Reads date from stream. More... | |
| void | write (std::ostream &ostr) |
| Writes date to stream. More... | |
| int | compare (const Date &other) const |
| Compares two dates. More... | |
Stores a day, month and year.
| Date::Date | ( | const char * | str | ) |
Parses string.
| str | C-style string |
Values are initialized with zeroes. Then it parses the string:
Skips spaces, saves day with atoi, skips two characters, skips spaces, saves month with atoi, skips two characters, skips spaces, saves year with atoi.
Values are validated with setters. You should always have spaces between day, month and year and no non-numeric characters between them.
| Date::Date | ( | unsigned short | day, |
| unsigned short | month, | ||
| unsigned short | year | ||
| ) |
Sets day, month and year.
Initializes values with zeroes and then uses setters to save the function arguments.
| int Date::compare | ( | const Date & | other | ) | const |
Compares two dates.
| String Date::createString | ( | ) | const |
| void Date::read | ( | std::istream & | istr | ) |
Reads date from stream.
| istr | An input stream |
Directly reads bytes from stream (calls read() function).
| bool Date::set_day | ( | unsigned short | newDay | ) |
Sets the day.
If newDay is equal to 0, or is more than the appropriate days in the month, the day isn't set.
| bool Date::set_month | ( | unsigned short | newMonth | ) |
Sets the month.
If newMonth is equal to 0 or is more than 12, the month isn't set.
| bool Date::set_year | ( | unsigned short | newYear | ) |
Sets the year.
Year isn't set when newYear is zero
| void Date::write | ( | std::ostream & | ostr | ) |
Writes date to stream.
| ostr | An output stream |
Directly writes bytes to stream (calls write() function).