Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

lt and lte

  • Loading branch information...
commit b3cb096ae838f5d6150e2dbc0776b787173bee8e 1 parent fd78a5e
@tarmstrong tarmstrong authored
Showing with 55 additions and 0 deletions.
  1. +11 −0 main.cpp
  2. +42 −0 megaint.cpp
  3. +2 −0  megaint.h
View
11 main.cpp
@@ -9,8 +9,10 @@ void test_mult();
void test_exp();
void test_x_equals_ops();
void test_streams();
+void test_lt();
int main() {
+ test_lt();
test_x_equals_ops();
test_addition();
test_subtraction();
@@ -22,6 +24,15 @@ int main() {
return 0;
}
+void test_lt() {
+ megaint a(101);
+ megaint b(102);
+ assert(a < b);
+ assert(a <= a);
+ assert(a <= b);
+ assert(!(a < a));
+}
+
// *=, -=, +=, /=
void test_x_equals_ops() {
cout << "test_x_equals_ops()" << endl;
View
42 megaint.cpp
@@ -514,3 +514,45 @@ bool megaint::isEven() const {
if(DEBUG) cout << *this << " isEven == " << result << endl;
return result;
}
+
+bool megaint::operator<(const megaint & rhs) {
+ if (this->digits->size() < rhs.digits->size()) {
+ return true;
+ }
+ else if (this->digits->size() > rhs.digits->size()) {
+ return false;
+ }
+ else {
+ for(unsigned int i=0; i<digits->size(); ++i)
+ {
+ if (digits->at(i) < rhs.digits->at(i)) {
+ return true;
+ }
+ else if (digits->at(i) > rhs.digits->at(i)) {
+ return false;
+ }
+ }
+ return false;
+ }
+}
+
+bool megaint::operator<=(const megaint & rhs) {
+ if (this->digits->size() < rhs.digits->size()) {
+ return true;
+ }
+ else if (this->digits->size() > rhs.digits->size()) {
+ return false;
+ }
+ else {
+ for(unsigned int i=0; i<digits->size(); ++i)
+ {
+ if (digits->at(i) < rhs.digits->at(i)) {
+ return true;
+ }
+ else if (digits->at(i) > rhs.digits->at(i)) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
View
2  megaint.h
@@ -20,6 +20,8 @@ class megaint
megaint(const long l);
megaint(const string & num);
~megaint();
+ bool operator<(const megaint & rhs);
+ bool operator<=(const megaint & rhs);
megaint & operator=(const megaint & rhs);
megaint operator+=(const megaint & rhs);
megaint operator-=(const megaint & rhs);
Please sign in to comment.
Something went wrong with that request. Please try again.