Summary Files Commits Branches @commit @diff @stats
path: root / Year 1 / Object-oriented Programming / Solutions Sem. 01 / exercise02.cpp
diff options
context:
space:
mode:
Commit2d8b66aa122ad7c2c73a778160176e26a8de4ec0 (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-03-05 15:52:37 +0200
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-03-05 15:52:37 +0200
Files1c787cd5c447f25f98ce48bbf8288082f6df41cf /Year 1/Object-oriented Programming/Solutions Sem. 01/exercise02.cpp
uni-projects-2d8b66aa122ad7c2c73a778160176e26a8de4ec0.tar
uni-projects-2d8b66aa122ad7c2c73a778160176e26a8de4ec0.tar.gz
uni-projects-2d8b66aa122ad7c2c73a778160176e26a8de4ec0.zip
Parent36c770ebb53a9a8ce2d89d872498b7201ac03f68 (diff)
Added solutions from oop seminar 1
1 files changed, 36 insertions, 0 deletions
-rw-r--r--Year 1/Object-oriented Programming/Solutions Sem. 01/exercise02.cpp36
diff --git a/Year 1/Object-oriented Programming/Solutions Sem. 01/exercise02.cpp b/Year 1/Object-oriented Programming/Solutions Sem. 01/exercise02.cpp
new file mode 100644
index 0000000..78b7616
--- /dev/null
+++ b/Year 1/Object-oriented Programming/Solutions Sem. 01/exercise02.cpp
@@ -0,0 +1,36 @@
+#include <iostream>
+
+struct Rational {
+ int m;
+ int n;
+};
+
+Rational sum(Rational a, Rational b) {
+ int divisor = a.n * b.n;
+ return { a.m * divisor + b.m * divisor, divisor };
+}
+
+Rational sub(Rational a, Rational b) {
+ b.m *= -1;
+ return sum(a, b);
+}
+
+Rational mult(Rational a, Rational b) {
+ return { a.m * b.m, a.n * b.n };
+}
+
+Rational div(Rational a, Rational b) {
+ int temp = b.m;
+ b.m = b.n;
+ b.n = temp;
+
+ return mult(a, b);
+}
+
+bool isValid(Rational a) {
+ return a.n != 0;
+}
+
+bool isWholeNumber(Rational a) {
+ return a.n % a.m == 0;
+}