bigint - #include <stack> using namespace std;...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: #include <stack> using namespace std; #include "bigint.h" #include "trace.h" bigint::bigint (): small_value (0) { } bigint::bigint (const bigint &that): small_value (that.small_value) { *this = that; } bigint &bigint::operator= (const bigint &that) { if (this == &that) return *this; this->small_value = that.small_value; return *this; } bigint::~bigint() { TRACE ('~', cout << *this); } bigint::bigint (int that): small_value (that) { } bigint::bigint (const string &that) { TRACE ('b', that); string::const_iterator itor = that.begin(); string::const_iterator end = that.end(); bool negative = false; if (*itor == '_') {negative = true; ++itor; } int newval = 0; for (; itor != end; ++itor) newval = newval * 10 + *itor - '0'; small_value = negative ? - newval : + newval; } bigint bigint::operator+ (const bigint &that) const { return this->small_value + that.small_value; } bigint bigint::operator- (const bigint &that) const { return this->small_value - that.small_value; } int bigint::compare (const bigint &that) const { return this->small_value < that.small_value ? -1 : this->small_value > that.small_value ? +1 : 0; } int bigint::smallint () const { if (*this < INT_MIN || *this > INT_MAX)...
View Full Document

This note was uploaded on 01/26/2010 for the course CMPS 109 taught by Professor Bailey,d during the Spring '08 term at University of California, Santa Cruz.

Page1 / 4

bigint - #include <stack> using namespace std;...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online