Summary Files Commits Branches @commit @diff @stats
path: root / Year 1 / Object-oriented Programming / Project 1 / src / Models / Hall.cpp
diff options
context:
space:
mode:
Commit24bdf39e6c21ab846f6c86803761d78a094e05c0 (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-05-26 20:31:26 +0300
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-05-26 20:31:26 +0300
Files1b2077b088098cc7ae6afc946b10a4d680110294 /Year 1/Object-oriented Programming/Project 1/src/Models/Hall.cpp
uni-projects-24bdf39e6c21ab846f6c86803761d78a094e05c0.tar
uni-projects-24bdf39e6c21ab846f6c86803761d78a094e05c0.tar.gz
uni-projects-24bdf39e6c21ab846f6c86803761d78a094e05c0.zip
Parentcbe944835cc0951a946d01f034b4d28ff9874a4e (diff)
Added files from project 1 (mirror)
1 files changed, 76 insertions, 0 deletions
-rw-r--r--Year 1/Object-oriented Programming/Project 1/src/Models/Hall.cpp76
diff --git a/Year 1/Object-oriented Programming/Project 1/src/Models/Hall.cpp b/Year 1/Object-oriented Programming/Project 1/src/Models/Hall.cpp
new file mode 100644
index 0000000..feacdac
--- /dev/null
+++ b/Year 1/Object-oriented Programming/Project 1/src/Models/Hall.cpp
@@ -0,0 +1,76 @@
+#include "Hall.h"
+
+Hall::Hall() : Hall(0, 0, 0) {}
+
+Hall::Hall(int number) : Hall(number, 0, 0) {}
+
+Hall::Hall(int number, unsigned rows, unsigned seatsPerRow) {
+ this->number = number;
+ this->rows = rows;
+ this->seatsPerRow = seatsPerRow;
+}
+
+int Hall::get_number() const {
+ return number;
+}
+unsigned Hall::get_rows() const {
+ return rows;
+}
+
+unsigned Hall::get_seatsPerRow() const {
+ return seatsPerRow;
+}
+
+/*! \param istr An input stream
+ *
+ * Directly reads bytes from stream (calls read() function).
+ *
+ * \remark Doesn't alter the stream in any other way.
+ * \note Best used with binary ifstream
+ */
+void Hall::read(std::istream& istr) {
+ istr.read((char*)&number, sizeof(number));
+ istr.read((char*)&rows, sizeof(rows));
+ istr.read((char*)&seatsPerRow, sizeof(seatsPerRow));
+}
+
+/*! \param ostr An output stream
+ *
+ * Directly writes bytes to stream (calls write() function).
+ *
+ * \remark Doesn't alter the stream in any other way.
+ * \note Best used with binary ofstream
+ */
+void Hall::write(std::ostream& ostr) const {
+ ostr.write((char*)&number, sizeof(number));
+ ostr.write((char*)&rows, sizeof(rows));
+ ostr.write((char*)&seatsPerRow, sizeof(seatsPerRow));
+}
+
+/*! \return -1 if number < other.number, 1 if number > other.number, 0 if number == other.number
+ */
+int Hall::compare(const Hall& other) const {
+ return (number > other.get_number()) - (number < other.get_number());
+}
+
+/*!
+ * Uses the stream's >> operator to read and parse all internal values.
+ *
+ * \note Best used with std::cin or text std::ifstream
+ */
+std::istream& operator>>(std::istream& istr, Hall& hall) {
+ int number;
+ unsigned rows, seatsPerRow;
+ istr >> number >> rows >> seatsPerRow;
+ hall = Hall(number, rows, seatsPerRow);
+ return istr;
+}
+
+/*!
+ * Uses the stream's << operator to write all internal data.
+ *
+ * \note Best used with std::cout or text std::ofstream
+ */
+std::ostream& operator<<(std::ostream& ostr, const Hall& hall) {
+ return ostr << hall.get_number() << " " << hall.get_rows() << " "<< hall.get_seatsPerRow();
+}