summaryrefslogtreecommitdiffstats
path: root/general/Frac.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'general/Frac.cpp')
-rw-r--r--general/Frac.cpp85
1 files changed, 39 insertions, 46 deletions
diff --git a/general/Frac.cpp b/general/Frac.cpp
index 317fdc53..36d0f591 100644
--- a/general/Frac.cpp
+++ b/general/Frac.cpp
@@ -1,60 +1,53 @@
-/////////////////////////////////////////////////////////////////////////////
-// Name: general/Frac.cpp
-// Purpose: A class to make handling fractions easier
-// Author: Ben Boeckel
-// Modified by: Ben Boeckel
-// Created: Sun Mar 18 15:25:16 2007
-// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions
-// Licence:
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License along
-// with this program. If not, see <http://www.gnu.org/licenses/>.
-/////////////////////////////////////////////////////////////////////////////
+/*
+ * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+// Header include
#include "Frac.h"
-void Frac::set(const int n, const int d) throw(Exception)
+void Frac::set(const int numerator, const int denominator) throw(Exception)
{
- if (((type == Improper) || ((n <= d) && (type == Proper)) || ((d <= n) && (type == Over1))) && (0 < d))
+ if (((m_type == Improper) || ((numerator <= denominator) && (m_type == Proper)) || ((denominator <= numerator) && (m_type == Over1))) && (0 < numerator))
{
- num = n;
- denom = d;
+ m_numerator = numerator;
+ m_denominator = denominator;
}
else
throw(Exception("Frac", "values conflict with type"));
}
-void Frac::set(const int n, const int d, const int t) throw(Exception)
+void Frac::set(const int numerator, const int demoninator, const int type) throw(Exception)
{
- setType(t);
- set(n, d);
+ setType(type);
+ set(numerator, demoninator);
}
-void Frac::setNum(const int n) throw(Exception)
+void Frac::setType(const int type) throw(BoundsException)
{
- set(n, denom);
-}
-
-void Frac::setDenom(const int d) throw(Exception)
-{
- set(num, d);
-}
-
-void Frac::setType(const int t) throw(BoundsException)
-{
- if (t < End)
+ if (type < End)
{
- type = t;
- set(1, 1);
+ m_type = type;
+ try
+ {
+ set(m_numerator, m_denominator);
+ }
+ catch (Exception& e)
+ {
+ set(1, 1);
+ }
}
else
throw(BoundsException("Frac", "type"));
@@ -62,10 +55,10 @@ void Frac::setType(const int t) throw(BoundsException)
void Frac::reduce()
{
- int i = num;
- int j = denom;
+ int i = m_numerator;
+ int j = m_denominator;
while (i - j)
(i > j) ? (i -= j) : (j -= i);
- num /= i;
- denom /= i;
+ m_numerator /= i;
+ m_denominator /= i;
}