From 793100813b3c50a1f304904440366a7137ae0992 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 30 Mar 2022 08:41:52 +0300 Subject: Reworked yesterdays oop practice folder structure --- .../06-Practice-29.03.2022/ex2/Rational.cpp | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Year 1/Object-oriented Programming/06-Practice-29.03.2022/ex2/Rational.cpp (limited to 'Year 1/Object-oriented Programming/06-Practice-29.03.2022/ex2/Rational.cpp') diff --git a/Year 1/Object-oriented Programming/06-Practice-29.03.2022/ex2/Rational.cpp b/Year 1/Object-oriented Programming/06-Practice-29.03.2022/ex2/Rational.cpp new file mode 100644 index 0000000..cc28545 --- /dev/null +++ b/Year 1/Object-oriented Programming/06-Practice-29.03.2022/ex2/Rational.cpp @@ -0,0 +1,47 @@ +#include "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 { + +} -- cgit v1.3.1-23-gd82d