Summary Files Commits Branches @commit @diff @stats
path: root / Year 1 / Object-oriented Programming / 05-Practice-29.03.2022 / ex2-Rational.cpp
diff options
context:
space:
mode:
Commitc105f7db9b10861dd0bdeedb3ed4d1ebe2054b87 (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-03-29 21:00:23 +0300
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-03-29 21:00:23 +0300
Files4db7b3e0720a5f573e4f3ef6dced6e20b2056550 /Year 1/Object-oriented Programming/05-Practice-29.03.2022/ex2-Rational.cpp
uni-projects-c105f7db9b10861dd0bdeedb3ed4d1ebe2054b87.tar
uni-projects-c105f7db9b10861dd0bdeedb3ed4d1ebe2054b87.tar.gz
uni-projects-c105f7db9b10861dd0bdeedb3ed4d1ebe2054b87.zip
Parent6a3cfbba14bce63cfdbae698cc0d052ba871a7a9 (diff)
Added todays oop practice
1 files changed, 47 insertions, 0 deletions
-rw-r--r--Year 1/Object-oriented Programming/05-Practice-29.03.2022/ex2-Rational.cpp47
diff --git a/Year 1/Object-oriented Programming/05-Practice-29.03.2022/ex2-Rational.cpp b/Year 1/Object-oriented Programming/05-Practice-29.03.2022/ex2-Rational.cpp
new file mode 100644
index 0000000..05794b5
--- /dev/null
+++ b/Year 1/Object-oriented Programming/05-Practice-29.03.2022/ex2-Rational.cpp
@@ -0,0 +1,47 @@
+#include "ex2-Rational.h"
+
+Rational::Rational(int numerator, int denumerator) {
+ set_numerator(numerator);
+ set_denumerator(denumerator);
+}
+
+int Rational::get_numerator() const {
+ return numerator;
+}
+void Rational::set_numerator(int numerator) {
+ this->numerator = numerator;
+}
+
+int Rational::get_denumerator() const {
+ return denumerator;
+}
+void Rational::set_denumerator(int denumerator) {
+ this->denumerator = denumerator;
+}
+
+void canonize() {
+
+}
+
+Rational Rational::operator+(const Rational& other) {
+ return Rational(numerator * other.denumerator + other.numerator * denumerator, denumerator * other.denumerator);
+}
+
+//x a = x*b + y*a
+//y b y*b
+
+Rational Rational::operator-(const Rational& other) {
+ return Rational(numerator * other.denumerator - other.numerator * denumerator, denumerator * other.denumerator);
+}
+
+Rational Rational::operator*(const Rational& other) {
+ return Rational(numerator * other.numerator, denumerator * other.denumerator);
+}
+
+Rational Rational::operator/(const Rational& other) {
+ return Rational(numerator / other.numerator, denumerator / other.denumerator);
+}
+
+int Rational::numcmp(const Rational& arg) const {
+
+}