Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Models / Ticket.cpp
diff options
context:
space:
mode:
Commitb844597fd23bc57aa97e231fc90eecfd6322cecc (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-05-07 08:28:27 +0300
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-05-07 08:28:27 +0300
Files86a4112ecfa1e3a54dbcf44a7ddf37575ba4aa39 /src/Models/Ticket.cpp
FMI-OOP-P1_TicketSystem-b844597fd23bc57aa97e231fc90eecfd6322cecc.tar
FMI-OOP-P1_TicketSystem-b844597fd23bc57aa97e231fc90eecfd6322cecc.tar.gz
FMI-OOP-P1_TicketSystem-b844597fd23bc57aa97e231fc90eecfd6322cecc.zip
Parent0910afb91c8f9672be1d6184f47fb75947ea14f1 (diff)
Reorganized whole architecture
1 files changed, 45 insertions, 0 deletions
-rw-r--r--src/Models/Ticket.cpp45
diff --git a/src/Models/Ticket.cpp b/src/Models/Ticket.cpp
new file mode 100644
index 0000000..e37cccf
--- /dev/null
+++ b/src/Models/Ticket.cpp
@@ -0,0 +1,45 @@
+#include "Ticket.h"
+
+Ticket::Ticket() : Ticket(0, 0) {}
+
+Ticket::Ticket(unsigned row, unsigned seat) {
+ this->row = row;
+ this->seat = seat;
+}
+
+unsigned Ticket::get_row() const {
+ return row;
+}
+
+unsigned Ticket::get_seat() const {
+ return seat;
+}
+
+void Ticket::read(std::istream& istr) {
+ istr.read((char*)&row, sizeof(row));
+ istr.read((char*)&row, sizeof(seat));
+}
+
+void Ticket::write(std::ostream& ostr) const {
+ ostr.write((const char*)&row, sizeof(row));
+ ostr.write((const char*)&seat, sizeof(seat));
+}
+
+int Ticket::compare(const Ticket& other) const {
+ if (row == other.row)
+ return (seat > other.seat) - (seat < other.seat);
+ return (row > other.row) - (row < other.row);
+}
+
+/* General */
+
+std::istream& operator>>(std::istream& istr, Ticket& ticket) {
+ unsigned row, seat;
+ istr >> row >> seat;
+ ticket = Ticket(row, seat);
+ return istr;
+}
+
+std::ostream& operator<<(std::ostream& ostr, const Ticket& ticket) {
+ return ostr << ticket.get_row() << " " << ticket.get_seat();
+}